1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 var testCases = []struct {
20 // TODO: Should MinIntegerDigits be 1?
26 RoundingContext: RoundingContext{
35 RoundingContext: RoundingContext{
44 RoundingContext: RoundingContext{
52 RoundingContext: RoundingContext{
60 RoundingContext: RoundingContext{
68 RoundingContext: RoundingContext{
77 RoundingContext: RoundingContext{
86 GroupingSize: [2]uint8{1, 0},
87 RoundingContext: RoundingContext{
95 GroupingSize: [2]uint8{1, 0},
96 RoundingContext: RoundingContext{
106 GroupingSize: [2]uint8{3, 0},
107 RoundingContext: RoundingContext{
109 MaxFractionDigits: 3,
116 GroupingSize: [2]uint8{3, 2},
117 RoundingContext: RoundingContext{
119 MaxFractionDigits: 3,
123 // Ignore additional separators.
127 GroupingSize: [2]uint8{3, 2},
128 RoundingContext: RoundingContext{
130 MaxFractionDigits: 3,
137 RoundingContext: RoundingContext{
139 MinExponentDigits: 1,
143 // At least one exponent digit is required. As long as this is true, one can
144 // determine that scientific rendering is needed if MinExponentDigits > 0.
151 RoundingContext: RoundingContext{
153 MinExponentDigits: 1,
160 RoundingContext: RoundingContext{
163 MaxFractionDigits: 3,
164 MinExponentDigits: 2,
171 RoundingContext: RoundingContext{
174 MinFractionDigits: 1,
175 MaxFractionDigits: 2,
176 MinExponentDigits: 1,
183 Flags: AlwaysExpSign,
184 RoundingContext: RoundingContext{
187 MinFractionDigits: 1,
188 MaxFractionDigits: 1,
189 MinExponentDigits: 1,
199 // significant digits
203 RoundingContext: RoundingContext{
204 MinSignificantDigits: 1,
205 MaxSignificantDigits: 1,
209 // significant digits
213 RoundingContext: RoundingContext{
214 MinSignificantDigits: 4,
215 MaxSignificantDigits: 4,
222 RoundingContext: RoundingContext{
223 MinSignificantDigits: 1,
224 MaxSignificantDigits: 4,
228 // Exponents in significant digits mode gets normalized.
232 RoundingContext: RoundingContext{
235 MinFractionDigits: 1,
236 MaxFractionDigits: 1,
237 MinExponentDigits: 1,
244 RoundingContext: RoundingContext{
247 MinFractionDigits: 0,
248 MaxFractionDigits: 3,
249 MinExponentDigits: 2,
253 // The significant digits mode does not allow fractions.
257 //alternative negative pattern
260 Affix: "\x00\x00\x01(\x01)",
263 RoundingContext: RoundingContext{
265 MaxFractionDigits: 3,
269 // Rounding increment
273 RoundingContext: RoundingContext{
277 MinFractionDigits: 2,
278 MaxFractionDigits: 2,
282 // Rounding increment with grouping
286 GroupingSize: [2]uint8{2, 0},
287 RoundingContext: RoundingContext{
291 MinFractionDigits: 0,
292 MaxFractionDigits: 0,
300 RoundingContext: RoundingContext{
303 MinFractionDigits: 1,
304 MaxFractionDigits: 1,
312 RoundingContext: RoundingContext{
315 MinFractionDigits: 1,
316 MaxFractionDigits: 1,
324 GroupingSize: [2]uint8{3, 0},
325 RoundingContext: RoundingContext{
327 MinFractionDigits: 2,
328 MaxFractionDigits: 2,
332 "#,##0.00 ¤;(#,##0.00 ¤)",
333 &Pattern{Affix: "\x00\x04\u00a0¤\x01(\x05\u00a0¤)",
336 GroupingSize: [2]uint8{3, 0},
337 RoundingContext: RoundingContext{
340 MinFractionDigits: 2,
341 MaxFractionDigits: 2,
357 Flags: PadBeforeSuffix,
362 Affix: "\x03pre\x03suf",
369 Affix: "\x03pre\x03suf",
372 Flags: PadAfterPrefix,
377 Affix: "\x03pre\x03suf",
380 Flags: PadBeforeSuffix,
385 Affix: "\x03pre\x03suf",
388 Flags: PadAfterSuffix,
392 &Pattern{Affix: "\x00\x09 o\\'clock",
395 RoundingContext: RoundingContext{
396 MinIntegerDigits: 0x1,
401 &Pattern{Affix: "\x05'123'\x05'456'",
404 RoundingContext: RoundingContext{
405 MinIntegerDigits: 0x1,
407 Flags: PadAfterPrefix},
409 // no duplicate padding
412 // no duplicate padding
416 func TestParsePattern(t *testing.T) {
417 for i, tc := range testCases {
418 t.Run(tc.pat, func(t *testing.T) {
419 f, err := ParsePattern(tc.pat)
420 if !reflect.DeepEqual(f, tc.want) {
421 t.Errorf("%d:%s:\ngot %#v;\nwant %#v", i, tc.pat, f, tc.want)
423 if got, want := err != nil, tc.want == nil; got != want {
424 t.Errorf("%d:%s:error: got %v; want %v", i, tc.pat, err, want)
430 func TestPatternSize(t *testing.T) {
431 if sz := unsafe.Sizeof(Pattern{}); sz > 56 {
432 t.Errorf("got %d; want <= 56", sz)