diff options
Diffstat (limited to 'js/src/tests/test262/intl402/ListFormat/prototype/formatToParts/es-es-narrow.js')
-rw-r--r-- | js/src/tests/test262/intl402/ListFormat/prototype/formatToParts/es-es-narrow.js | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/ListFormat/prototype/formatToParts/es-es-narrow.js b/js/src/tests/test262/intl402/ListFormat/prototype/formatToParts/es-es-narrow.js new file mode 100644 index 0000000000..ffd14fe622 --- /dev/null +++ b/js/src/tests/test262/intl402/ListFormat/prototype/formatToParts/es-es-narrow.js @@ -0,0 +1,92 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.ListFormat.prototype.formatToParts +description: > + Checks the behavior of Intl.ListFormat.prototype.formatToParts() in English. +features: [Intl.ListFormat] +locale: [en-US] +---*/ + +function verifyFormatParts(actual, expected, message) { + assert.sameValue(actual.length, expected.length, `${message}: length`); + + for (let i = 0; i < actual.length; ++i) { + assert.sameValue(actual[i].type, expected[i].type, `${message}: parts[${i}].type`); + assert.sameValue(actual[i].value, expected[i].value, `${message}: parts[${i}].value`); + } +} + +function CustomIterator(array) { + this.i = 0; + this.array = array; +} + +CustomIterator.prototype[Symbol.iterator] = function() { + return this; +} + +CustomIterator.prototype.next = function() { + if (this.i >= this.array.length) { + return { + "done": true, + }; + } + + return { + "value": this.array[this.i++], + "done": false, + }; +} + +const transforms = [ + a => a, + a => a[Symbol.iterator](), + a => new CustomIterator(a), +]; + +const lf = new Intl.ListFormat("es-ES", { + "style": "narrow", + "type": "unit", +}); + +assert.sameValue(typeof lf.formatToParts, "function", "format should be supported"); + +for (const f of transforms) { + verifyFormatParts(lf.formatToParts(f([])), []); + verifyFormatParts(lf.formatToParts(f(["foo"])), [ + { "type": "element", "value": "foo" }, + ]); + verifyFormatParts(lf.formatToParts(f(["foo", "bar"])), [ + { "type": "element", "value": "foo" }, + { "type": "literal", "value": " " }, + { "type": "element", "value": "bar" }, + ]); + verifyFormatParts(lf.formatToParts(f(["foo", "bar", "baz"])), [ + { "type": "element", "value": "foo" }, + { "type": "literal", "value": " " }, + { "type": "element", "value": "bar" }, + { "type": "literal", "value": " " }, + { "type": "element", "value": "baz" }, + ]); + verifyFormatParts(lf.formatToParts(f(["foo", "bar", "baz", "quux"])), [ + { "type": "element", "value": "foo" }, + { "type": "literal", "value": " " }, + { "type": "element", "value": "bar" }, + { "type": "literal", "value": " " }, + { "type": "element", "value": "baz" }, + { "type": "literal", "value": " " }, + { "type": "element", "value": "quux" }, + ]); +} + +verifyFormatParts(lf.formatToParts("foo"), [ + { "type": "element", "value": "f" }, + { "type": "literal", "value": " " }, + { "type": "element", "value": "o" }, + { "type": "literal", "value": " " }, + { "type": "element", "value": "o" }, +]); + +reportCompare(0, 0); |