From e5ae99c6cacb6cca6def0f79c5c8fa5919560a20 Mon Sep 17 00:00:00 2001 From: Frank Tang <41213225+FrankYFTang@users.noreply.github.com> Date: Mon, 15 Oct 2018 10:40:25 -0700 Subject: [PATCH] Change tests to reflect https://github.com/tc39/proposal-intl-list-format/pull/27 (#1860) * Changes Intl.ListFormat tests reflecting spec Reflect https://github.com/tc39/proposal-intl-list-format/pull/27 while style:"narrow" and type is not "unit". * add cases for throws * remove commetns which cause lint error --- .../constructor/options-style-valid.js | 12 ++++++++++-- .../ListFormat/prototype/format/en-us-narrow.js | 9 +++++---- .../prototype/formatToParts/en-us-narrow.js | 17 +++++++++-------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/test/intl402/ListFormat/constructor/constructor/options-style-valid.js b/test/intl402/ListFormat/constructor/constructor/options-style-valid.js index ba699978ea..01d1cd8ee6 100644 --- a/test/intl402/ListFormat/constructor/constructor/options-style-valid.js +++ b/test/intl402/ListFormat/constructor/constructor/options-style-valid.js @@ -8,6 +8,7 @@ info: | InitializeListFormat (listFormat, locales, options) 9. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long"). 10. Set listFormat.[[Style]] to s. + 14. If style is "narrow" and type is not "unit", throw a RangeError exception. features: [Intl.ListFormat] ---*/ @@ -15,8 +16,7 @@ const validOptions = [ [undefined, "long"], ["long", "long"], ["short", "short"], - ["narrow", "narrow"], - [{ toString() { return "narrow"; } }, "narrow"], + [{ toString() { return "short"; } }, "short"], ]; for (const [validOption, expected] of validOptions) { @@ -24,3 +24,11 @@ for (const [validOption, expected] of validOptions) { const resolvedOptions = lf.resolvedOptions(); assert.sameValue(resolvedOptions.style, expected); } + +const lf = new Intl.ListFormat([], {"style": "narrow", "type": "unit"}); +const resolvedOptions = lf.resolvedOptions(); +assert.sameValue(resolvedOptions.style, "narrow"); + +assert.throws(RangeError, () => lf = new Intl.ListFormat([], {"style": "narrow"})); +assert.throws(RangeError, () => lf = new Intl.ListFormat([], {"style": "narrow", "type": "conjuction"})); +assert.throws(RangeError, () => lf = new Intl.ListFormat([], {"style": "narrow", "type": "disjuction"})); diff --git a/test/intl402/ListFormat/prototype/format/en-us-narrow.js b/test/intl402/ListFormat/prototype/format/en-us-narrow.js index 17a6bba49c..dbe6792d6a 100644 --- a/test/intl402/ListFormat/prototype/format/en-us-narrow.js +++ b/test/intl402/ListFormat/prototype/format/en-us-narrow.js @@ -38,6 +38,7 @@ const transforms = [ const lf = new Intl.ListFormat("en-US", { "style": "narrow", + "type": "unit", }); assert.sameValue(typeof lf.format, "function", "format should be supported"); @@ -45,9 +46,9 @@ assert.sameValue(typeof lf.format, "function", "format should be supported"); for (const f of transforms) { assert.sameValue(lf.format(f([])), ""); assert.sameValue(lf.format(f(["foo"])), "foo"); - assert.sameValue(lf.format(f(["foo", "bar"])), "foo and bar"); - assert.sameValue(lf.format(f(["foo", "bar", "baz"])), "foo, bar, and baz"); - assert.sameValue(lf.format(f(["foo", "bar", "baz", "quux"])), "foo, bar, baz, and quux"); + assert.sameValue(lf.format(f(["foo", "bar"])), "foo bar"); + assert.sameValue(lf.format(f(["foo", "bar", "baz"])), "foo bar baz"); + assert.sameValue(lf.format(f(["foo", "bar", "baz", "quux"])), "foo bar baz quux"); } -assert.sameValue(lf.format("foo"), "f, o, and o"); +assert.sameValue(lf.format("foo"), "f o o"); diff --git a/test/intl402/ListFormat/prototype/formatToParts/en-us-narrow.js b/test/intl402/ListFormat/prototype/formatToParts/en-us-narrow.js index 891c8fb372..6d4e7c16e8 100644 --- a/test/intl402/ListFormat/prototype/formatToParts/en-us-narrow.js +++ b/test/intl402/ListFormat/prototype/formatToParts/en-us-narrow.js @@ -47,6 +47,7 @@ const transforms = [ const lf = new Intl.ListFormat("en-US", { "style": "narrow", + "type": "unit", }); assert.sameValue(typeof lf.formatToParts, "function", "formatToParts should be supported"); @@ -58,31 +59,31 @@ for (const f of transforms) { ]); verifyFormatParts(lf.formatToParts(f(["foo", "bar"])), [ { "type": "element", "value": "foo" }, - { "type": "literal", "value": " and " }, + { "type": "literal", "value": " " }, { "type": "element", "value": "bar" }, ]); verifyFormatParts(lf.formatToParts(f(["foo", "bar", "baz"])), [ { "type": "element", "value": "foo" }, - { "type": "literal", "value": ", " }, + { "type": "literal", "value": " " }, { "type": "element", "value": "bar" }, - { "type": "literal", "value": ", and " }, + { "type": "literal", "value": " " }, { "type": "element", "value": "baz" }, ]); verifyFormatParts(lf.formatToParts(f(["foo", "bar", "baz", "quux"])), [ { "type": "element", "value": "foo" }, - { "type": "literal", "value": ", " }, + { "type": "literal", "value": " " }, { "type": "element", "value": "bar" }, - { "type": "literal", "value": ", " }, + { "type": "literal", "value": " " }, { "type": "element", "value": "baz" }, - { "type": "literal", "value": ", and " }, + { "type": "literal", "value": " " }, { "type": "element", "value": "quux" }, ]); } verifyFormatParts(lf.formatToParts("foo"), [ { "type": "element", "value": "f" }, - { "type": "literal", "value": ", " }, + { "type": "literal", "value": " " }, { "type": "element", "value": "o" }, - { "type": "literal", "value": ", and " }, + { "type": "literal", "value": " " }, { "type": "element", "value": "o" }, ]);