diff options
Diffstat (limited to 'js/src/tests/test262/intl402/Segmenter/prototype/segment')
27 files changed, 1039 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/branding.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/branding.js new file mode 100644 index 0000000000..7bb5ab5ae5 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/branding.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.prototype.segment +description: Verifies the branding check for the "segment" function of the Segmenter prototype object. +info: | + Intl.Segmenter.prototype.segment( string ) + + 2. If Type(segment) is not Object or segment does not have an [[InitializedSegmenter]] internal slot, throw a TypeError exception. +features: [Intl.Segmenter] +---*/ + +const segment = Intl.Segmenter.prototype.segment; + +assert.sameValue(typeof segment, "function"); + +assert.throws(TypeError, () => segment.call(undefined), "undefined"); +assert.throws(TypeError, () => segment.call(null), "null"); +assert.throws(TypeError, () => segment.call(true), "true"); +assert.throws(TypeError, () => segment.call(""), "empty string"); +assert.throws(TypeError, () => segment.call(Symbol()), "symbol"); +assert.throws(TypeError, () => segment.call(1), "1"); +assert.throws(TypeError, () => segment.call({}), "plain object"); +assert.throws(TypeError, () => segment.call(Intl.Segmenter), "Intl.Segmenter"); +assert.throws(TypeError, () => segment.call(Intl.Segmenter.prototype), "Intl.Segmenter.prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/browser.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/browser.js diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/branding.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/branding.js new file mode 100644 index 0000000000..d3b323ead2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/branding.js @@ -0,0 +1,28 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Verifies the branding check for the "segment" function of the %Segments.prototype%.containing. +info: | + %Segments.prototype%.containing ( index ) + 1. Let segments be the this value. + 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]). + +features: [Intl.Segmenter] +---*/ +const segment = (new Intl.Segmenter()).segment("123"); +const containing = segment.containing; +assert.sameValue(typeof containing, "function"); +assert.throws(TypeError, () => containing.call(undefined), "undefined"); +assert.throws(TypeError, () => containing.call(null), "null"); +assert.throws(TypeError, () => containing.call(true), "true"); +assert.throws(TypeError, () => containing.call(""), "empty string"); +assert.throws(TypeError, () => containing.call(Symbol()), "symbol"); +assert.throws(TypeError, () => containing.call(1), "1"); +assert.throws(TypeError, () => containing.call({}), "plain object"); +assert.throws(TypeError, () => containing.call(Intl.Segmenter), "Intl.Segmenter"); +assert.throws(TypeError, () => containing.call(Intl.Segmenter.prototype), "Intl.Segmenter.prototype"); +assert.sameValue(undefined, containing.call(segment, -1)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/breakable-input.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/breakable-input.js new file mode 100644 index 0000000000..d1f50c5b9c --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/breakable-input.js @@ -0,0 +1,56 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Verifies the cases which the input is breakable. +info: | + %Segments.prototype%.containing ( index ) + + 8. Let startIndex be ! FindBoundary(segmenter, string, n, before). + 9. Let endIndex be ! FindBoundary(segmenter, string, n, after). + +features: [Intl.Segmenter] +---*/ + +// The inputs are breakable for "grapheme" and "word" but not for "sentence" +const granularities = [undefined, "grapheme", "word"]; +// The following all contains more than one segments in either "grapheme" or "word" +// granularity. +const inputs = [ + "123 ", + "a ", + " a", + " \ud800\udc00", // SPACE + surrogate + "\ud800\udc00 ", // surrogate + SPACE + "\udc00\ud800", // incorrect surrogate- tail + leading + "\ud800 ", // only leading surrogate + SPACE + "\udc00 ", // only trailing surrogate + SPACE + " \ud800", // SPACE + only leading surrogate + " \udc00", // SPACE + only trailing surrogate + " 台", // SPACE + a Han character + "台 ", // a Han character + SPACE + "\u0301 ", // a modifier + SPACE +]; + +granularities.forEach( + function(granularity) { + const segmenter = new Intl.Segmenter(undefined, {granularity}); + inputs.forEach(function(input) { + const segment = segmenter.segment(input); + let msg = `granularity: ${granularity} input: ${input}`; + const first = segment.containing(0); + assert.sameValue(0, first.index, `${msg} containing(0) index`); + assert.sameValue(input, first.input, `${msg} containing(0) input`); + assert.sameValue(false, first.segment == input, + `${msg} containing(0) segment`); + const last = segment.containing(input.length - 1); + msg += ` containing(${input.length - 1}) ` + assert.sameValue(true, last.index > 0, `${msg} index > 0`); + assert.sameValue(true, last.index < input.length, `${msg} index`); + assert.sameValue(input, last.input, `${msg} input`); + assert.sameValue(false, last.segment == input, `${msg} segment`); + }); + }); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/browser.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/browser.js diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/index-throws.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/index-throws.js new file mode 100644 index 0000000000..2948b6a242 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/index-throws.js @@ -0,0 +1,48 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Verifies the cases which the value of index which throws. +info: | + %Segments.prototype%.containing ( index ) + + 6. Let n be ? ToInteger(index). + 7. If n < 0 or n ≥ len, return undefined. + 8. Let startIndex be ! FindBoundary(segmenter, string, n, before). + + ToInteger ( argument ) + 1. Let number be ? ToNumber(argument). + + ToNumber ( argument ) + Symbol | Throw a TypeError exception. + BigInt | Throw a TypeError exception. + +features: [Intl.Segmenter] +---*/ + +const input = "a b c"; +const granularities = [undefined, "grapheme", "word", "sentence"]; +const index_throws = [ + // Symbol + Symbol(), + // BigInt + 0n, + -1n, + 1n, + BigInt(0), + BigInt(1), + BigInt(-1), + BigInt(input.length), +]; + +granularities.forEach( + function(granularity) { + const segmenter = new Intl.Segmenter(undefined, {granularity}); + const segment = segmenter.segment(input); + index_throws.forEach(function(index) { + assert.throws(TypeError, () => {segment.containing(index);}) + }); + }); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/iswordlike.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/iswordlike.js new file mode 100644 index 0000000000..599e95aa27 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/iswordlike.js @@ -0,0 +1,59 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Verifies the isWordLike in the result when granularity is not "word". +info: | + %Segments.prototype%.containing ( index ) + + 10. Return ! CreateSegmentDataObject(segmenter, string, startIndex, endIndex). + + CreateSegmentDataObject ( segmenter, string, startIndex, endIndex ) + 11. If granularity is "word", then + a. Let isWordLike be a Boolean value indicating whether the segment in string is "word-like" according to locale segmenter.[[Locale]]. + b. Perform ! CreateDataPropertyOrThrow(result, "isWordLike", isWordLike). + +includes: [compareArray.js] +features: [Intl.Segmenter] +---*/ + +const other_granularities = [undefined, "grapheme", "sentence"]; +// Some text +const inputs = [ + "Hello world!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean +]; + +other_granularities.forEach( + function(granularity) { + const segmenter = new Intl.Segmenter(undefined, {granularity}); + inputs.forEach(function(input) { + const segment = segmenter.segment(input); + for (let index = 0; index < input.length; index++) { + const result = segment.containing(index); + const msg = + `granularity: ${granularity} input: ${input} containing(${index})`; + assert.sameValue(true, result.index >= 0, `${msg} index >= 0`); + assert.sameValue(true, result.index < input.length, `${msg} index`); + assert.sameValue("string", typeof result.input, `${msg} input`); + assert.sameValue(undefined, result.isWordLike, + `${msg} isWordLike should be undefined`); + assert.compareArray(Object.getOwnPropertyNames(result), ["segment", "index", "input"]); + } + }); + }); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/length.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/length.js new file mode 100644 index 0000000000..e42cf8f308 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/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-%segmentsprototype%.containing +description: Checks the "length" property of %Segments.prototype%.containing() +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] +---*/ + +const segment = (new Intl.Segmenter()).segment(""); +verifyProperty(segment.containing, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/name.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/name.js new file mode 100644 index 0000000000..e5d4bb9403 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/name.js @@ -0,0 +1,24 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Checks the "name" property of %Segments.prototype%.containing ( index ) +info: | + %Segments.prototype%.containing ( index ) + 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 2020 Language Specification, 11th 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] +---*/ +const segment = (new Intl.Segmenter()).segment(""); +verifyProperty(segment.containing, "name", { + value: "containing", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/one-index.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/one-index.js new file mode 100644 index 0000000000..b23683ef99 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/one-index.js @@ -0,0 +1,70 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Verifies the cases which the value of index turn into 1. +info: | + %Segments.prototype%.containing ( index ) + + 6. Let n be ? ToInteger(index). + 7. If n < 0 or n ≥ len, return undefined. + 8. Let startIndex be ! FindBoundary(segmenter, string, n, before). + + ToInteger ( argument ) + 1. Let number be ? ToNumber(argument). + 2. If number is NaN, +0, or -0, return +0. + 4. Let integer be the Number value that is the same sign as number and whose magnitude is floor(abs(number)). + 5. If integer is -0, return +0. + 6. Return integer. + + ToNumber ( argument ) + Undefined | Return NaN. + Null | Return +0. + Boolean | If argument is true, return 1. If argument is false, return +0. + +features: [Intl.Segmenter] +---*/ + +const input = "a c"; +const granularities = [undefined, "grapheme", "word"]; +const index_to_one = [ + 1, + 1.49, + 14.9E-1, + 14.9e-1, + "1.49", + "14.9E-1", + "14.9e-1", + true, + { toString(){ return "1"; } }, + { valueOf(){ return 1; } }, + { [Symbol.toPrimitive](){ return 1; } }, +]; + +// Except granularity: "sentence", check the result.segment is " ". +granularities.forEach( + function(granularity) { + const segmenter = new Intl.Segmenter(undefined, {granularity}); + const segment = segmenter.segment(input); + index_to_one.forEach(function(index) { + const result = segment.containing(index); + const msg = "granularity: " + granularity + " index: " + index; + assert.sameValue(1, result.index, msg + " index"); + assert.sameValue(" ", result.segment, msg + " segment"); + assert.sameValue(input, result.input, msg + " input"); + }); + }); + +// For granularity: "sentence", result.segment is input +const segmenter = new Intl.Segmenter(undefined, {granularity: "sentence"}); +const segment = segmenter.segment(input); +index_to_one.forEach(function(index) { + const result = segment.containing(index); + const msg = "granularity: sentence index: " + index; + assert.sameValue(0, result.index, msg + " index"); + assert.sameValue(input, result.segment, msg + " segment"); + assert.sameValue(input, result.input, msg + " input"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/out-of-bound-index.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/out-of-bound-index.js new file mode 100644 index 0000000000..196de36d7f --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/out-of-bound-index.js @@ -0,0 +1,56 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Verifies the cases which the value of index turn into out of bound. +info: | + %Segments.prototype%.containing ( index ) + + 6. Let n be ? ToInteger(index). + 7. If n < 0 or n ≥ len, return undefined. + 8. Let startIndex be ! FindBoundary(segmenter, string, n, before). + + ToInteger ( argument ) + 1. Let number be ? ToNumber(argument). + 2. If number is NaN, +0, or -0, return +0. + 4. Let integer be the Number value that is the same sign as number and whose magnitude is floor(abs(number)). + 5. If integer is -0, return +0. + 6. Return integer. + + ToNumber ( argument ) + String | See grammar and conversion algorithm below. + +features: [Intl.Segmenter] +---*/ + +const input = "a b c"; +const granularities = [undefined, "grapheme", "word", "sentence"]; +const index_to_out_of_bound = [ + input.length, + input.length + 0.1, + -1, + -2, + "-1", + "-2", + "-1.1", + Infinity, + -Infinity, + "Infinity", + "-Infinity", + { toString(){ return "-1"; } }, + { valueOf(){ return input.length; } }, + { [Symbol.toPrimitive](){ return -1; } }, +]; + +granularities.forEach( + function(granularity) { + const segmenter = new Intl.Segmenter(undefined, {granularity}); + const segment = segmenter.segment(input); + index_to_out_of_bound.forEach(function(index) { + const result = segment.containing(index); + assert.sameValue(undefined, result); + }); + }); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/prop-desc.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/prop-desc.js new file mode 100644 index 0000000000..dd39c1862b --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/prop-desc.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-%segmentsprototype%.containing +description: Checks the "containing" property of the %Segments.prototype% object. +info: | + %Segments.prototype%.containing ( index ) + + 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. + +features: [Intl.Segmenter] +---*/ + +const segment = (new Intl.Segmenter()).segment(""); +assert.sameValue( + typeof segment.containing, + "function", + "typeof %Segments.prototype%.containing is function" +); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/shell.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/shell.js diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/unbreakable-input.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/unbreakable-input.js new file mode 100644 index 0000000000..bcc43b81f7 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/unbreakable-input.js @@ -0,0 +1,60 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Verifies the cases which the input is unbreakable. +info: | + %Segments.prototype%.containing ( index ) + + 8. Let startIndex be ! FindBoundary(segmenter, string, n, before). + 9. Let endIndex be ! FindBoundary(segmenter, string, n, after). + +features: [Intl.Segmenter] +---*/ + +const granularities = [undefined, "grapheme", "word", "sentence"]; +// The following all contains only one segment in any granularity. +const inputs = [ + "a", + " ", + "\ud800\udc00", // surrogate + "\ud800", // only leading surrogate + "\udc00", // only trailing surrogate + "台", // a Han character + "\u0301", // a modifier + "a\u0301", // ASCII + a modifier + "ซิ่", // a Thai cluster + "𐂰", // a Surrogate pair + "\uD83D\uDC4B\uD83C\uDFFB", // Emoji short sequence: waving_hand_light_skin_tone + "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB0", // Emoji long sequence: man_light_skin_tone_red_hair + "\u1102", // Jamo L + "\u1162", // Jamo V + "\u11A9", // Jamo T + "\u1102\u1162", // Jamo LV + "\u1102\u1162\u11A9", // Jamo LVT + "\u1102\u1102", // Jamo L L + "\u1102\u1102\u1162", // Jamo L L V + "\u1102\u1102\u1162\u11A9", // Jamo L L V T + "\u1162\u1162", // Jamo V V + "\u1162\u11A9", // Jamo V T + "\u1102\u1162\u1162", // Jamo V V + "\u11A9\u11A9", // Jamo T T + "\u1102\u1162\u11A9\u11A9", // Jamo LVT T +]; + +granularities.forEach( + function(granularity) { + const segmenter = new Intl.Segmenter(undefined, {granularity}); + inputs.forEach(function(input) { + const segment = segmenter.segment(input); + for (let index = 0; index < input.length; index++) { + const result = segment.containing(index); + assert.sameValue(0, result.index); + assert.sameValue(input, result.input); + assert.sameValue(input, result.segment); + } + }); + }); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/word-iswordlike.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/word-iswordlike.js new file mode 100644 index 0000000000..3124a65619 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/word-iswordlike.js @@ -0,0 +1,58 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Verifies the isWordLike in the result when granularity is "word". +info: | + %Segments.prototype%.containing ( index ) + + 10. Return ! CreateSegmentDataObject(segmenter, string, startIndex, endIndex). + + CreateSegmentDataObject ( segmenter, string, startIndex, endIndex ) + 11. If granularity is "word", then + a. Let isWordLike be a Boolean value indicating whether the segment in string is "word-like" according to locale segmenter.[[Locale]]. + b. Perform ! CreateDataPropertyOrThrow(result, "isWordLike", isWordLike). + +includes: [compareArray.js] +features: [Intl.Segmenter] +---*/ + +// Some text +const inputs = [ + "Hello world!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean +]; + +const granularity = "word"; +const segmenter = new Intl.Segmenter(undefined, {granularity}); +inputs.forEach(function(input) { + const segment = segmenter.segment(input); + for (let index = 0; index < input.length; index++) { + const result = segment.containing(index); + const msg = "granularity: " + granularity + " input: " + input + + " containing(" + index + ") "; + assert.sameValue(true, result.index >= 0, msg + "index >= 0"); + assert.sameValue(true, result.index < input.length, + msg + "index < " + input.length); + assert.sameValue("string", typeof result.input, msg + "input"); + assert.sameValue("boolean", typeof result.isWordLike, + msg + "isWordLike should be boolean"); + assert.compareArray(Object.getOwnPropertyNames(result), + ["segment", "index", "input", "isWordLike"]); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/zero-index.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/zero-index.js new file mode 100644 index 0000000000..0e768bd224 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/zero-index.js @@ -0,0 +1,72 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%segmentsprototype%.containing +description: Verifies the cases which the value of index turn into 0. +info: | + %Segments.prototype%.containing ( index ) + + 6. Let n be ? ToInteger(index). + 7. If n < 0 or n ≥ len, return undefined. + 8. Let startIndex be ! FindBoundary(segmenter, string, n, before). + + ToInteger ( argument ) + 1. Let number be ? ToNumber(argument). + 2. If number is NaN, +0, or -0, return +0. + 4. Let integer be the Number value that is the same sign as number and whose magnitude is floor(abs(number)). + 5. If integer is -0, return +0. + 6. Return integer. + + ToNumber ( argument ) + Undefined | Return NaN. + Null | Return +0. + Boolean | If argument is true, return 1. If argument is false, return +0. + +features: [Intl.Segmenter] +---*/ + +const input = "a b c"; +const granularities = [undefined, "grapheme", "word", "sentence"]; +const index_to_zeros = [ + 0, + -0, + NaN, + 0.49, + -0.49, + null, + undefined, + false, + "\ud800\udc00", // surrogate + "\ud800", // only leading surrogate + "\udc00", // only trailing surrogate + "a", + "g", + "\u00DD", + "0", + "+0", + "-0", + "0.49", + "+0.49", + "-0.49", + "4.9e-1", + "-4.9e-1", + "4.9E-1", + "-4.9E-1", + { toString(){ return "-0.1"; } }, + { valueOf(){ return 0.1; } }, + { [Symbol.toPrimitive](){ return -0.1; } }, +]; + +granularities.forEach( + function(granularity) { + const segmenter = new Intl.Segmenter(undefined, {granularity}); + const segment = segmenter.segment(input); + index_to_zeros.forEach(function(index) { + const result = segment.containing(index); + assert.sameValue(0, result.index); + assert.sameValue(input, result.input); + }); + }); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/length.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/length.js new file mode 100644 index 0000000000..21db9d950e --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/length.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.prototype.segment +description: Checks the "length" property of Intl.Segmenter.prototype.segment(). +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.prototype.segment, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/name.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/name.js new file mode 100644 index 0000000000..823f44f579 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/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.prototype.segment +description: Checks the "name" property of Intl.Segmenter.prototype.segment(). +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.prototype.segment, "name", { + value: "segment", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/nested-next.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/nested-next.js new file mode 100644 index 0000000000..6d21985021 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/nested-next.js @@ -0,0 +1,39 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 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-%segmentsprototype%-@@iterator +description: Test to ensure the nested calling of the next method won't caused confusion to each other. +info: | + %Segments.prototype% [ @@iterator ] () + 5. Return ! CreateSegmentIterator(segmenter, string) + + CreateSegmentIterator ( segmenter, string ) + 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ». + 2. Let iterator be ! ObjectCreate(%SegmentIterator.prototype%, internalSlotsList). + 3. Set iterator.[[IteratingSegmenter]] to segmenter. + 4. Set iterator.[[IteratedString]] to string. + 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0. + 6. Return iterator. + + %SegmentIterator.prototype%.next () + 5. Let startIndex be iterator.[[IteratedStringNextSegmentCodeUnitIndex]]. + +features: [Intl.Segmenter] +---*/ + +const segmenter = new Intl.Segmenter(); +const input = "ABCD"; +const segments = segmenter.segment(input); +let result = ""; +for (let v1 of segments) { + for (let v2 of segments) { + result += v1.segment; + result += v2.segment; + } + result += ":"; +} +assert.sameValue("AAABACAD:BABBBCBD:CACBCCCD:DADBDCDD:", result); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/next-inside-next.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/next-inside-next.js new file mode 100644 index 0000000000..2936d7621e --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/next-inside-next.js @@ -0,0 +1,50 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 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-%segmentsprototype%-@@iterator +description: Test to ensure the next on two segments of the segmenter won't interfer each other. +info: | + %Segments.prototype% [ @@iterator ] () + 5. Return ! CreateSegmentIterator(segmenter, string) + + CreateSegmentIterator ( segmenter, string ) + 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ». + 2. Let iterator be ! ObjectCreate(%SegmentIterator.prototype%, internalSlotsList). + 3. Set iterator.[[IteratingSegmenter]] to segmenter. + 4. Set iterator.[[IteratedString]] to string. + 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0. + 6. Return iterator. + + %SegmentIterator.prototype%.next () + 5. Let startIndex be iterator.[[IteratedStringNextSegmentCodeUnitIndex]]. + +features: [Intl.Segmenter] +---*/ + +const segmenter = new Intl.Segmenter(); +const input1 = "ABCD"; +const input2 = "123"; +const segments1 = segmenter.segment(input1); +const segments2 = segmenter.segment(input2); +let result = ""; +for (let v1 of segments1) { + for (let v2 of segments2) { + result += v1.segment; + result += v2.segment; + } + result += ":"; +} +// Now loop segments2 . +for (let v2 of segments2) { + for (let v1 of segments1) { + result += v2.segment; + result += v1.segment; + } + result += ":"; +} +assert.sameValue( + "A1A2A3:B1B2B3:C1C2C3:D1D2D3:1A1B1C1D:2A2B2C2D:3A3B3C3D:", result); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/next-mix-with-containing.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/next-mix-with-containing.js new file mode 100644 index 0000000000..dcc231c12b --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/next-mix-with-containing.js @@ -0,0 +1,55 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2020 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-%segmentsprototype%-@@iterator +description: Test to ensure the the calling of containing() won't impact the calling of the next(). +info: | + %Segments.prototype% [ @@iterator ] () + 5. Return ! CreateSegmentIterator(segmenter, string) + + CreateSegmentIterator ( segmenter, string ) + 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ». + 2. Let iterator be ! ObjectCreate(%SegmentIterator.prototype%, internalSlotsList). + 3. Set iterator.[[IteratingSegmenter]] to segmenter. + 4. Set iterator.[[IteratedString]] to string. + 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0. + 6. Return iterator. + + %SegmentIterator.prototype%.next () + 5. Let startIndex be iterator.[[IteratedStringNextSegmentCodeUnitIndex]]. + + %Segments.prototype%.containing ( index ) + 3. Let segmenter be segments.[[SegmentsSegmenter]]. + 4. Let string be segments.[[SegmentsString]]. + + +features: [Intl.Segmenter] +---*/ + +const segmenter = new Intl.Segmenter(); +const input = "ABC"; +const segments = segmenter.segment(input); +let next_result = ""; +for (let i = 0; i < input.length; i++) { + let containing_result = segments.containing(i); + let msg = "containing(" + i + ") before the loop. "; + assert.sameValue(input[i], containing_result.segment, msg + "segment"); + assert.sameValue(i, containing_result.index, msg + "index"); + assert.sameValue(input, containing_result.input, msg + "input"); + for (let v of segments) { + next_result += v.segment; + next_result += ":"; + // Ensure the value n passing into segments.containing(n) will not impact + // the result of next(). + msg = "containing(" + i + ") inside the loop. "; + containing_result = segments.containing(i); + assert.sameValue(input[i], containing_result.segment, msg + "segment"); + assert.sameValue(i, containing_result.index, msg + "index"); + assert.sameValue(input, containing_result.input, msg + "input"); + } +} +assert.sameValue("A:B:C:A:B:C:A:B:C:", next_result); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/prop-desc.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/prop-desc.js new file mode 100644 index 0000000000..d760eab7e5 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/prop-desc.js @@ -0,0 +1,31 @@ +// |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.prototype.segment +description: Checks the "segment" property of the Segmenter prototype object. +info: | + Intl.Segmenter.prototype.segment( string ) + + 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.prototype.segment, + "function", + "typeof Intl.Segmenter.prototype.segment is function" +); + +verifyProperty(Intl.Segmenter.prototype, "segment", { + writable: true, + enumerable: false, + configurable: true, +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-grapheme-iterable.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-grapheme-iterable.js new file mode 100644 index 0000000000..5b3766ff3a --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-grapheme-iterable.js @@ -0,0 +1,57 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 the V8 project authors. All rights reserved. +// Copyright 2020 Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.prototype.segment +description: Verifies the behavior for the "segment" function of the Segmenter prototype object. +info: | + Intl.Segmenter.prototype.segment( string ) +includes: [compareArray.js] +features: [Intl.Segmenter] +---*/ + +const seg = new Intl.Segmenter([], {granularity: "grapheme"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + let segments = []; + for (const v of seg.segment(text)) { + assert.sameValue("string", typeof v.segment); + assert.sameValue(true, v.segment.length > 0, "length > 0"); + + assert.sameValue("number", typeof v.index); + assert.sameValue(true, v.index >= 0, "index >= 0"); + assert.sameValue(true, v.index < text.length, "index < input.length"); + + assert.sameValue("string", typeof v.input); + assert.sameValue(text, v.input); + + assert.sameValue(undefined, v.isWordLike); + assert.sameValue(false, v.hasOwnProperty("isWordLike")); + + assert.sameValue(text.slice(v.index, v.index + v.segment.length), v.segment); + assert.compareArray(Object.getOwnPropertyNames(v), ["segment", "index", "input"]); + + segments.push(v.segment); + } + assert.sameValue(text, segments.join('')); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-sentence-iterable.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-sentence-iterable.js new file mode 100644 index 0000000000..706e49b4c5 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-sentence-iterable.js @@ -0,0 +1,57 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 the V8 project authors. All rights reserved. +// Copyright 2020 Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.prototype.segment +description: Verifies the behavior for the "segment" function of the Segmenter prototype object. +info: | + Intl.Segmenter.prototype.segment( string ) +includes: [compareArray.js] +features: [Intl.Segmenter] +---*/ + +const seg = new Intl.Segmenter([], {granularity: "sentence"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + let segments = []; + for (const v of seg.segment(text)) { + assert.sameValue("string", typeof v.segment); + assert.sameValue(true, v.segment.length > 0, "length > 0"); + + assert.sameValue("number", typeof v.index); + assert.sameValue(true, v.index >= 0, "index >= 0"); + assert.sameValue(true, v.index < text.length, "index < input.length"); + + assert.sameValue("string", typeof v.input); + assert.sameValue(text, v.input); + + assert.sameValue(undefined, v.isWordLike); + assert.sameValue(false, v.hasOwnProperty("isWordLike")); + + assert.sameValue(text.slice(v.index, v.index + v.segment.length), v.segment); + assert.compareArray(Object.getOwnPropertyNames(v), ["segment", "index", "input"]); + + segments.push(v.segment); + } + assert.sameValue(text, segments.join('')); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-tostring.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-tostring.js new file mode 100644 index 0000000000..433cd9ad44 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-tostring.js @@ -0,0 +1,37 @@ +// |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.prototype.segment +description: Verifies the string coercion in the "segment" function of the Segmenter prototype object. +info: | + Intl.Segmenter.prototype.segment( string ) + + 3. Let string be ? ToString(string). +features: [Intl.Segmenter] +---*/ + +const tests = [ + [[], "undefined"], + [[undefined], "undefined"], + [[null], "null"], + [[true], "true"], + [[false], "false"], + [[12], "12"], + [[1.23], "1.23"], + [[["a", "b"]], "a"], + [[{}], "["], // "[object Object]" +]; + +const segmenter = new Intl.Segmenter("en", { "granularity": "word" }); +for (const [args, expected] of tests) { + const segments = segmenter.segment(...args); + const actual = [...segments][0].segment; + assert.sameValue(actual, expected, `Expected segment "${expected}", found "${actual}" for arguments ${args}`); +} + +const symbol = Symbol(); +assert.throws(TypeError, () => segmenter.segment(symbol)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-word-iterable.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-word-iterable.js new file mode 100644 index 0000000000..af7b9598d5 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/segment-word-iterable.js @@ -0,0 +1,57 @@ +// |reftest| skip-if(!Intl.Segmenter) -- Intl.Segmenter is not enabled unconditionally +// Copyright 2018 the V8 project authors. All rights reserved. +// Copyright 2020 Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Segmenter.prototype.segment +description: Verifies the behavior for the "segment" function of the Segmenter prototype object. +info: | + Intl.Segmenter.prototype.segment( string ) +includes: [compareArray.js] +features: [Intl.Segmenter] +---*/ + +const seg = new Intl.Segmenter([], {granularity: "word"}) +for (const text of [ + "Hello world!", // English + " Hello world! ", // English with space before/after + " Hello world? Foo bar!", // English + "Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech + "Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese + "Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek + "Решение Индии о покупке российских С-400 расценили как вызов США", // Russian + "הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew, + "ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic + "भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi + "ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil + "'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్సైట్లో పెట్టవద్దు'", // Telugu + "台北》抹黑柯P失敗?朱學恒酸:姚文智氣pupu嗆大老闆", // Chinese + "วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai + "九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese + "법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean + ]) { + let segments = []; + for (const v of seg.segment(text)) { + assert.sameValue("string", typeof v.segment); + assert.sameValue(true, v.segment.length > 0, "length > 0"); + + assert.sameValue("number", typeof v.index); + assert.sameValue(true, v.index >= 0, "index >= 0"); + assert.sameValue(true, v.index < text.length, "index < input.length"); + + assert.sameValue("string", typeof v.input); + assert.sameValue(text, v.input); + + assert.sameValue("boolean", typeof v.isWordLike); + assert.sameValue(true, v.hasOwnProperty("isWordLike")); + + assert.sameValue(text.slice(v.index, v.index + v.segment.length), v.segment); + assert.compareArray(Object.getOwnPropertyNames(v), ["segment", "index", "input", "isWordLike"]); + + segments.push(v.segment); + } + assert.sameValue(text, segments.join('')); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Segmenter/prototype/segment/shell.js b/js/src/tests/test262/intl402/Segmenter/prototype/segment/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Segmenter/prototype/segment/shell.js |