diff options
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" }, + ]); +}); |