Skip to content

Commit f0fd876

Browse files
committed
refactor: generated locale tests
1 parent fd04537 commit f0fd876

File tree

6 files changed

+219
-209
lines changed

6 files changed

+219
-209
lines changed

locale-tests/all.test.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { formatNumber, parseNumber, formatDate, parseDate, firstDay, weekendRange, setData } from '../src/main';
2+
import { LOCALES, NO_CURRENCY_LOCALE, clean } from './utils';
3+
4+
describe('generated-locales', () => {
5+
const date = new Date(2000, 0, 1);
6+
const number = 5.55;
7+
const numberString = '5.55';
8+
9+
describe.each(LOCALES)('%s (all)', (locale) => {
10+
beforeAll(() => {
11+
const all = require(`./locales/${ locale }/all`).default;
12+
setData(all);
13+
});
14+
15+
afterAll(() => {
16+
clean();
17+
});
18+
19+
it('format number', () => {
20+
expect(() => {
21+
formatNumber(number, 'n', locale);
22+
}).not.toThrow();
23+
});
24+
25+
it('parse number', () => {
26+
expect(() => {
27+
parseNumber(numberString, locale, 'n');
28+
}).not.toThrow();
29+
});
30+
31+
if (locale !== NO_CURRENCY_LOCALE) {
32+
it('format currency', () => {
33+
expect(() => {
34+
formatNumber(number, 'c', locale);
35+
}).not.toThrow();
36+
});
37+
38+
it('parse currency', () => {
39+
expect(() => {
40+
parseNumber(numberString, locale, 'c');
41+
}).not.toThrow();
42+
});
43+
44+
it('format accounting', () => {
45+
expect(() => {
46+
formatNumber(number, 'a', locale);
47+
}).not.toThrow();
48+
});
49+
50+
it('parse accounting', () => {
51+
expect(() => {
52+
parseNumber(numberString, locale, 'a');
53+
}).not.toThrow();
54+
});
55+
}
56+
57+
it('format date', () => {
58+
expect(() => {
59+
formatDate(date, 'F', locale);
60+
}).not.toThrow();
61+
});
62+
63+
it('parse date', () => {
64+
expect(() => {
65+
parseDate(formatDate(date, 'F'), 'F', locale);
66+
}).not.toThrow();
67+
});
68+
69+
it('firstDay', () => {
70+
expect(() => {
71+
firstDay(locale);
72+
}).not.toThrow();
73+
});
74+
75+
it('weekendRange', () => {
76+
expect(() => {
77+
weekendRange(locale);
78+
}).not.toThrow();
79+
});
80+
});
81+
});

locale-tests/calendar.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { formatDate, parseDate, firstDay, weekendRange, setData } from '../src/main';
2+
import { LOCALES, clean } from './utils';
3+
4+
describe('generated-locales', () => {
5+
const date = new Date(2000, 0, 1);
6+
7+
describe.each(LOCALES)('%s (calendar)', (locale) => {
8+
beforeAll(() => {
9+
const calendar = require(`./locales/${ locale }/calendar`).default;
10+
setData(calendar);
11+
});
12+
13+
afterAll(() => {
14+
clean();
15+
});
16+
17+
it('format', () => {
18+
expect(() => {
19+
formatDate(date, 'F', locale);
20+
}).not.toThrow();
21+
});
22+
23+
it('parse', () => {
24+
expect(() => {
25+
parseDate(formatDate(date, 'F'), 'F', locale);
26+
}).not.toThrow();
27+
});
28+
29+
it('firstDay', () => {
30+
expect(() => {
31+
firstDay(locale);
32+
}).not.toThrow();
33+
});
34+
35+
it('weekendRange', () => {
36+
expect(() => {
37+
weekendRange(locale);
38+
}).not.toThrow();
39+
});
40+
});
41+
});

locale-tests/currency.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { formatNumber, parseNumber, setData } from '../src/main';
2+
import { LOCALES, clean, NO_CURRENCY_LOCALE } from './utils';
3+
4+
const number = 5.55;
5+
const numberString = '5.55';
6+
const currencyLocales = LOCALES.filter(locale => locale !== NO_CURRENCY_LOCALE);
7+
8+
describe.each(currencyLocales)('%s currency', (locale) => {
9+
beforeAll(() => {
10+
const numbers = require(`./locales/${ locale }/numbers`).default;
11+
const currencies = require(`./locales/${ locale }/currencies`).default;
12+
13+
setData(numbers);
14+
setData(currencies);
15+
16+
});
17+
18+
afterAll(() => {
19+
clean();
20+
});
21+
22+
it('format', () => {
23+
expect(() => {
24+
formatNumber(number, 'c', locale);
25+
}).not.toThrow();
26+
});
27+
28+
it('parse', () => {
29+
expect(() => {
30+
parseNumber(numberString, locale, 'c');
31+
}).not.toThrow();
32+
});
33+
34+
it('format accounting', () => {
35+
expect(() => {
36+
formatNumber(number, 'a', locale);
37+
}).not.toThrow();
38+
});
39+
40+
it('parse accounting', () => {
41+
expect(() => {
42+
parseNumber(numberString, locale, 'a');
43+
}).not.toThrow();
44+
});
45+
});

locale-tests/generated-locales.test.js

Lines changed: 0 additions & 209 deletions
This file was deleted.

0 commit comments

Comments
 (0)