diff options
author | Andreu Botella <abb@randomunok.com> | 2022-01-17 06:50:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-17 06:50:10 +0100 |
commit | 76c7b9abf9876dde631d3b20c322a5b08a4a006d (patch) | |
tree | 9b297317da43f1c505697b0bf6ff2325d8a86f7b /cli/tests/unit | |
parent | 51518499b3dc4aef95ec688afc77ec131f2604c1 (diff) |
fix(tsc): Add typings for `Intl.ListFormat` (#13301)
V8 has supported `Intl.ListFormat` since version 7.2, but TypeScript doesn't
have typings for it yet. This PR manually adds those typings, copying them from
microsoft/TypeScript#47254.
Diffstat (limited to 'cli/tests/unit')
-rw-r--r-- | cli/tests/unit/esnext_test.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cli/tests/unit/esnext_test.ts b/cli/tests/unit/esnext_test.ts index cc5e89e80..c6b3c07c2 100644 --- a/cli/tests/unit/esnext_test.ts +++ b/cli/tests/unit/esnext_test.ts @@ -23,3 +23,35 @@ Deno.test(function errorCause() { const e = new Error("test", { cause: "something" }); assertEquals(e.cause, "something"); }); + +Deno.test(function intlListFormat() { + const formatter = new Intl.ListFormat("en", { + style: "long", + type: "conjunction", + }); + assertEquals( + formatter.format(["red", "green", "blue"]), + "red, green, and blue", + ); + + const formatter2 = new Intl.ListFormat("en", { + style: "short", + type: "disjunction", + }); + assertEquals(formatter2.formatToParts(["Rust", "golang"]), [ + { type: "element", value: "Rust" }, + { type: "literal", value: " or " }, + { type: "element", value: "golang" }, + ]); + + // Works with iterables as well + assertEquals( + formatter.format(new Set(["red", "green", "blue"])), + "red, green, and blue", + ); + assertEquals(formatter2.formatToParts(new Set(["Rust", "golang"])), [ + { type: "element", value: "Rust" }, + { type: "literal", value: " or " }, + { type: "element", value: "golang" }, + ]); +}); |