-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFormatsTest.java
110 lines (95 loc) · 5.39 KB
/
FormatsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright 2014-2015 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.schildbach.wallet.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.regex.Matcher;
import org.junit.Test;
/**
* @author Andreas Schildbach
*/
public class FormatsTest {
@Test
public void monetarySpannable() throws Exception {
final Matcher single = Formats.PATTERN_MONETARY_SPANNABLE.matcher("0");
assertTrue(single.find());
assertNull(single.group(Formats.PATTERN_GROUP_PREFIX));
assertNotNull(single.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertEquals("0", single.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertNull(single.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
final Matcher many = Formats.PATTERN_MONETARY_SPANNABLE.matcher("00000000");
assertTrue(many.find());
assertNull(many.group(Formats.PATTERN_GROUP_PREFIX));
assertNotNull(many.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertEquals("00000000", many.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertNull(many.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
final Matcher standard = Formats.PATTERN_MONETARY_SPANNABLE.matcher("0.0000");
assertTrue(standard.find());
assertNull(standard.group(Formats.PATTERN_GROUP_PREFIX));
assertNotNull(standard.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertEquals("0.00", standard.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertNotNull(standard.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
assertEquals("00", standard.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
final Matcher startWithDot = Formats.PATTERN_MONETARY_SPANNABLE.matcher(".0000");
assertTrue(startWithDot.find());
assertNull(startWithDot.group(Formats.PATTERN_GROUP_PREFIX));
assertNotNull(startWithDot.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertEquals(".00", startWithDot.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertNotNull(startWithDot.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
assertEquals("00", startWithDot.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
final Matcher endWithDot = Formats.PATTERN_MONETARY_SPANNABLE.matcher("00.");
assertTrue(endWithDot.find());
assertNull(endWithDot.group(Formats.PATTERN_GROUP_PREFIX));
assertNotNull(endWithDot.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertEquals("00.", endWithDot.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertNull(endWithDot.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
final Matcher signed = Formats.PATTERN_MONETARY_SPANNABLE.matcher("-0.00");
assertTrue(signed.find());
assertNull(signed.group(Formats.PATTERN_GROUP_PREFIX));
assertNotNull(signed.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertEquals("-0.00", signed.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertNull(signed.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
final Matcher symbol = Formats.PATTERN_MONETARY_SPANNABLE.matcher("€0.00");
assertTrue(symbol.find());
assertNotNull(symbol.group(Formats.PATTERN_GROUP_PREFIX));
assertEquals("€", symbol.group(Formats.PATTERN_GROUP_PREFIX));
assertNotNull(symbol.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertEquals("0.00", symbol.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertNull(symbol.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
final Matcher code = Formats.PATTERN_MONETARY_SPANNABLE.matcher("BTC 0.00");
assertTrue(code.find());
assertNotNull(code.group(Formats.PATTERN_GROUP_PREFIX));
assertEquals("BTC", code.group(Formats.PATTERN_GROUP_PREFIX));
assertNotNull(code.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertEquals("0.00", code.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertNull(code.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
final Matcher subString = Formats.PATTERN_MONETARY_SPANNABLE.matcher("###$0###");
assertTrue(subString.find());
assertNotNull(subString.group(Formats.PATTERN_GROUP_PREFIX));
assertEquals("$", subString.group(Formats.PATTERN_GROUP_PREFIX));
assertNotNull(subString.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertEquals("0", subString.group(Formats.PATTERN_GROUP_SIGNIFICANT));
assertNull(subString.group(Formats.PATTERN_GROUP_INSIGNIFICANT));
final Matcher empty = Formats.PATTERN_MONETARY_SPANNABLE.matcher("");
assertFalse(empty.find());
final Matcher signOnly = Formats.PATTERN_MONETARY_SPANNABLE.matcher("+");
assertFalse(signOnly.find());
}
}