forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparserSpec.js
More file actions
103 lines (91 loc) · 3.98 KB
/
parserSpec.js
File metadata and controls
103 lines (91 loc) · 3.98 KB
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
'use strict';
var parser = require('../src/parser');
var ensureDecimalSep = parser.ensureDecimalSep;
var parsePattern = parser.parsePattern;
describe('ensureDecimalSep', function() {
it('should leave patterns with DECIMAL_SEP untouched', function() {
[
'#,##0.00',
'$#,##0.00',
'#,##0.00$',
'$0.00',
'0.00$',
'0.0',
'#,##0.',
'0.'
].forEach(function(pattern) {
expect(ensureDecimalSep(pattern)).toBe(pattern);
});
});
it('should add a DECIMAL_SEP in patterns that don\'t have one (after the last ZERO)', function() {
var patterns = {
'#,##000': '#,##000.',
'$#,#0#00': '$#,#0#00.',
'#,##000$': '#,##000.$',
'$000': '$000.',
'000$': '000.$',
'00': '00.',
'#,##0': '#,##0.',
'0': '0.'
};
Object.keys(patterns).forEach(function(input) {
var output = patterns[input];
expect(ensureDecimalSep(input)).toBe(output);
});
});
});
describe('parsePattern', function() {
function parseAndExpect(pattern, pp, np, ps, ns, mii, mif, maf, g, lg) {
var p = parsePattern(pattern);
expect(p.minInt).toEqual(mii);
expect(p.minFrac).toEqual(mif);
expect(p.maxFrac).toEqual(maf);
expect(p.posPre).toEqual(pp);
expect(p.posSuf).toEqual(ps);
expect(p.negPre).toEqual(np);
expect(p.negSuf).toEqual(ns);
expect(p.gSize).toBe(g);
expect(p.lgSize).toBe(lg);
}
it('should parse DECIMAL patterns', function() {
// all DECIMAL patterns from closure
parseAndExpect('#,##0.###', '', '-', '', '', 1, 0, 3, 3, 3);
parseAndExpect('#,##0.###;#,##0.###-', '', '', '', '-', 1, 0, 3, 3, 3);
parseAndExpect('#,##,##0.###', '', '-', '', '', 1, 0, 3, 2, 3);
parseAndExpect('#,##0.###;\'\u202A\'-#,##0.###\'\u202C\'',
'', '\u202A-', '', '\u202C', 1, 0, 3, 3, 3);
parseAndExpect('#0.###;#0.###-', '', '', '', '-', 1, 0, 3, 0, 0);
// Even patterns without a DECIMAL_SEP
parseAndExpect('#,##0', '', '-', '', '', 1, 0, 0, 3, 3);
parseAndExpect('+#,##0', '+', '-+', '', '', 1, 0, 0, 3, 3);
parseAndExpect('#,#0;+#,#0', '', '+', '', '', 1, 0, 0, 2, 2);
parseAndExpect('#,##,##0+;(#,##,##0)', '', '(', '+', ')', 1, 0, 0, 2, 3);
});
it('should parse CURRENCY patterns', function() {
// all CURRENCY patterns from closure
parseAndExpect('#,##0.00 \u00A4', '', '-', ' \u00A4', ' \u00A4', 1, 2, 2, 3, 3);
parseAndExpect('#,##0.00\u00A0\u00A4;\'\u202A\'-#,##0.00\'\u202C\'\u00A0\u00A4',
'', '\u202A-', '\u00A0\u00A4', '\u202C\u00A0\u00A4', 1, 2, 2, 3, 3);
parseAndExpect('#,##0.00 \u00A4;(#,##0.00 \u00A4)',
'', '(', ' \u00A4', ' \u00A4)', 1, 2, 2, 3, 3);
parseAndExpect('#,##,##0.00\u00A4', '', '-', '\u00A4', '\u00A4', 1, 2, 2, 2, 3);
parseAndExpect('#,##,##0.00\u00A4;(#,##,##0.00\u00A4)',
'', '(', '\u00A4', '\u00A4)', 1, 2, 2, 2, 3);
parseAndExpect('\u00A4#,##0.00', '\u00A4', '-\u00A4', '', '', 1, 2, 2, 3, 3);
parseAndExpect('\u00A4#,##0.00;(\u00A4#,##0.00)',
'\u00A4', '(\u00A4', '', ')', 1, 2, 2, 3, 3);
parseAndExpect('\u00A4#,##0.00;\u00A4-#,##0.00',
'\u00A4', '\u00A4-', '', '', 1, 2, 2, 3, 3);
parseAndExpect('\u00A4 #,##0.00', '\u00A4 ', '-\u00A4 ', '', '', 1, 2, 2, 3, 3);
parseAndExpect('\u00A4 #,##0.00;\u00A4-#,##0.00',
'\u00A4 ', '\u00A4-', '', '', 1, 2, 2, 3, 3);
parseAndExpect('\u00A4 #,##0.00;\u00A4 #,##0.00-',
'\u00A4 ', '\u00A4 ', '', '-', 1, 2, 2, 3, 3);
parseAndExpect('\u00A4 #,##,##0.00', '\u00A4 ', '-\u00A4 ', '', '', 1, 2, 2, 2, 3);
// Even patterns without a DECIMAL_SEP
parseAndExpect('#,##0 \u00A4', '', '-', ' \u00A4', ' \u00A4', 1, 0, 0, 3, 3);
parseAndExpect('\u00A4 #,##0', '\u00A4 ', '-\u00A4 ', '', '', 1, 0, 0, 3, 3);
parseAndExpect('#,#0 \u00A4;+#,#0\u00A4', '', '+', ' \u00A4', '\u00A4', 1, 0, 0, 2, 2);
parseAndExpect('\u00A4 #,##,##0;(\u00A4 #,##,##0)', '\u00A4 ', '(\u00A4 ', '', ')', 1, 0, 0, 2, 3);
});
});