@schukai/monster
Version:
Monster is a simple library for creating fast, robust and lightweight websites.
80 lines (58 loc) • 3.87 kB
JavaScript
import {expect} from "chai"
import {parseLocale, Locale} from "../../../source/i18n/locale.mjs";
describe('Locale', function () {
describe('new instance', function () {
[
// language, region, script, variants, extlang, privateUse
// https://www.rfc-editor.org/rfc/rfc5646.html
['zh', undefined, 'Hant', undefined, undefined, undefined, 'zh-Hant'], // zh-Hant (Chinese written using the Traditional Chinese script)
['de', 'CH', undefined, '1901', undefined, undefined, 'de-CH-1901'], // de-CH-1901 (German as used in Switzerland using the 1901 variant [orthography])
['sl', 'IT', undefined, 'nedis', undefined, undefined, 'sl-IT-nedis'], // sl-IT-nedis (Slovenian as used in Italy, Nadiza dialect)
['hy', 'IT', 'Latn', 'arevela', undefined, undefined, 'hy-Latn-IT-arevela'], // hy-Latn-IT-arevela (Eastern Armenian written in Latin script, as used in Italy)
['zh', 'CN', 'Hans', undefined, undefined, undefined, 'zh-Hans-CN'], // zh-Hans-CN (Chinese written using the Simplified script as used in mainland China)
['sr', 'RS', 'Latn', undefined, undefined, undefined, 'sr-Latn-RS'], // sr-Latn-RS (Serbian written using the Latin script as used in Serbia)
].forEach(function (data) {
let a = data.shift()
let b = data.shift()
let c = data.shift()
let d = data.shift()
let e = data.shift()
let f = data.shift()
let g = data.shift()
it('new Locale(' + a + ',' + b + ',' + c + ',' + d + ',' + e + ',' + f + ') should return ' + g, function () {
expect(new Locale(a, b, c, d, e, f).toString()).is.equal(g)
});
});
});
describe('parseLocale()', function () {
[
// language, region, script, variants, extlang, privateUse
// https://www.rfc-editor.org/rfc/rfc5646.html
['zh', undefined, 'Hant', undefined, undefined, undefined, 'zh-Hant'], // zh-Hant (Chinese written using the Traditional Chinese script)
['de', 'CH', undefined, '1901', undefined, undefined, 'de-CH-1901'], // de-CH-1901 (German as used in Switzerland using the 1901 variant [orthography])
['sl', 'IT', undefined, 'nedis', undefined, undefined, 'sl-IT-nedis'], // sl-IT-nedis (Slovenian as used in Italy, Nadiza dialect)
['hy', 'IT', 'Latn', 'arevela', undefined, undefined, 'hy-Latn-IT-arevela'], // hy-Latn-IT-arevela (Eastern Armenian written in Latin script, as used in Italy)
['zh', 'CN', 'Hans', undefined, undefined, undefined, 'zh-Hans-CN'], // zh-Hans-CN (Chinese written using the Simplified script as used in mainland China)
['sr', 'RS', 'Latn', undefined, undefined, undefined, 'sr-Latn-RS'], // sr-Latn-RS (Serbian written using the Latin script as used in Serbia)
].forEach(function (data) {
let a = data.shift()
let b = data.shift()
let c = data.shift()
let d = data.shift()
let e = data.shift()
let f = data.shift()
let g = data.shift()
it('new Locale(' + a + ',' + b + ',' + c + ',' + d + ',' + e + ',' + f + ') should return ' + g, function () {
const locale = parseLocale(g)
expect(locale.localeString).to.be.equal(g);
expect(locale.language).to.be.equal(a);
expect(locale.region).to.be.equal(b);
expect(locale.script).to.be.equal(c);
expect(locale.variants).to.be.equal(d);
expect(locale.extlang).to.be.equal(e);
expect(locale.privateUse).to.be.equal(f);
expect(new Locale(a, b, c, d, e, f).toString()).is.equal(g)
});
});
});
});