diff options
Diffstat (limited to 'js/src/tests/test262/intl402/Segmenter/constructor')
43 files changed, 1285 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/browser.js b/js/src/tests/test262/intl402/Segmenter/constructor/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/browser.js diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/browser.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/browser.js diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/locales-invalid.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/locales-invalid.js new file mode 100644 index 0000000000..cb4b709c05 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/locales-invalid.js @@ -0,0 +1,20 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks error cases for the locales argument to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 3. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_). +includes: [testIntl.js] +features: [Intl.Segmenter] +---*/ + +for (const [locales, expectedError] of getInvalidLocaleArguments()) { + assert.throws(expectedError, function() { new Intl.Segmenter(locales) }) +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/locales-valid.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/locales-valid.js new file mode 100644 index 0000000000..3aa9976448 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/locales-valid.js @@ -0,0 +1,53 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks various cases for the locales argument to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 3. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_). +features: [Intl.Segmenter, Array.prototype.includes] +---*/ + +const defaultLocale = new Intl.Segmenter().resolvedOptions().locale; + +const tests = [ + [undefined, [defaultLocale], "undefined"], + ["EN", ["en"], "Single value"], + [[], [defaultLocale], "Empty array"], + [["sr"], ["sr"], "Single-element array"], + [["fr", "ar"], ["fr", "ar"], "Two-element array"], + [["xyz", "ar"], ["ar"], "Two-element array with unknown code"], + [["en", "EN"], ["en"], "Duplicate value (canonical first)"], + [["EN", "en"], ["en"], "Duplicate value (canonical last)"], + [{ 0: "DE", length: 0 }, [defaultLocale], "Object with zero length"], + [{ 0: "DE", length: 1 }, ["de"], "Object with length"], + [{ 0: "ja", 1: "fr" }, [defaultLocale], "Object without length, indexed from 0"], + [{ 1: "ja", 2: "fr" }, [defaultLocale], "Object without length, indexed from 1"], +]; + +const errorTests = [ + [["en-GB-oed"], "Grandfathered"], + [["x-private"], "Private", ["lookup"]], +]; + +for (const [locales, expected, name, matchers = ["best fit", "lookup"]] of tests) { + for (const localeMatcher of matchers) { + const segmenter = new Intl.Segmenter(locales, { localeMatcher }); + const actual = segmenter.resolvedOptions().locale; + assert(expected.includes(actual), `${name}: expected one of ${expected}, found ${actual}`); + } +} + +for (const [locales, name, matchers = ["best fit", "lookup"]] of errorTests) { + for (const localeMatcher of matchers) { + assert.throws(RangeError, function() { + new Intl.Segmenter(locales, { localeMatcher }); + }, name); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/newtarget-undefined.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/newtarget-undefined.js new file mode 100644 index 0000000000..37d4d35d2b --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/newtarget-undefined.js @@ -0,0 +1,29 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Verifies the NewTarget check for Intl.Segmenter. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter, "function"); + +assert.throws(TypeError, function() { + Intl.Segmenter(); +}); + +assert.throws(TypeError, function() { + Intl.Segmenter("en"); +}); + +assert.throws(TypeError, function() { + Intl.Segmenter("not-valid-tag"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-getoptionsobject.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-getoptionsobject.js new file mode 100644 index 0000000000..c8a1851ae3 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-getoptionsobject.js @@ -0,0 +1,28 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks handling of non-object option arguments to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + +features: [Intl.Segmenter,BigInt] +---*/ + +const optionsArguments = [ + null, + true, + false, + "test", + 7, + Symbol(), + 123456789n, +]; + +for (const options of optionsArguments) { + assert.throws(TypeError, function() { new Intl.Segment([], options) }) +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-abrupt-throws.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-abrupt-throws.js new file mode 100644 index 0000000000..ed64988cfd --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-abrupt-throws.js @@ -0,0 +1,28 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.segmenter +description: Return abrupt completion from GetOption granularity +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 13. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme"). + + GetOption ( options, property, type, values, fallback ) + 1. Let value be ? Get(options, property). +features: [Intl.Segmenter] +---*/ + + +var options = {}; +Object.defineProperty(options, 'granularity', { + get() { throw new Test262Error(); }, +}); + +assert.throws(Test262Error, () => { + new Intl.Segmenter(undefined, options); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-invalid.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-invalid.js new file mode 100644 index 0000000000..37f0fa262d --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-invalid.js @@ -0,0 +1,42 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks handling of invalid value for the style option to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 13. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme"). + 14. Set segmenter.[[SegmenterGranularity]] to granularity. +features: [Intl.Segmenter] +---*/ + +const invalidOptions = [ + null, + 1, + "", + "standard", + "Grapheme", + "GRAPHEME", + "grapheme\0", + "Word", + "WORD", + "word\0", + "Sentence", + "SENTENCE", + "sentence\0", + "line", + "Line", + "LINE", + "line\0", +]; + +for (const granularity of invalidOptions) { + assert.throws(RangeError, function() { + new Intl.Segmenter([], { granularity }); + }, `${granularity} is an invalid style option value`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-toString-abrupt-throws.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-toString-abrupt-throws.js new file mode 100644 index 0000000000..547dd69381 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-toString-abrupt-throws.js @@ -0,0 +1,59 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.segmenter +description: Return abrupt completion from GetOption granularity + +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 13. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme"). + + GetOption ( options, property, type, values, fallback ) + 6. If type is "string", then + a. Let value be ? ToString(value). +features: [Intl.Segmenter, Symbol] +---*/ + +const options = { + granularity: { + toString() { + throw new Test262Error(); + } + } +}; + +assert.throws(Test262Error, () => { + new Intl.Segmenter(undefined, options); +}, 'from toString'); + +options.granularity = { + toString: undefined, + valueOf() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.Segmenter(undefined, options); +}, 'from valueOf'); + +options.granularity = { + [Symbol.toPrimitive]() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.Segmenter(undefined, options); +}, 'from ToPrimitive'); + +options.granularity = Symbol(); + +assert.throws(TypeError, () => { + new Intl.Segmenter(undefined, options); +}, 'symbol value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-valid.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-valid.js new file mode 100644 index 0000000000..f96b1cf45a --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-granularity-valid.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks handling of valid values for the granularity option to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 11. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme"). + 12. Set segmenter.[[SegmenterGranularity]] to granularity. +features: [Intl.Segmenter] +---*/ + +const validOptions = [ + [undefined, "grapheme"], + ["grapheme", "grapheme"], + ["word", "word"], + ["sentence", "sentence"], + [{ toString() { return "word"; } }, "word"], +]; + +for (const [granularity, expected] of validOptions) { + const segmenter = new Intl.Segmenter([], { granularity }); + const resolvedOptions = segmenter.resolvedOptions(); + assert.sameValue(resolvedOptions.granularity, expected); +} + +assert.throws(RangeError, () => new Intl.Segmenter([], {granularity: "line"})); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-invalid.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-invalid.js new file mode 100644 index 0000000000..107efa8c9b --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-invalid.js @@ -0,0 +1,20 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks handling of a null options argument to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 5. Else + a. Let options be ? ToObject(options). +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter, "function"); + +assert.throws(TypeError, function() { new Intl.Segmenter([], null) }) + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-abrupt-throws.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-abrupt-throws.js new file mode 100644 index 0000000000..16548dcc13 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-abrupt-throws.js @@ -0,0 +1,34 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.segmenter +description: > + Return abrupt completion from GetOption localeMatcher +info: | + Intl.Segmenter ([ locales [ , options ]]) + 1. If NewTarget is undefined, throw a TypeError exception. + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + GetOption ( options, property, type, values, fallback ) + 1. Let value be ? Get(options, property). + ... +features: [Intl.Segmenter] +---*/ + +var options = {}; +Object.defineProperty(options, 'localeMatcher', { + get() { throw new Test262Error(); }, +}); + +assert.throws(Test262Error, () => { + new Intl.Segmenter(undefined, options); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-invalid.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-invalid.js new file mode 100644 index 0000000000..53fe25e8a5 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-invalid.js @@ -0,0 +1,33 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks handling of invalid value for the localeMatcher option to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 7. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). +features: [Intl.Segmenter] +---*/ + +const invalidOptions = [ + null, + 1, + "", + "Lookup", + "LOOKUP", + "lookup\0", + "Best fit", + "BEST FIT", + "best\u00a0fit", +]; + +for (const localeMatcher of invalidOptions) { + assert.throws(RangeError, function() { + new Intl.Segmenter([], { localeMatcher }); + }, `${localeMatcher} is an invalid localeMatcher option value`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-toString-abrupt-throws.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-toString-abrupt-throws.js new file mode 100644 index 0000000000..991af934db --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-toString-abrupt-throws.js @@ -0,0 +1,68 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.segmenter +description: > + Return abrupt completion from GetOption localeMatcher +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + + GetOption ( options, property, type, values, fallback ) + 6. If type is "string", then + a. Let value be ? ToString(value). + ... +features: [Intl.Segmenter, Symbol] +---*/ + +const options = { + localeMatcher: { + toString() { + throw new Test262Error(); + } + } +}; + +assert.throws(Test262Error, () => { + new Intl.Segmenter(undefined, options); +}, 'from toString'); + +options.localeMatcher = { + toString: undefined, + valueOf() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.Segmenter(undefined, options); +}, 'from valueOf'); + +options.localeMatcher = { + [Symbol.toPrimitive]() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.Segmenter(undefined, options); +}, 'from ToPrimitive'); + +options.localeMatcher = Symbol(); + +assert.throws(TypeError, () => { + new Intl.Segmenter(undefined, options); +}, 'symbol value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-valid.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-valid.js new file mode 100644 index 0000000000..e572cf14b7 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-localeMatcher-valid.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.segmenter +description: > + Valid options for localeMatcher +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.Segmenter] +locale: [en] +---*/ + +// results for option values verified in the tests for resolvedOptions + +const localeMatchers = [ + undefined, + 'lookup', + 'best fit' +]; + +localeMatchers.forEach(localeMatcher => { + const obj = new Intl.Segmenter(undefined, { localeMatcher }); + + assert(obj instanceof Intl.Segmenter, `instanceof check - ${localeMatcher}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.Segmenter.prototype, `proto check - ${localeMatcher}`); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-null.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-null.js new file mode 100644 index 0000000000..f3f9d56c31 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-null.js @@ -0,0 +1,26 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.Segmenter +description: > + Throws TypeError if options is null +info: | + Intl.Segmenter ([ locales [ , options ]]) + 1. If NewTarget is undefined, throw a TypeError exception. + 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... +features: [Intl.Segmenter] +---*/ + +assert.throws(TypeError, () => { + new Intl.Segmenter(undefined, null); +}, 'null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-order.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-order.js new file mode 100644 index 0000000000..aaf1464569 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-order.js @@ -0,0 +1,56 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks the order of operations on the options argument to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 7. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + 11. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme"). +includes: [compareArray.js] +features: [Intl.Segmenter] +---*/ + +const callOrder = []; + +new Intl.Segmenter([], { + get localeMatcher() { + callOrder.push("localeMatcher"); + return { + toString() { + callOrder.push("localeMatcher toString"); + return "best fit"; + } + }; + }, + get lineBreakStyle() { + callOrder.push("lineBreakStyle"); + return { + toString() { + callOrder.push("lineBreakStyle toString"); + return "strict"; + } + }; + }, + get granularity() { + callOrder.push("granularity"); + return { + toString() { + callOrder.push("granularity toString"); + return "word"; + } + }; + }, +}); + +assert.compareArray(callOrder, [ + "localeMatcher", + "localeMatcher toString", + "granularity", + "granularity toString", +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-throwing-getters.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-throwing-getters.js new file mode 100644 index 0000000000..4329cfedcd --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-throwing-getters.js @@ -0,0 +1,28 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks the propagation of exceptions from the options for the Segmenter constructor. +features: [Intl.Segmenter] +---*/ + +function CustomError() {} + +const options = [ + "localeMatcher", + "granularity", +]; + +for (const option of options) { + assert.throws(CustomError, () => { + new Intl.Segmenter("en", { + get [option]() { + throw new CustomError(); + } + }); + }, `Exception from ${option} getter should be propagated`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-undefined.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-undefined.js new file mode 100644 index 0000000000..76486524f9 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-undefined.js @@ -0,0 +1,52 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks handling of non-object option arguments to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 4. If options is undefined, then + a. Let options be ObjectCreate(null). +features: [Intl.Segmenter] +---*/ + +Object.defineProperties(Object.prototype, { + "localeMatcher": { + "get": function() { + throw new Error("Should not call getter on Object.prototype: localeMatcher"); + }, + }, + + "lineBreakStyle": { + "get": function() { + throw new Error("Should not call getter on Object.prototype: lineBreakStyle"); + }, + }, + + "granularity": { + "get": function() { + throw new Error("Should not call getter on Object.prototype: granularity"); + }, + }, +}); + +const optionsArguments = [ + [], + [[]], + [[], undefined], +]; + +for (const args of optionsArguments) { + const segmenter = new Intl.Segmenter(...args); + const resolvedOptions = segmenter.resolvedOptions(); + assert.sameValue(resolvedOptions.granularity, "grapheme", + `Calling with ${args.length} empty arguments should yield the correct value for "granularity"`); + assert( + !Object.prototype.hasOwnProperty.call(resolvedOptions, "lineBreakStyle"), + `Calling with ${args.length} empty arguments should yield the correct value for "lineBreakStyle"`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-valid-combinations.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-valid-combinations.js new file mode 100644 index 0000000000..dfddc80cee --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/options-valid-combinations.js @@ -0,0 +1,39 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 the V8 project authors, Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks handling of valid values for the granularity option to the Segmenter constructor. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 11. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme"). + 12. Set segmenter.[[SegmenterGranularity]] to granularity. +features: [Intl.Segmenter] +---*/ + +const granularityOptions = ["grapheme", "word", "sentence"]; +const combinations = []; + +combinations.push([ + {}, + "grapheme", + undefined, +]); + +for (const granularity of granularityOptions) { + combinations.push([ + { granularity }, + granularity, + undefined, + ]); +} + +for (const [input, granularity, lineBreakStyle] of combinations) { + const segmenter = new Intl.Segmenter([], input); + const resolvedOptions = segmenter.resolvedOptions(); + assert.sameValue(resolvedOptions.granularity, granularity); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/proto-from-ctor-realm.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/proto-from-ctor-realm.js new file mode 100644 index 0000000000..e3bc3b7be1 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/proto-from-ctor-realm.js @@ -0,0 +1,61 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Default [[Prototype]] value derived from realm of the NewTarget. +info: | + Intl.Segmenter ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%SegmenterPrototype%", « [[InitializedSegmenter]] »). + ... + 14. Return segmenter. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, 'prototype'). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [Intl.Segmenter, cross-realm, Reflect, Symbol] +---*/ + +var other = $262.createRealm().global; +var newTarget = new other.Function(); +var seg; + +newTarget.prototype = undefined; +seg = Reflect.construct(Intl.Segmenter, [], newTarget); +assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is undefined'); + +newTarget.prototype = null; +seg = Reflect.construct(Intl.Segmenter, [], newTarget); +assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is null'); + +newTarget.prototype = false; +seg = Reflect.construct(Intl.Segmenter, [], newTarget); +assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Boolean'); + +newTarget.prototype = 'str'; +seg = Reflect.construct(Intl.Segmenter, [], newTarget); +assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is a String'); + +newTarget.prototype = Symbol(); +seg = Reflect.construct(Intl.Segmenter, [], newTarget); +assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Symbol'); + +newTarget.prototype = 1; +seg = Reflect.construct(Intl.Segmenter, [], newTarget); +assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Number'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/shell.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/shell.js diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/constructor/subclassing.js b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/subclassing.js new file mode 100644 index 0000000000..485ece668b --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/constructor/subclassing.js @@ -0,0 +1,56 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks that Segmenter can be subclassed. +info: | + Intl.Segmenter ( [ locales [ , options ] ] ) + + 2. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%SegmenterPrototype%", « [[InitializedSegmenter]] »). +includes: [compareArray.js] +features: [Intl.Segmenter] +---*/ + +function segments(iterator) { + return [...iterator].map(result => result.segment); +} + +class CustomSegmenter extends Intl.Segmenter { + constructor(locales, options) { + super(locales, options); + this.isCustom = true; + } +} + +const locale = "de"; +const value = "Hello"; + +const real_segmenter = new Intl.Segmenter(locale); +assert.sameValue(real_segmenter.isCustom, undefined, "Custom property"); + +const custom_segmenter = new CustomSegmenter(locale); +assert.sameValue(custom_segmenter.isCustom, true, "Custom property"); + +assert.compareArray(segments(custom_segmenter.segment(value)), + segments(real_segmenter.segment(value)), + "Direct call"); + +assert.compareArray(segments(Intl.Segmenter.prototype.segment.call(custom_segmenter, value)), + segments(Intl.Segmenter.prototype.segment.call(real_segmenter, value)), + "Indirect call"); + +assert.sameValue(Object.getPrototypeOf(custom_segmenter), CustomSegmenter.prototype, "Prototype"); +assert.sameValue(Object.getPrototypeOf(CustomSegmenter), Intl.Segmenter, + "Object.getPrototypeOf(CustomSegmenter) returns Intl.Segmenter"); +assert.sameValue(Object.getPrototypeOf(CustomSegmenter.prototype), Intl.Segmenter.prototype, + "Object.getPrototypeOf(CustomSegmenter.prototype) returns Intl.Segmenter.prototype"); +assert.sameValue(custom_segmenter instanceof Intl.Segmenter, true, + "The result of `custom_segmenter instanceof Intl.Segmenter` is true"); + +assert.throws(TypeError, function() { + CustomSegmenter(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/length.js b/js/src/tests/test262/intl402/Segmenter/constructor/length.js new file mode 100644 index 0000000000..97bcaf7a38 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/length.js @@ -0,0 +1,25 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: > + Checks the "length" property of the Segmenter constructor. +info: | + Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor. + The Segmenter constructor is a standard built-in property of the Intl object. + Every built-in function object, including constructors, has a length property whose value is an integer. Unless otherwise specified, this value is equal to the largest number of named arguments shown in the subclause headings for the function description. Optional parameters (which are indicated with brackets: [ ]) or rest parameters (which are shown using the form «...name») are not included in the default argument count. + Unless otherwise specified, the length property of a built-in function object has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.Segmenter] +---*/ + +verifyProperty(Intl.Segmenter, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/name.js b/js/src/tests/test262/intl402/Segmenter/constructor/name.js new file mode 100644 index 0000000000..f055578fe8 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/name.js @@ -0,0 +1,23 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Checks the "name" property of the Segmenter constructor. +info: | + Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor. + Every built-in function object, including constructors, that is not identified as an anonymous function has a name property whose value is a String. Unless otherwise specified, this value is the name that is given to the function in this specification. + Unless otherwise specified, the name property of a built-in function object, if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.Segmenter] +---*/ + +verifyProperty(Intl.Segmenter, "name", { + value: "Segmenter", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/prop-desc.js b/js/src/tests/test262/intl402/Segmenter/constructor/prop-desc.js new file mode 100644 index 0000000000..bab8f0d3a4 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/prop-desc.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: Verifies the "Segmenter" property of Intl. +info: | + Requirements for Standard Built-in ECMAScript Objects + + Unless specified otherwise in this document, the objects, functions, and constructors + described in this standard are subject to the generic requirements and restrictions + specified for standard built-in ECMAScript objects in the ECMAScript 2018 Language + Specification, 9th edition, clause 17, or successor. + + ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 has the + attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true } + unless otherwise specified. + +includes: [propertyHelper.js] +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter, "function"); + +verifyProperty(Intl, "Segmenter", { + value: Intl.Segmenter, + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/prototype.js b/js/src/tests/test262/intl402/Segmenter/constructor/prototype.js new file mode 100644 index 0000000000..7725c52654 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/prototype.js @@ -0,0 +1,20 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter +description: The prototype of the Intl.Segmenter constructor is %FunctionPrototype%. +info: | + Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor. + Unless otherwise specified every built-in function object has the %FunctionPrototype% object as the initial value of its [[Prototype]] internal slot. +features: [Intl.Segmenter] +---*/ + +assert.sameValue( + Object.getPrototypeOf(Intl.Segmenter), + Function.prototype, + "Object.getPrototypeOf(Intl.Segmenter) equals the value of Function.prototype" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/shell.js b/js/src/tests/test262/intl402/Segmenter/constructor/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/shell.js diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/basic.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/basic.js new file mode 100644 index 0000000000..d2f847e0e1 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/basic.js @@ -0,0 +1,22 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: Tests that Intl.Segmenter has a supportedLocalesOf property, and it works as expected. +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter.supportedLocalesOf, "function", + "supportedLocalesOf should be supported."); + +const defaultLocale = new Intl.Segmenter().resolvedOptions().locale; +const notSupported = "zxx"; // "no linguistic content" +const requestedLocales = [defaultLocale, notSupported]; + +const supportedLocales = Intl.Segmenter.supportedLocalesOf(requestedLocales); +assert.sameValue(supportedLocales.length, 1, "The length of supported locales list is not 1."); +assert.sameValue(supportedLocales[0], defaultLocale, "The default locale is not returned in the supported list."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/branding.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/branding.js new file mode 100644 index 0000000000..dee2601595 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/branding.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: > + Verifies there's no branding check for Intl.Segmenter.supportedLocalesOf(). +info: | + Intl.Segmenter.supportedLocalesOf ( locales [, options ]) +features: [Intl.Segmenter] +---*/ + +const supportedLocalesOf = Intl.Segmenter.supportedLocalesOf; + +assert.sameValue(typeof supportedLocalesOf, "function"); + +const thisValues = [ + undefined, + null, + true, + "", + Symbol(), + 1, + {}, + Intl.Segmenter, + Intl.Segmenter.prototype, +]; + +for (const thisValue of thisValues) { + const result = supportedLocalesOf.call(thisValue); + assert.sameValue(Array.isArray(result), true); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/browser.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/browser.js diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/length.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/length.js new file mode 100644 index 0000000000..e9bcaa18bc --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/length.js @@ -0,0 +1,25 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: > + Checks the "length" property of Intl.Segmenter.supportedLocalesOf(). +info: | + The value of the length property of the supportedLocalesOf method is 1. + Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor. + Every built-in function object, including constructors, has a length property whose value is an integer. + Unless otherwise specified, the length property of a built-in function object has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.Segmenter] +---*/ + +verifyProperty(Intl.Segmenter.supportedLocalesOf, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/locales-empty.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/locales-empty.js new file mode 100644 index 0000000000..642ab7f744 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/locales-empty.js @@ -0,0 +1,22 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 the V8 project authors, Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: Checks handling of an empty locales argument to the supportedLocalesOf function. +info: | + Intl.Segmenter.supportedLocalesOf ( locales [, options ]) + + 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). +includes: [compareArray.js] +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter.supportedLocalesOf, "function", + "Should support Intl.Segmenter.supportedLocalesOf."); + +assert.compareArray(Intl.Segmenter.supportedLocalesOf(), []); +assert.compareArray(Intl.Segmenter.supportedLocalesOf([]), []); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/locales-invalid.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/locales-invalid.js new file mode 100644 index 0000000000..a8cc8ffbde --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/locales-invalid.js @@ -0,0 +1,23 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: Checks error cases for the locales argument to the supportedLocalesOf function. +info: | + Intl.Segmenter.supportedLocalesOf ( locales [, options ]) + + 2. Let requestedLocales be CanonicalizeLocaleList(locales). +includes: [testIntl.js] +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter.supportedLocalesOf, "function", + "Should support Intl.Segmenter.supportedLocalesOf."); + +for (const [locales, expectedError] of getInvalidLocaleArguments()) { + assert.throws(expectedError, () => Intl.Segmenter.supportedLocalesOf(locales)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/locales-specific.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/locales-specific.js new file mode 100644 index 0000000000..17970524f0 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/locales-specific.js @@ -0,0 +1,25 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 the V8 project authors, Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: Checks handling of specific locales arguments to the supportedLocalesOf function. +info: | + Intl.Segmenter.supportedLocalesOf ( locales [, options ]) + + 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). +includes: [compareArray.js] +locale: [sr, sr-Thai-RS, de, zh-CN] +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter.supportedLocalesOf, "function", + "Should support Intl.Segmenter.supportedLocalesOf."); + +assert.compareArray(Intl.Segmenter.supportedLocalesOf("sr"), ["sr"]); + +const multiLocale = ["sr-Thai-RS", "de", "zh-CN"]; +assert.compareArray(Intl.Segmenter.supportedLocalesOf(multiLocale, {localeMatcher: "lookup"}), multiLocale); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/name.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/name.js new file mode 100644 index 0000000000..c4fdcfff14 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/name.js @@ -0,0 +1,24 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: > + Checks the "name" property of Intl.Segmenter.supportedLocalesOf(). +info: | + Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor. + Every built-in function object, including constructors, that is not identified as an anonymous function has a name property whose value is a String. Unless otherwise specified, this value is the name that is given to the function in this specification. + Unless otherwise specified, the name property of a built-in function object, if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.Segmenter] +---*/ + +verifyProperty(Intl.Segmenter.supportedLocalesOf, "name", { + value: "supportedLocalesOf", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-localeMatcher-invalid.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-localeMatcher-invalid.js new file mode 100644 index 0000000000..02d1699849 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-localeMatcher-invalid.js @@ -0,0 +1,37 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: Checks handling of invalid values for the localeMatcher option to the supportedLocalesOf function. +info: | + SupportedLocales ( availableLocales, requestedLocales, options ) + + 1. If options is not undefined, then + b. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter.supportedLocalesOf, "function", + "Should support Intl.Segmenter.supportedLocalesOf."); + +const invalidOptions = [ + null, + 1, + "", + "Lookup", + "LOOKUP", + "lookup\0", + "Best fit", + "BEST FIT", + "best\u00a0fit", +]; + +for (const invalidOption of invalidOptions) { + assert.throws(RangeError, function() { + Intl.Segmenter.supportedLocalesOf([], {"localeMatcher": invalidOption}); + }, `${invalidOption} is an invalid localeMatcher option value`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-null.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-null.js new file mode 100644 index 0000000000..f97ad6627f --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-null.js @@ -0,0 +1,23 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: Checks handling of a null options argument to the supportedLocalesOf function. +info: | + SupportedLocales ( availableLocales, requestedLocales, options ) + + 1. If options is not undefined, then + a. Let options be ? ToObject(options). +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter.supportedLocalesOf, "function", + "Should support Intl.Segmenter.supportedLocalesOf."); + +assert.throws(TypeError, function() { + Intl.Segmenter.supportedLocalesOf([], null); +}, "Should throw when passing null as the options argument"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-toobject.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-toobject.js new file mode 100644 index 0000000000..db621a80c6 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-toobject.js @@ -0,0 +1,44 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: Checks handling of non-object options arguments to the supportedLocalesOf function. +info: | + SupportedLocales ( availableLocales, requestedLocales, options ) + + 1. If options is not undefined, then + a. Let options be ? ToObject(options). +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter.supportedLocalesOf, "function", + "Should support Intl.Segmenter.supportedLocalesOf."); + +let called; +Object.defineProperties(Object.prototype, { + "localeMatcher": { + get() { + ++called; + return "best fit"; + } + } +}); + +const optionsArguments = [ + true, + "test", + 7, + Symbol(), +]; + +for (const options of optionsArguments) { + called = 0; + const result = Intl.Segmenter.supportedLocalesOf([], options); + assert.sameValue(Array.isArray(result), true, `Expected array from ${String(options)}`); + assert.sameValue(called, 1, `Expected one call from ${String(options)}`); +} + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-undefined.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-undefined.js new file mode 100644 index 0000000000..b81006fe81 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/options-undefined.js @@ -0,0 +1,29 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: Checks handling of an undefined options argument to the supportedLocalesOf function. +info: | + SupportedLocales ( availableLocales, requestedLocales, options ) + + 1. If options is not undefined, then + b. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). +features: [Intl.Segmenter] +---*/ + +assert.sameValue(typeof Intl.Segmenter.supportedLocalesOf, "function", + "Should support Intl.Segmenter.supportedLocalesOf."); + +Object.defineProperties(Object.prototype, { + "localeMatcher": { + get() { throw new Error("Should not call localeMatcher getter"); } + } +}); + +assert.sameValue(Array.isArray(Intl.Segmenter.supportedLocalesOf()), true, "No arguments"); +assert.sameValue(Array.isArray(Intl.Segmenter.supportedLocalesOf([])), true, "One argument"); +assert.sameValue(Array.isArray(Intl.Segmenter.supportedLocalesOf([], undefined)), true, "Two arguments"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/prop-desc.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/prop-desc.js new file mode 100644 index 0000000000..ac246193b2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/prop-desc.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: > + Checks the "supportedLocalesOf" property of the Segmenter prototype object. +info: | + Intl.Segmenter.supportedLocalesOf ( locales [, options ]) + + Unless specified otherwise in this document, the objects, functions, and constructors described in this standard are subject to the generic requirements and restrictions specified for standard built-in ECMAScript objects in the ECMAScript 2019 Language Specification, 10th edition, clause 17, or successor. + + Every other data property described in clauses 18 through 26 and in Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [Intl.Segmenter] +---*/ + +assert.sameValue( + typeof Intl.Segmenter.supportedLocalesOf, + "function", + "typeof Intl.Segmenter.supportedLocalesOf is function" +); + +verifyProperty(Intl.Segmenter, "supportedLocalesOf", { + writable: true, + enumerable: false, + configurable: true, +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/result-type.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/result-type.js new file mode 100644 index 0000000000..f476c36251 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/result-type.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.supportedLocalesOf +description: Verifies the type of the return value of Intl.Segmenter.supportedLocalesOf(). +info: | + Intl.Segmenter.supportedLocalesOf ( locales [, options ]) +includes: [propertyHelper.js] +features: [Intl.Segmenter] +---*/ + +const result = Intl.Segmenter.supportedLocalesOf("en"); +assert.sameValue(Array.isArray(result), true, + "Array.isArray() should return true"); +assert.sameValue(Object.getPrototypeOf(result), Array.prototype, + "The prototype should be Array.prototype"); +assert.sameValue(Object.isExtensible(result), true, + "Object.isExtensible() should return true"); + +assert.notSameValue(result.length, 0); +for (let i = 0; i < result.length; ++i) { + verifyProperty(result, String(i), { + "writable": true, + "enumerable": true, + "configurable": true, + }); +} + +verifyProperty(result, "length", { + "enumerable": false, + "configurable": false, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/shell.js b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/constructor/supportedLocalesOf/shell.js |