1
|
|
|
/*! |
2
|
|
|
* Copyright (c) 2022 Pedro José Batista, licensed under the MIT License. |
3
|
|
|
* See the LICENSE.md file in the project root for more information. |
4
|
|
|
*/ |
5
|
|
|
import { expect, use } from "chai"; |
6
|
|
|
import chaiSubset from "chai-subset"; |
7
|
|
|
import "mocha"; |
8
|
|
|
import { basicNumbers, constants, Format, randomOptionsCombinations } from "./helpers"; |
9
|
|
|
|
10
|
|
|
use(chaiSubset); |
11
|
|
|
|
12
|
|
|
describe("Randomized localization test (comparing results to native)", () => { |
13
|
|
|
const languages: [undefined, ...string[]] = [] as any; |
14
|
|
|
|
15
|
|
|
for (const locale of [undefined, ...constants.LOCALES]) { |
16
|
|
|
const language = (locale ?? "").replace(/^.*-([a-z]+)$/i, "$1").toLowerCase(); |
17
|
|
|
const firstOfKind = !languages.includes(language); |
18
|
|
|
if (!firstOfKind) continue; |
19
|
|
|
languages.push(language || undefined); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
for (const language of languages.sort()) { |
23
|
|
|
it(`locale=${language || "undefined"}, 822 randomized options variations, should match native`, function () { |
24
|
|
|
this.timeout(5000); |
25
|
|
|
const ecmaOptionsCombinations = randomOptionsCombinations(true); |
26
|
|
|
for (const options of ecmaOptionsCombinations) { |
27
|
|
|
const decFormat = new Format(language, options); |
28
|
|
|
const numFormat = new Intl.NumberFormat(language, options as Intl.NumberFormatOptions); |
29
|
|
|
|
30
|
|
|
for (const number of basicNumbers) { |
31
|
|
|
const decParts = decFormat.formatToParts(number); |
32
|
|
|
const numParts = numFormat.formatToParts(number as any); |
33
|
|
|
|
34
|
|
|
expect(decParts.length).to.equal(numParts.length); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
}); |
38
|
|
|
} |
39
|
|
|
}); |
40
|
|
|
|