aboutsummaryrefslogtreecommitdiffstats
path: root/i18n/spec
diff options
context:
space:
mode:
Diffstat (limited to 'i18n/spec')
-rw-r--r--i18n/spec/converterSpec.js53
-rw-r--r--i18n/spec/parserSpec.js51
-rw-r--r--i18n/spec/utilSpec.js14
3 files changed, 118 insertions, 0 deletions
diff --git a/i18n/spec/converterSpec.js b/i18n/spec/converterSpec.js
new file mode 100644
index 00000000..a7879e6b
--- /dev/null
+++ b/i18n/spec/converterSpec.js
@@ -0,0 +1,53 @@
+var converter = require('../src/converter.js');
+
+describe("convertNumberData", function() {
+ var convert = converter.convertNumberData,
+ dataObj = { DECIMAL_SEP: ',',
+ GROUP_SEP: '.',
+ DECIMAL_PATTERN: '#,##0.###;#,##0.###-',
+ CURRENCY_PATTERN: '\u00A4#,##0.00;\u00A4#,##0.00-',
+ DEF_CURRENCY_CODE: 'USD' };
+
+ it('should convert number object', function() {
+ var processedData = convert(dataObj, {USD: ['x', '$', 'y']});
+ expect(processedData.DECIMAL_SEP).toBe(',');
+ expect(processedData.GROUP_SEP).toBe('.');
+ expect(processedData.PATTERNS.length).toBe(2);
+ expect(processedData.PATTERNS[0].gSize).toBe(3);
+ expect(processedData.PATTERNS[0].negSuf).toBe('-');
+ expect(processedData.CURRENCY_SYM).toBe('$');
+
+ dataObj.DEF_CURRENCY_CODE = 'NoSuchCode';
+ processedData = convert(dataObj, {});
+ expect(processedData.CURRENCY_SYM).toBe('NoSuchCode');
+ });
+});
+
+
+describe("convertDatetimeData", function() {
+ var convert = converter.convertDatetimeData,
+ dataObj = { MONTHS: ['Enero', 'Pebrero'],
+ SHORTMONTHS: ['Ene', 'Peb'],
+ WEEKDAYS: ['Linggo', 'Lunes'],
+ SHORTWEEKDAYS: ['Lin', 'Lun'],
+ AMPMS: ['AM', 'PM'],
+ DATEFORMATS: ['a', 'b', 'c', 'd'],
+ TIMEFORMATS: ['e', 'f', 'g', 'h'] };
+
+ it('should convert empty datetime obj', function() {
+ var processedData = convert(dataObj);
+ expect(processedData.MONTH).toEqual(['Enero', 'Pebrero']);
+ expect(processedData.SHORTMONTH).toEqual(['Ene', 'Peb']);
+ expect(processedData.DAY).toEqual(['Linggo', 'Lunes']);
+ expect(processedData.SHORTDAY).toEqual(['Lin', 'Lun']);
+ expect(processedData.AMPMS).toEqual(['AM', 'PM']);
+ expect(processedData.medium).toBe('c g');
+ expect(processedData.short).toBe('d h');
+ expect(processedData.fullDate).toBe('a');
+ expect(processedData.longDate).toBe('b');
+ expect(processedData.mediumDate).toBe('c');
+ expect(processedData.shortDate).toBe('d');
+ expect(processedData.mediumTime).toBe('g');
+ expect(processedData.shortTime).toBe('h');
+ });
+});
diff --git a/i18n/spec/parserSpec.js b/i18n/spec/parserSpec.js
new file mode 100644
index 00000000..2904e31c
--- /dev/null
+++ b/i18n/spec/parserSpec.js
@@ -0,0 +1,51 @@
+var parsePattern = require('../src/parser.js').parsePattern;
+
+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);
+ });
+
+ 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);
+ });
+});
diff --git a/i18n/spec/utilSpec.js b/i18n/spec/utilSpec.js
new file mode 100644
index 00000000..e6304254
--- /dev/null
+++ b/i18n/spec/utilSpec.js
@@ -0,0 +1,14 @@
+var util = require('../src/util.js');
+
+describe('findLocaleId', function() {
+ it('should find localeId', function() {
+ expect(util.findLocaleId('', 'num')).toBeUndefined();
+ expect(util.findLocaleId('aa', 'datetime')).toBeUndefined();
+ expect(util.findLocaleId('aa', 'randomType')).toBeUndefined();
+ expect(util.findLocaleId('NumberFormatSymbols_en', 'datetime')).toBeUndefined();
+ expect(util.findLocaleId('DateTimeSymbols_en', 'num')).toBeUndefined();
+
+ expect(util.findLocaleId('DateTimeSymbols_en', 'datetime')).toBe('en');
+ expect(util.findLocaleId('NumberFormatSymbols_en_US', 'num')).toBe('en_US');
+ });
+});