Skip to content

Commit

Permalink
refactor: generated locale tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvetomir committed Jul 6, 2022
1 parent fd04537 commit f0fd876
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 209 deletions.
81 changes: 81 additions & 0 deletions locale-tests/all.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { formatNumber, parseNumber, formatDate, parseDate, firstDay, weekendRange, setData } from '../src/main';
import { LOCALES, NO_CURRENCY_LOCALE, clean } from './utils';

describe('generated-locales', () => {
const date = new Date(2000, 0, 1);
const number = 5.55;
const numberString = '5.55';

describe.each(LOCALES)('%s (all)', (locale) => {
beforeAll(() => {
const all = require(`./locales/${ locale }/all`).default;
setData(all);
});

afterAll(() => {
clean();
});

it('format number', () => {
expect(() => {
formatNumber(number, 'n', locale);
}).not.toThrow();
});

it('parse number', () => {
expect(() => {
parseNumber(numberString, locale, 'n');
}).not.toThrow();
});

if (locale !== NO_CURRENCY_LOCALE) {
it('format currency', () => {
expect(() => {
formatNumber(number, 'c', locale);
}).not.toThrow();
});

it('parse currency', () => {
expect(() => {
parseNumber(numberString, locale, 'c');
}).not.toThrow();
});

it('format accounting', () => {
expect(() => {
formatNumber(number, 'a', locale);
}).not.toThrow();
});

it('parse accounting', () => {
expect(() => {
parseNumber(numberString, locale, 'a');
}).not.toThrow();
});
}

it('format date', () => {
expect(() => {
formatDate(date, 'F', locale);
}).not.toThrow();
});

it('parse date', () => {
expect(() => {
parseDate(formatDate(date, 'F'), 'F', locale);
}).not.toThrow();
});

it('firstDay', () => {
expect(() => {
firstDay(locale);
}).not.toThrow();
});

it('weekendRange', () => {
expect(() => {
weekendRange(locale);
}).not.toThrow();
});
});
});
41 changes: 41 additions & 0 deletions locale-tests/calendar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { formatDate, parseDate, firstDay, weekendRange, setData } from '../src/main';
import { LOCALES, clean } from './utils';

describe('generated-locales', () => {
const date = new Date(2000, 0, 1);

describe.each(LOCALES)('%s (calendar)', (locale) => {
beforeAll(() => {
const calendar = require(`./locales/${ locale }/calendar`).default;
setData(calendar);
});

afterAll(() => {
clean();
});

it('format', () => {
expect(() => {
formatDate(date, 'F', locale);
}).not.toThrow();
});

it('parse', () => {
expect(() => {
parseDate(formatDate(date, 'F'), 'F', locale);
}).not.toThrow();
});

it('firstDay', () => {
expect(() => {
firstDay(locale);
}).not.toThrow();
});

it('weekendRange', () => {
expect(() => {
weekendRange(locale);
}).not.toThrow();
});
});
});
45 changes: 45 additions & 0 deletions locale-tests/currency.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { formatNumber, parseNumber, setData } from '../src/main';
import { LOCALES, clean, NO_CURRENCY_LOCALE } from './utils';

const number = 5.55;
const numberString = '5.55';
const currencyLocales = LOCALES.filter(locale => locale !== NO_CURRENCY_LOCALE);

describe.each(currencyLocales)('%s currency', (locale) => {
beforeAll(() => {
const numbers = require(`./locales/${ locale }/numbers`).default;
const currencies = require(`./locales/${ locale }/currencies`).default;

setData(numbers);
setData(currencies);

});

afterAll(() => {
clean();
});

it('format', () => {
expect(() => {
formatNumber(number, 'c', locale);
}).not.toThrow();
});

it('parse', () => {
expect(() => {
parseNumber(numberString, locale, 'c');
}).not.toThrow();
});

it('format accounting', () => {
expect(() => {
formatNumber(number, 'a', locale);
}).not.toThrow();
});

it('parse accounting', () => {
expect(() => {
parseNumber(numberString, locale, 'a');
}).not.toThrow();
});
});
209 changes: 0 additions & 209 deletions locale-tests/generated-locales.test.js

This file was deleted.

Loading

0 comments on commit f0fd876

Please sign in to comment.