summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/text/internal/number/pattern_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/text/internal/number/pattern_test.go')
-rw-r--r--vendor/golang.org/x/text/internal/number/pattern_test.go333
1 files changed, 205 insertions, 128 deletions
diff --git a/vendor/golang.org/x/text/internal/number/pattern_test.go b/vendor/golang.org/x/text/internal/number/pattern_test.go
index 97ff64d55..a7517d004 100644
--- a/vendor/golang.org/x/text/internal/number/pattern_test.go
+++ b/vendor/golang.org/x/text/internal/number/pattern_test.go
@@ -22,96 +22,122 @@ var testCases = []struct {
}, {
"0",
&Pattern{
- FormatWidth: 1,
- MinIntegerDigits: 1,
+ FormatWidth: 1,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ },
},
}, {
"+0",
&Pattern{
- Affix: "\x01+\x00",
- FormatWidth: 2,
- MinIntegerDigits: 1,
+ Affix: "\x01+\x00",
+ FormatWidth: 2,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ },
},
}, {
"0+",
&Pattern{
- Affix: "\x00\x01+",
- FormatWidth: 2,
- MinIntegerDigits: 1,
+ Affix: "\x00\x01+",
+ FormatWidth: 2,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ },
},
}, {
"0000",
&Pattern{
- FormatWidth: 4,
- MinIntegerDigits: 4,
+ FormatWidth: 4,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 4,
+ },
},
}, {
".#",
&Pattern{
- FormatWidth: 2,
- MaxFractionDigits: 1,
+ FormatWidth: 2,
+ RoundingContext: RoundingContext{
+ MaxFractionDigits: 1,
+ },
},
}, {
"#0.###",
&Pattern{
- FormatWidth: 6,
- MinIntegerDigits: 1,
- MaxFractionDigits: 3,
+ FormatWidth: 6,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MaxFractionDigits: 3,
+ },
},
}, {
"#0.######",
&Pattern{
- FormatWidth: 9,
- MinIntegerDigits: 1,
- MaxFractionDigits: 6,
+ FormatWidth: 9,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MaxFractionDigits: 6,
+ },
},
}, {
"#,0",
&Pattern{
- FormatWidth: 3,
- GroupingSize: [2]uint8{1, 0},
- MinIntegerDigits: 1,
+ FormatWidth: 3,
+ GroupingSize: [2]uint8{1, 0},
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ },
},
}, {
"#,0.00",
&Pattern{
- FormatWidth: 6,
- GroupingSize: [2]uint8{1, 0},
- MinIntegerDigits: 1,
- MinFractionDigits: 2,
- MaxFractionDigits: 2,
+ FormatWidth: 6,
+ GroupingSize: [2]uint8{1, 0},
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MinFractionDigits: 2,
+ MaxFractionDigits: 2,
+ },
},
}, {
"#,##0.###",
&Pattern{
- FormatWidth: 9,
- GroupingSize: [2]uint8{3, 0},
- MinIntegerDigits: 1,
- MaxFractionDigits: 3,
+ FormatWidth: 9,
+ GroupingSize: [2]uint8{3, 0},
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MaxFractionDigits: 3,
+ },
},
}, {
"#,##,##0.###",
&Pattern{
- FormatWidth: 12,
- GroupingSize: [2]uint8{3, 2},
- MinIntegerDigits: 1,
- MaxFractionDigits: 3,
+ FormatWidth: 12,
+ GroupingSize: [2]uint8{3, 2},
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MaxFractionDigits: 3,
+ },
},
}, {
// Ignore additional separators.
"#,####,##,##0.###",
&Pattern{
- FormatWidth: 17,
- GroupingSize: [2]uint8{3, 2},
- MinIntegerDigits: 1,
- MaxFractionDigits: 3,
+ FormatWidth: 17,
+ GroupingSize: [2]uint8{3, 2},
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MaxFractionDigits: 3,
+ },
},
}, {
"#E0",
&Pattern{
- FormatWidth: 3,
- MaxIntegerDigits: 1,
- MinExponentDigits: 1,
+ FormatWidth: 3,
+ RoundingContext: RoundingContext{
+ MaxIntegerDigits: 1,
+ MinExponentDigits: 1,
+ },
},
}, {
// At least one exponent digit is required. As long as this is true, one can
@@ -121,30 +147,47 @@ var testCases = []struct {
}, {
"0E0",
&Pattern{
- FormatWidth: 3,
- MinIntegerDigits: 1,
- MinExponentDigits: 1,
+ FormatWidth: 3,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MinExponentDigits: 1,
+ },
+ },
+}, {
+ "##0.###E00",
+ &Pattern{
+ FormatWidth: 10,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MaxIntegerDigits: 3,
+ MaxFractionDigits: 3,
+ MinExponentDigits: 2,
+ },
},
}, {
"##00.0#E0",
&Pattern{
- FormatWidth: 9,
- MinIntegerDigits: 2,
- MaxIntegerDigits: 4,
- MinFractionDigits: 1,
- MaxFractionDigits: 2,
- MinExponentDigits: 1,
+ FormatWidth: 9,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 2,
+ MaxIntegerDigits: 4,
+ MinFractionDigits: 1,
+ MaxFractionDigits: 2,
+ MinExponentDigits: 1,
+ },
},
}, {
"#00.0E+0",
&Pattern{
- FormatWidth: 8,
- Flags: AlwaysExpSign,
- MinIntegerDigits: 2,
- MaxIntegerDigits: 3,
- MinFractionDigits: 1,
- MaxFractionDigits: 1,
- MinExponentDigits: 1,
+ FormatWidth: 8,
+ Flags: AlwaysExpSign,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 2,
+ MaxIntegerDigits: 3,
+ MinFractionDigits: 1,
+ MaxFractionDigits: 1,
+ MinExponentDigits: 1,
+ },
},
}, {
"0.0E++0",
@@ -156,45 +199,58 @@ var testCases = []struct {
// significant digits
"@",
&Pattern{
- FormatWidth: 1,
- MinSignificantDigits: 1,
- MaxSignificantDigits: 1,
+ FormatWidth: 1,
+ RoundingContext: RoundingContext{
+ MinSignificantDigits: 1,
+ MaxSignificantDigits: 1,
+ MaxFractionDigits: -1,
+ },
},
}, {
// significant digits
"@@@@",
&Pattern{
- FormatWidth: 4,
- MinSignificantDigits: 4,
- MaxSignificantDigits: 4,
+ FormatWidth: 4,
+ RoundingContext: RoundingContext{
+ MinSignificantDigits: 4,
+ MaxSignificantDigits: 4,
+ MaxFractionDigits: -1,
+ },
},
}, {
"@###",
&Pattern{
- FormatWidth: 4,
- MinSignificantDigits: 1,
- MaxSignificantDigits: 4,
+ FormatWidth: 4,
+ RoundingContext: RoundingContext{
+ MinSignificantDigits: 1,
+ MaxSignificantDigits: 4,
+ MaxFractionDigits: -1,
+ },
},
}, {
// Exponents in significant digits mode gets normalized.
"@@E0",
&Pattern{
- FormatWidth: 4,
- MinIntegerDigits: 1,
- MaxIntegerDigits: 1,
- MinFractionDigits: 1,
- MaxFractionDigits: 1,
- MinExponentDigits: 1,
+ FormatWidth: 4,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MaxIntegerDigits: 1,
+ MinFractionDigits: 1,
+ MaxFractionDigits: 1,
+ MinExponentDigits: 1,
+ },
},
}, {
"@###E00",
&Pattern{
- FormatWidth: 7,
- MinIntegerDigits: 1,
- MaxIntegerDigits: 1,
- MinFractionDigits: 0,
- MaxFractionDigits: 3,
- MinExponentDigits: 2,
+ FormatWidth: 7,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MaxIntegerDigits: 1,
+ MinFractionDigits: 0,
+ MaxFractionDigits: 3,
+ MinExponentDigits: 2,
+ },
},
}, {
// The significant digits mode does not allow fractions.
@@ -204,73 +260,89 @@ var testCases = []struct {
//alternative negative pattern
"#0.###;(#0.###)",
&Pattern{
- Affix: "\x00\x00\x01(\x01)",
- NegOffset: 2,
- FormatWidth: 6,
- MinIntegerDigits: 1,
- MaxFractionDigits: 3,
+ Affix: "\x00\x00\x01(\x01)",
+ NegOffset: 2,
+ FormatWidth: 6,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MaxFractionDigits: 3,
+ },
},
}, {
// Rounding increment
"1.05",
&Pattern{
- RoundIncrement: 105,
- FormatWidth: 4,
- MinIntegerDigits: 1,
- MinFractionDigits: 2,
- MaxFractionDigits: 2,
+ FormatWidth: 4,
+ RoundingContext: RoundingContext{
+ Increment: 105,
+ IncrementScale: 2,
+ MinIntegerDigits: 1,
+ MinFractionDigits: 2,
+ MaxFractionDigits: 2,
+ },
},
}, {
// Rounding increment with grouping
"1,05",
&Pattern{
- RoundIncrement: 105,
- FormatWidth: 4,
- GroupingSize: [2]uint8{2, 0},
- MinIntegerDigits: 3,
- MinFractionDigits: 0,
- MaxFractionDigits: 0,
+ FormatWidth: 4,
+ GroupingSize: [2]uint8{2, 0},
+ RoundingContext: RoundingContext{
+ Increment: 105,
+ IncrementScale: 0,
+ MinIntegerDigits: 3,
+ MinFractionDigits: 0,
+ MaxFractionDigits: 0,
+ },
},
}, {
"0.0%",
&Pattern{
- Affix: "\x00\x01%",
- DigitShift: 2,
- FormatWidth: 4,
- MinIntegerDigits: 1,
- MinFractionDigits: 1,
- MaxFractionDigits: 1,
+ Affix: "\x00\x01%",
+ FormatWidth: 4,
+ RoundingContext: RoundingContext{
+ DigitShift: 2,
+ MinIntegerDigits: 1,
+ MinFractionDigits: 1,
+ MaxFractionDigits: 1,
+ },
},
}, {
"0.0‰",
&Pattern{
- Affix: "\x00\x03‰",
- DigitShift: 3,
- FormatWidth: 4,
- MinIntegerDigits: 1,
- MinFractionDigits: 1,
- MaxFractionDigits: 1,
+ Affix: "\x00\x03‰",
+ FormatWidth: 4,
+ RoundingContext: RoundingContext{
+ DigitShift: 3,
+ MinIntegerDigits: 1,
+ MinFractionDigits: 1,
+ MaxFractionDigits: 1,
+ },
},
}, {
"#,##0.00¤",
&Pattern{
- Affix: "\x00\x02¤",
- FormatWidth: 9,
- GroupingSize: [2]uint8{3, 0},
- MinIntegerDigits: 1,
- MinFractionDigits: 2,
- MaxFractionDigits: 2,
+ Affix: "\x00\x02¤",
+ FormatWidth: 9,
+ GroupingSize: [2]uint8{3, 0},
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 1,
+ MinFractionDigits: 2,
+ MaxFractionDigits: 2,
+ },
},
}, {
"#,##0.00 ¤;(#,##0.00 ¤)",
&Pattern{Affix: "\x00\x04\u00a0¤\x01(\x05\u00a0¤)",
- NegOffset: 6,
- DigitShift: 0,
- FormatWidth: 10,
- GroupingSize: [2]uint8{3, 0},
- MinIntegerDigits: 1,
- MinFractionDigits: 2,
- MaxFractionDigits: 2,
+ NegOffset: 6,
+ FormatWidth: 10,
+ GroupingSize: [2]uint8{3, 0},
+ RoundingContext: RoundingContext{
+ DigitShift: 0,
+ MinIntegerDigits: 1,
+ MinFractionDigits: 2,
+ MaxFractionDigits: 2,
+ },
},
}, {
// padding
@@ -321,16 +393,21 @@ var testCases = []struct {
}, {
`* #0 o''clock`,
&Pattern{Affix: "\x00\x09 o\\'clock",
- FormatWidth: 10,
- PadRune: 32,
- MinIntegerDigits: 0x1},
+ FormatWidth: 10,
+ PadRune: 32,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 0x1,
+ },
+ },
}, {
`'123'* #0'456'`,
&Pattern{Affix: "\x05'123'\x05'456'",
- FormatWidth: 8,
- PadRune: 32,
- MinIntegerDigits: 0x1,
- Flags: PadAfterPrefix},
+ FormatWidth: 8,
+ PadRune: 32,
+ RoundingContext: RoundingContext{
+ MinIntegerDigits: 0x1,
+ },
+ Flags: PadAfterPrefix},
}, {
// no duplicate padding
"*xpre#suf*x", nil,
@@ -354,8 +431,8 @@ func TestParsePattern(t *testing.T) {
}
func TestPatternSize(t *testing.T) {
- if sz := unsafe.Sizeof(Pattern{}); sz > 48 {
- t.Errorf("got %d; want <= 48", sz)
+ if sz := unsafe.Sizeof(Pattern{}); sz > 56 {
+ t.Errorf("got %d; want <= 56", sz)
}
}