From 1185b5287d4db5f9a8ecd6c4b2921d7cb3efaa03 Mon Sep 17 00:00:00 2001 From: Ms2ger <Ms2ger@igalia.com> Date: Wed, 24 Oct 2018 14:13:58 +0200 Subject: [PATCH] Intl.Segmenter: Submit remaining V8 tests. --- .../v8/intl/segmenter/constructor.js | 216 ------------- .../v8/intl/segmenter/resolved-options.js | 299 ------------------ .../intl/segmenter/segment-grapheme-next.js | 40 --- .../segmenter/segment-line-following-modes.js | 57 ---- .../v8/intl/segmenter/segment-line-next.js | 40 --- .../intl/segmenter/segment-sentence-next.js | 40 --- .../v8/intl/segmenter/segment-word-next.js | 40 --- .../v8/intl/segmenter/segment.js | 39 --- .../v8/intl/segmenter/subclassing.js | 17 - .../v8/intl/segmenter/supported-locale.js | 22 -- .../constructor/constructor/locales-valid.js | 26 +- .../options-granularity-invalid.js | 1 + .../options-lineBreakStyle-invalid.js | 1 + .../constructor/options-toobject-prototype.js | 1 + .../constructor/options-toobject.js | 1 + .../constructor/options-valid-combinations.js | 59 ++++ .../supportedLocalesOf/locales-empty.js | 19 ++ .../supportedLocalesOf/locales-specific.js | 22 ++ .../segment/segment-grapheme-next.js | 4 + .../prototype/segment/segment-line-next.js | 8 +- .../segment/segment-sentence-next.js | 4 + .../prototype/segment/segment-tostring.js | 36 +++ .../prototype/segment/segment-word-next.js | 4 + 23 files changed, 174 insertions(+), 822 deletions(-) delete mode 100644 implementation-contributed/v8/intl/segmenter/constructor.js delete mode 100644 implementation-contributed/v8/intl/segmenter/resolved-options.js delete mode 100644 implementation-contributed/v8/intl/segmenter/segment-grapheme-next.js delete mode 100644 implementation-contributed/v8/intl/segmenter/segment-line-following-modes.js delete mode 100644 implementation-contributed/v8/intl/segmenter/segment-line-next.js delete mode 100644 implementation-contributed/v8/intl/segmenter/segment-sentence-next.js delete mode 100644 implementation-contributed/v8/intl/segmenter/segment-word-next.js delete mode 100644 implementation-contributed/v8/intl/segmenter/segment.js delete mode 100644 implementation-contributed/v8/intl/segmenter/subclassing.js delete mode 100644 implementation-contributed/v8/intl/segmenter/supported-locale.js create mode 100644 test/intl402/Segmenter/constructor/constructor/options-valid-combinations.js create mode 100644 test/intl402/Segmenter/constructor/supportedLocalesOf/locales-empty.js create mode 100644 test/intl402/Segmenter/constructor/supportedLocalesOf/locales-specific.js create mode 100644 test/intl402/Segmenter/prototype/segment/segment-tostring.js diff --git a/implementation-contributed/v8/intl/segmenter/constructor.js b/implementation-contributed/v8/intl/segmenter/constructor.js deleted file mode 100644 index 655bb100df..0000000000 --- a/implementation-contributed/v8/intl/segmenter/constructor.js +++ /dev/null @@ -1,216 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-intl-segmenter - -// Segmenter constructor can't be called as function. -assertThrows(() => Intl.Segmenter(["sr"]), TypeError); - -// Invalid locale string. -assertThrows(() => new Intl.Segmenter(["abcdefghi"]), RangeError); - -assertDoesNotThrow(() => new Intl.Segmenter(["sr"], {}), TypeError); - -assertDoesNotThrow(() => new Intl.Segmenter([], {})); - -assertDoesNotThrow(() => new Intl.Segmenter(["fr", "ar"], {})); - -assertDoesNotThrow(() => new Intl.Segmenter({ 0: "ja", 1: "fr" }, {})); - -assertDoesNotThrow(() => new Intl.Segmenter({ 1: "ja", 2: "fr" }, {})); - -assertDoesNotThrow(() => new Intl.Segmenter(["sr"])); - -assertDoesNotThrow(() => new Intl.Segmenter()); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - lineBreakStyle: "strict", - granularity: "grapheme" - }) -); - -assertDoesNotThrow( - () => new Intl.Segmenter(["sr"], { granularity: "sentence" }) -); - -assertDoesNotThrow(() => new Intl.Segmenter(["sr"], { granularity: "word" })); - -assertDoesNotThrow( - () => new Intl.Segmenter(["sr"], { granularity: "grapheme" }) -); - -assertDoesNotThrow(() => new Intl.Segmenter(["sr"], { granularity: "line" })); - -assertThrows( - () => new Intl.Segmenter(["sr"], { granularity: "standard" }), - RangeError -); - -assertDoesNotThrow( - () => new Intl.Segmenter(["sr"], { lineBreakStyle: "normal" }) -); - -assertDoesNotThrow( - () => new Intl.Segmenter(["sr"], { lineBreakStyle: "strict" }) -); - -assertDoesNotThrow( - () => new Intl.Segmenter(["sr"], { lineBreakStyle: "loose" }) -); - -assertThrows( - () => new Intl.Segmenter(["sr"], { lineBreakStyle: "giant" }), - RangeError -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "sentence", - lineBreakStyle: "normal" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "sentence", - lineBreakStyle: "strict" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "sentence", - lineBreakStyle: "loose" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "word", - lineBreakStyle: "normal" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "word", - lineBreakStyle: "strict" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "word", - lineBreakStyle: "loose" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "grapheme", - lineBreakStyle: "normal" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "grapheme", - lineBreakStyle: "strict" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "grapheme", - lineBreakStyle: "loose" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "line", - lineBreakStyle: "loose" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "line", - lineBreakStyle: "normal" - }) -); - -assertDoesNotThrow( - () => - new Intl.Segmenter(["sr"], { - granularity: "line", - lineBreakStyle: "strict" - }) -); - -// propagate exception from getter -assertThrows( - () => - new Intl.Segmenter(undefined, { - get localeMatcher() { - throw new TypeError(""); - } - }), - TypeError -); -assertThrows( - () => - new Intl.Segmenter(undefined, { - get lineBreakStyle() { - throw new TypeError(""); - } - }), - TypeError -); -assertThrows( - () => - new Intl.Segmenter(undefined, { - get granularity() { - throw new TypeError(""); - } - }), - TypeError -); - -// Throws only once during construction. -// Check for all getters to prevent regression. -// Preserve the order of getter initialization. -let getCount = 0; -let localeMatcher = -1; -let lineBreakStyle = -1; -let granularity = -1; - -new Intl.Segmenter(["en-US"], { - get localeMatcher() { - localeMatcher = ++getCount; - }, - get lineBreakStyle() { - lineBreakStyle = ++getCount; - }, - get granularity() { - granularity = ++getCount; - } -}); - -assertEquals(1, localeMatcher); -assertEquals(2, lineBreakStyle); -assertEquals(3, granularity); diff --git a/implementation-contributed/v8/intl/segmenter/resolved-options.js b/implementation-contributed/v8/intl/segmenter/resolved-options.js deleted file mode 100644 index 2e2a910ddb..0000000000 --- a/implementation-contributed/v8/intl/segmenter/resolved-options.js +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-intl-segmenter - -let segmenter = new Intl.Segmenter([], { granularity: "line" }); -// The default lineBreakStyle is 'normal' -assertEquals("normal", segmenter.resolvedOptions().lineBreakStyle); - -segmenter = new Intl.Segmenter(); -assertEquals(undefined, segmenter.resolvedOptions().lineBreakStyle); - -// The default granularity is 'grapheme' -assertEquals("grapheme", segmenter.resolvedOptions().granularity); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { lineBreakStyle: "strict" }).resolvedOptions() - .lineBreakStyle -); - -assertEquals( - "grapheme", - new Intl.Segmenter(["sr"], { lineBreakStyle: "strict" }).resolvedOptions() - .granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { lineBreakStyle: "normal" }).resolvedOptions() - .lineBreakStyle -); - -assertEquals( - "grapheme", - new Intl.Segmenter(["sr"], { lineBreakStyle: "normal" }).resolvedOptions() - .granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { lineBreakStyle: "loose" }).resolvedOptions() - .lineBreakStyle -); - -assertEquals( - "grapheme", - new Intl.Segmenter(["sr"], { lineBreakStyle: "loose" }).resolvedOptions() - .granularity -); - -assertEquals( - "word", - new Intl.Segmenter(["sr"], { granularity: "word" }).resolvedOptions() - .granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { granularity: "word" }).resolvedOptions() - .lineBreakStyle -); - -assertEquals( - "grapheme", - new Intl.Segmenter(["sr"], { granularity: "grapheme" }).resolvedOptions() - .granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { granularity: "grapheme" }).resolvedOptions() - .lineBreakStyle -); - -assertEquals( - "sentence", - new Intl.Segmenter(["sr"], { granularity: "sentence" }).resolvedOptions() - .granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { granularity: "sentence" }).resolvedOptions() - .lineBreakStyle -); - -assertEquals( - "line", - new Intl.Segmenter(["sr"], { granularity: "line" }).resolvedOptions() - .granularity -); - -assertEquals( - "normal", - new Intl.Segmenter(["sr"], { granularity: "line" }).resolvedOptions() - .lineBreakStyle -); - -assertEquals( - "grapheme", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "loose", - granularity: "grapheme" - }).resolvedOptions().granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { - lineBreakStyle: "loose", - granularity: "grapheme" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "grapheme", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "strict", - granularity: "grapheme" - }).resolvedOptions().granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { - lineBreakStyle: "strict", - granularity: "grapheme" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "grapheme", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "normal", - granularity: "grapheme" - }).resolvedOptions().granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { - lineBreakStyle: "normal", - granularity: "grapheme" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "word", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "loose", - granularity: "word" - }).resolvedOptions().granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { - lineBreakStyle: "loose", - granularity: "word" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "word", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "strict", - granularity: "word" - }).resolvedOptions().granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { - lineBreakStyle: "strict", - granularity: "word" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "word", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "normal", - granularity: "word" - }).resolvedOptions().granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { - lineBreakStyle: "normal", - granularity: "word" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "sentence", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "loose", - granularity: "sentence" - }).resolvedOptions().granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { - lineBreakStyle: "loose", - granularity: "sentence" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "sentence", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "strict", - granularity: "sentence" - }).resolvedOptions().granularity -); - -assertEquals( - undefined, - new Intl.Segmenter(["sr"], { - lineBreakStyle: "strict", - granularity: "sentence" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "sentence", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "normal", - granularity: "sentence" - }).resolvedOptions().granularity -); - -assertEquals( - "normal", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "normal", - granularity: "line" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "line", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "loose", - granularity: "line" - }).resolvedOptions().granularity -); - -assertEquals( - "loose", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "loose", - granularity: "line" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "line", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "strict", - granularity: "line" - }).resolvedOptions().granularity -); - -assertEquals( - "strict", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "strict", - granularity: "line" - }).resolvedOptions().lineBreakStyle -); - -assertEquals( - "line", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "normal", - granularity: "line" - }).resolvedOptions().granularity -); - -assertEquals( - "normal", - new Intl.Segmenter(["sr"], { - lineBreakStyle: "normal", - granularity: "line" - }).resolvedOptions().lineBreakStyle -); - -assertEquals("ar", new Intl.Segmenter(["ar"]).resolvedOptions().locale); - -assertEquals("ar", new Intl.Segmenter(["ar", "en"]).resolvedOptions().locale); - -assertEquals("fr", new Intl.Segmenter(["fr", "en"]).resolvedOptions().locale); - -assertEquals("ar", new Intl.Segmenter(["xyz", "ar"]).resolvedOptions().locale); diff --git a/implementation-contributed/v8/intl/segmenter/segment-grapheme-next.js b/implementation-contributed/v8/intl/segmenter/segment-grapheme-next.js deleted file mode 100644 index 41e812e692..0000000000 --- a/implementation-contributed/v8/intl/segmenter/segment-grapheme-next.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-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 - ]) { - const iter = seg.segment(text); - let segments = []; - let oldPos = -1; - for (let result = iter.next(); !result.done; result = iter.next()) { - const v = result.value; - assertEquals(undefined, v.breakType); - assertEquals("string", typeof v.segment); - assertTrue(v.segment.length > 0); - segments.push(v.segment); - assertEquals("number", typeof v.position); - assertTrue(oldPos < v.position); - oldPos = v.position; - } - assertEquals(text, segments.join('')); -} diff --git a/implementation-contributed/v8/intl/segmenter/segment-line-following-modes.js b/implementation-contributed/v8/intl/segmenter/segment-line-following-modes.js deleted file mode 100644 index 8f0810dcdf..0000000000 --- a/implementation-contributed/v8/intl/segmenter/segment-line-following-modes.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-intl-segmenter - -let breakCounts = {}; -for (const locale of ["en", "fr", "ja", "zh", "ko"]) { - for (const lineBreakStyle of ["strict", "normal", "loose"]) { - const seg = new Intl.Segmenter( - [locale], {granularity: "line", lineBreakStyle: lineBreakStyle}); - let opportunity = 0; - for (const text of [ - // We know the following data caused different line break results between - // different modes. - // https://www.w3.org/TR/css-text-3/#propdef-line-break - // Japanese small kana or the Katakana-Hiragana prolonged sound mark - "ã‚ãーãƒãƒ¼ã‚ーã„ーãーãƒãƒ¼", - // hyphens: - // †U+2010, – U+2013, 〜 U+301C, ã‚ U+30A0 - "ABCâ€DEF–GHI〜JKLã‚ MNO", - // iteration marks: - // 々 U+3005, 〻 U+303B, ã‚ U+309D, ã‚ž U+309E, ヽ U+30FD, ヾ U+30FE - "ã‚々ã‚〻ã‚ã‚ã‚ã‚žã‚ヽã‚ヾã‚", - // centered punctuation marks: - // ・ U+30FB, : U+FF1A, ï¼› U+FF1B, ï½¥ U+FF65, ‼ U+203C - "ABC・DEF:GHIï¼›JKLï½¥MNO‼PQR", - // centered punctuation marks: - // ⇠U+2047, ∠U+2048, ≠U+2049, ï¼ U+FF01, ? U+FF1F - "ABCâ‡DEFâˆGHIâ‰JKLï¼MNO?PQR", - ]) { - const iter = seg.segment(text); - while (!iter.following()) { - opportunity++; - } - } - breakCounts[locale + "-" + lineBreakStyle] = opportunity; - } -} -// In Japanese -// Just test the break count in loose mode is greater than normal mode. -assertTrue(breakCounts["ja-loose"] > breakCounts["ja-normal"]); -// and test the break count in normal mode is greater than strict mode. -assertTrue(breakCounts["ja-normal"] > breakCounts["ja-strict"]); -// In Chinese -// Just test the break count in loose mode is greater than normal mode. -assertTrue(breakCounts["zh-loose"] > breakCounts["zh-normal"]); -// and test the break count in normal mode is greater than strict mode. -assertTrue(breakCounts["zh-normal"] > breakCounts["zh-strict"]); -// In English, French and Korean -assertTrue(breakCounts["en-loose"] >= breakCounts["en-normal"]); -assertTrue(breakCounts["fr-loose"] >= breakCounts["fr-normal"]); -assertTrue(breakCounts["ko-loose"] >= breakCounts["ko-normal"]); -// and test the break count in normal mode is greater than strict mode. -assertTrue(breakCounts["en-normal"] > breakCounts["en-strict"]); -assertTrue(breakCounts["fr-normal"] > breakCounts["fr-strict"]); -assertTrue(breakCounts["ko-normal"] > breakCounts["ko-strict"]); diff --git a/implementation-contributed/v8/intl/segmenter/segment-line-next.js b/implementation-contributed/v8/intl/segmenter/segment-line-next.js deleted file mode 100644 index a4c76acfd1..0000000000 --- a/implementation-contributed/v8/intl/segmenter/segment-line-next.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-intl-segmenter - -const seg = new Intl.Segmenter([], {granularity: "line"}) -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 - ]) { - const iter = seg.segment(text); - let segments = []; - let oldPos = -1; - for (let result = iter.next(); !result.done; result = iter.next()) { - const v = result.value; - assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType); - assertEquals("string", typeof v.segment); - assertTrue(v.segment.length > 0); - segments.push(v.segment); - assertEquals("number", typeof v.position); - assertTrue(oldPos < v.position); - oldPos = v.position; - } - assertEquals(text, segments.join('')); -} diff --git a/implementation-contributed/v8/intl/segmenter/segment-sentence-next.js b/implementation-contributed/v8/intl/segmenter/segment-sentence-next.js deleted file mode 100644 index 8a76781e58..0000000000 --- a/implementation-contributed/v8/intl/segmenter/segment-sentence-next.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-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 - ]) { - const iter = seg.segment(text); - let segments = []; - let oldPos = -1; - for (let result = iter.next(); !result.done; result = iter.next()) { - const v = result.value; - assertTrue(["sep", "term"].includes(iter.breakType), iter.breakType); - assertEquals("string", typeof v.segment); - assertTrue(v.segment.length > 0); - segments.push(v.segment); - assertEquals("number", typeof v.position); - assertTrue(oldPos < v.position); - oldPos = v.position; - } - assertEquals(text, segments.join('')); -} diff --git a/implementation-contributed/v8/intl/segmenter/segment-word-next.js b/implementation-contributed/v8/intl/segmenter/segment-word-next.js deleted file mode 100644 index 53b73793df..0000000000 --- a/implementation-contributed/v8/intl/segmenter/segment-word-next.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-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 - ]) { - const iter = seg.segment(text); - let segments = []; - let oldPos = -1; - for (let result = iter.next(); !result.done; result = iter.next()) { - const v = result.value; - assertTrue(["word", "none"].includes(iter.breakType), iter.breakType); - assertEquals("string", typeof v.segment); - assertTrue(v.segment.length > 0); - segments.push(v.segment); - assertEquals("number", typeof v.position); - assertTrue(oldPos < v.position); - oldPos = v.position; - } - assertEquals(text, segments.join('')); -} diff --git a/implementation-contributed/v8/intl/segmenter/segment.js b/implementation-contributed/v8/intl/segmenter/segment.js deleted file mode 100644 index 4c76b96e54..0000000000 --- a/implementation-contributed/v8/intl/segmenter/segment.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-intl-segmenter - -assertEquals("function", typeof Intl.Segmenter.prototype.segment); -assertEquals(1, Intl.Segmenter.prototype.segment.length); - -let seg = new Intl.Segmenter("en", {granularity: "word"}) -let res; - -// test with 0 args -assertDoesNotThrow(() => res = seg.segment()) -// test with 1 arg -assertDoesNotThrow(() => res = seg.segment("hello")) -assertEquals("hello", res.next().value.segment); -// test with 2 args -assertDoesNotThrow(() => res = seg.segment("hello world")) -assertEquals("hello", res.next().value.segment); - -// test with other types -assertDoesNotThrow(() => res = seg.segment(undefined)) -assertEquals("undefined", res.next().value.segment); -assertDoesNotThrow(() => res = seg.segment(null)) -assertEquals("null", res.next().value.segment); -assertDoesNotThrow(() => res = seg.segment(true)) -assertEquals("true", res.next().value.segment); -assertDoesNotThrow(() => res = seg.segment(false)) -assertEquals("false", res.next().value.segment); -assertDoesNotThrow(() => res = seg.segment(1234)) -assertEquals("1234", res.next().value.segment); -assertDoesNotThrow(() => res = seg.segment(3.1415926)) -assertEquals("3.1415926", res.next().value.segment); -assertDoesNotThrow(() => res = seg.segment(["hello","world"])) -assertEquals("hello", res.next().value.segment); -assertDoesNotThrow(() => res = seg.segment({k: 'v'})) -assertEquals("[", res.next().value.segment); -assertThrows(() => res = seg.segment(Symbol()), TypeError) diff --git a/implementation-contributed/v8/intl/segmenter/subclassing.js b/implementation-contributed/v8/intl/segmenter/subclassing.js deleted file mode 100644 index 2bea1e88ce..0000000000 --- a/implementation-contributed/v8/intl/segmenter/subclassing.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-intl-segmenter - -// Test subclassing of Segmenter -class CustomSegmenter extends Intl.Segmenter { - constructor(locales, options) { - super(locales, options); - this.isCustom = true; - } -} - -const seg = new CustomSegmenter("zh"); -assertEquals(true, seg.isCustom, "Custom property"); -assertEquals(Object.getPrototypeOf(seg), CustomSegmenter.prototype, "Prototype"); diff --git a/implementation-contributed/v8/intl/segmenter/supported-locale.js b/implementation-contributed/v8/intl/segmenter/supported-locale.js deleted file mode 100644 index 9197b6a815..0000000000 --- a/implementation-contributed/v8/intl/segmenter/supported-locale.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2018 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Flags: --harmony-intl-segmenter -assertEquals( - typeof Intl.Segmenter.supportedLocalesOf, - "function", - "Intl.Segmenter.supportedLocalesOf should be a function" -); - -const undef = Intl.Segmenter.supportedLocalesOf(); -assertEquals([], undef); - -const empty = Intl.Segmenter.supportedLocalesOf([]); -assertEquals([], empty); - -const strLocale = Intl.Segmenter.supportedLocalesOf("sr"); -assertEquals("sr", strLocale[0]); - -const multiLocale = ["sr-Thai-RS", "de", "zh-CN"]; -assertEquals(multiLocale, Intl.Segmenter.supportedLocalesOf(multiLocale)); diff --git a/test/intl402/Segmenter/constructor/constructor/locales-valid.js b/test/intl402/Segmenter/constructor/constructor/locales-valid.js index 08318192cb..06be557e99 100644 --- a/test/intl402/Segmenter/constructor/constructor/locales-valid.js +++ b/test/intl402/Segmenter/constructor/constructor/locales-valid.js @@ -15,20 +15,26 @@ features: [Intl.Segmenter] const defaultLocale = new Intl.Segmenter().resolvedOptions().locale; const tests = [ - [undefined, defaultLocale, "undefined"], - ["EN", "en", "Single value"], - [[], defaultLocale, "Empty array"], - [["en-GB-oed"], "en-GB", "Grandfathered"], - [["x-private"], defaultLocale, "Private", ["lookup"]], - [["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"], + [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-GB-oed"], ["en-GB"], "Grandfathered"], + [["x-private"], [defaultLocale], "Private", ["lookup"]], + [["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"], ]; for (const [locales, expected, name, matchers = ["best fit", "lookup"]] of tests) { for (const localeMatcher of matchers) { const segmenter = new Intl.Segmenter(locales, { localeMatcher }); - assert.sameValue(segmenter.resolvedOptions().locale, expected, name); + const actual = segmenter.resolvedOptions().locale; + assert(expected.includes(actual), `${name}: expected one of ${expected}, found ${actual}`); } } diff --git a/test/intl402/Segmenter/constructor/constructor/options-granularity-invalid.js b/test/intl402/Segmenter/constructor/constructor/options-granularity-invalid.js index 36bd0c80c9..3476dd4398 100644 --- a/test/intl402/Segmenter/constructor/constructor/options-granularity-invalid.js +++ b/test/intl402/Segmenter/constructor/constructor/options-granularity-invalid.js @@ -16,6 +16,7 @@ const invalidOptions = [ null, 1, "", + "standard", "Grapheme", "GRAPHEME", "grapheme\0", diff --git a/test/intl402/Segmenter/constructor/constructor/options-lineBreakStyle-invalid.js b/test/intl402/Segmenter/constructor/constructor/options-lineBreakStyle-invalid.js index 03cbbfbaba..b1b892960a 100644 --- a/test/intl402/Segmenter/constructor/constructor/options-lineBreakStyle-invalid.js +++ b/test/intl402/Segmenter/constructor/constructor/options-lineBreakStyle-invalid.js @@ -17,6 +17,7 @@ const invalidOptions = [ null, 1, "", + "giant", "Strict", "STRICT", "strict\0", diff --git a/test/intl402/Segmenter/constructor/constructor/options-toobject-prototype.js b/test/intl402/Segmenter/constructor/constructor/options-toobject-prototype.js index 9b1ad79bb5..d4163990ca 100644 --- a/test/intl402/Segmenter/constructor/constructor/options-toobject-prototype.js +++ b/test/intl402/Segmenter/constructor/constructor/options-toobject-prototype.js @@ -26,6 +26,7 @@ const optionsArguments = [ "test", 7, Symbol(), + {}, ]; for (const options of optionsArguments) { diff --git a/test/intl402/Segmenter/constructor/constructor/options-toobject.js b/test/intl402/Segmenter/constructor/constructor/options-toobject.js index d0581d40ae..ab3b6230c8 100644 --- a/test/intl402/Segmenter/constructor/constructor/options-toobject.js +++ b/test/intl402/Segmenter/constructor/constructor/options-toobject.js @@ -17,6 +17,7 @@ const optionsArguments = [ "test", 7, Symbol(), + {}, ]; for (const options of optionsArguments) { diff --git a/test/intl402/Segmenter/constructor/constructor/options-valid-combinations.js b/test/intl402/Segmenter/constructor/constructor/options-valid-combinations.js new file mode 100644 index 0000000000..027f9e3887 --- /dev/null +++ b/test/intl402/Segmenter/constructor/constructor/options-valid-combinations.js @@ -0,0 +1,59 @@ +// 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 ]]) + + 9. Let lineBreakStyle be ? GetOption(options, "lineBreakStyle", "string", « "strict", "normal", "loose" », "normal"). + 13. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence", "line" », "grapheme"). + 14. Set segmenter.[[SegmenterGranularity]] to granularity. + 15. If granularity is "line", + a. Set segmenter.[[SegmenterLineBreakStyle]] to r.[[lb]]. +features: [Intl.Segmenter] +---*/ + +const lineBreakStyleOptions = ["strict", "normal", "loose"]; +const granularityOptions = ["grapheme", "word", "sentence", "line"]; +const combinations = []; + +combinations.push([ + {}, + "grapheme", + undefined, +]); + +for (const lineBreakStyle of lineBreakStyleOptions) { + combinations.push([ + { lineBreakStyle }, + "grapheme", + undefined, + ]); +} + +for (const granularity of granularityOptions) { + combinations.push([ + { granularity }, + granularity, + granularity === "line" ? "normal" : undefined, + ]); +} + +for (const lineBreakStyle of lineBreakStyleOptions) { + for (const granularity of granularityOptions) { + combinations.push([ + { granularity, lineBreakStyle }, + granularity, + granularity === "line" ? lineBreakStyle : undefined, + ]); + } +} + +for (const [input, granularity, lineBreakStyle] of combinations) { + const segmenter = new Intl.Segmenter([], input); + const resolvedOptions = segmenter.resolvedOptions(); + assert.sameValue(resolvedOptions.granularity, granularity); + assert.sameValue(resolvedOptions.lineBreakStyle, lineBreakStyle); +} diff --git a/test/intl402/Segmenter/constructor/supportedLocalesOf/locales-empty.js b/test/intl402/Segmenter/constructor/supportedLocalesOf/locales-empty.js new file mode 100644 index 0000000000..b785c7603d --- /dev/null +++ b/test/intl402/Segmenter/constructor/supportedLocalesOf/locales-empty.js @@ -0,0 +1,19 @@ +// 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([]), []); diff --git a/test/intl402/Segmenter/constructor/supportedLocalesOf/locales-specific.js b/test/intl402/Segmenter/constructor/supportedLocalesOf/locales-specific.js new file mode 100644 index 0000000000..333818f00d --- /dev/null +++ b/test/intl402/Segmenter/constructor/supportedLocalesOf/locales-specific.js @@ -0,0 +1,22 @@ +// 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), multiLocale); diff --git a/test/intl402/Segmenter/prototype/segment/segment-grapheme-next.js b/test/intl402/Segmenter/prototype/segment/segment-grapheme-next.js index 6a31f6866e..9d30c6ac15 100644 --- a/test/intl402/Segmenter/prototype/segment/segment-grapheme-next.js +++ b/test/intl402/Segmenter/prototype/segment/segment-grapheme-next.js @@ -30,12 +30,16 @@ for (const text of [ ]) { const iter = seg.segment(text); let segments = []; + let oldPos = -1; for (let result = iter.next(); !result.done; result = iter.next()) { const v = result.value; assert.sameValue(undefined, v.breakType); assert.sameValue("string", typeof v.segment); assert(v.segment.length > 0); segments.push(v.segment); + assert.sameValue(typeof v.position, "number"); + assert(oldPos < v.position); + oldPos = v.position; } assert.sameValue(text, segments.join('')); } diff --git a/test/intl402/Segmenter/prototype/segment/segment-line-next.js b/test/intl402/Segmenter/prototype/segment/segment-line-next.js index 01cd79a61d..3e95f8b825 100644 --- a/test/intl402/Segmenter/prototype/segment/segment-line-next.js +++ b/test/intl402/Segmenter/prototype/segment/segment-line-next.js @@ -30,12 +30,16 @@ for (const text of [ ]) { const iter = seg.segment(text); let segments = []; + let oldPos = -1; for (let result = iter.next(); !result.done; result = iter.next()) { const v = result.value; assert(["soft", "hard"].includes(iter.breakType), iter.breakType); assert.sameValue("string", typeof v.segment); assert(v.segment.length > 0); segments.push(v.segment); - } - assert.sameValue(text, segments.join('')); + assert.sameValue(typeof v.position, "number"); + assert(oldPos < v.position); + oldPos = v.position; + } + assert.sameValue(text, segments.join('')); } diff --git a/test/intl402/Segmenter/prototype/segment/segment-sentence-next.js b/test/intl402/Segmenter/prototype/segment/segment-sentence-next.js index 41492252f8..9115d28ae3 100644 --- a/test/intl402/Segmenter/prototype/segment/segment-sentence-next.js +++ b/test/intl402/Segmenter/prototype/segment/segment-sentence-next.js @@ -30,12 +30,16 @@ for (const text of [ ]) { const iter = seg.segment(text); let segments = []; + let oldPos = -1; for (let result = iter.next(); !result.done; result = iter.next()) { const v = result.value; assert(["sep", "term"].includes(iter.breakType), iter.breakType); assert.sameValue("string", typeof v.segment); assert(v.segment.length > 0); segments.push(v.segment); + assert.sameValue(typeof v.position, "number"); + assert(oldPos < v.position); + oldPos = v.position; } assert.sameValue(text, segments.join('')); } diff --git a/test/intl402/Segmenter/prototype/segment/segment-tostring.js b/test/intl402/Segmenter/prototype/segment/segment-tostring.js new file mode 100644 index 0000000000..5569d22f61 --- /dev/null +++ b/test/intl402/Segmenter/prototype/segment/segment-tostring.js @@ -0,0 +1,36 @@ +// 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 iterator = segmenter.segment(...args); + const result = iterator.next().value; + assert.sameValue(result.segment, expected, `Expected segment "${expected}", found "${result.segment}" for arguments ${args}`); + assert(["word", "none"].includes(result.breakType), `Expected valid breakType, found "${result.breakType}" for arguments ${args}`); + assert.sameValue(result.position, expected.length, `Expected position ${expected.length}, found ${result.position} for arguments ${args}`); +} + +const symbol = Symbol(); +assert.throws(TypeError, () => segmenter.segment(symbol)); diff --git a/test/intl402/Segmenter/prototype/segment/segment-word-next.js b/test/intl402/Segmenter/prototype/segment/segment-word-next.js index 27bed47278..975bbace59 100644 --- a/test/intl402/Segmenter/prototype/segment/segment-word-next.js +++ b/test/intl402/Segmenter/prototype/segment/segment-word-next.js @@ -30,12 +30,16 @@ for (const text of [ ]) { const iter = seg.segment(text); let segments = []; + let oldPos = -1; for (let result = iter.next(); !result.done; result = iter.next()) { const v = result.value; assert(["word", "none"].includes(iter.breakType), iter.breakType); assert.sameValue("string", typeof v.segment); assert(v.segment.length > 0); segments.push(v.segment); + assert.sameValue(typeof v.position, "number"); + assert(oldPos < v.position); + oldPos = v.position; } assert.sameValue(text, segments.join('')); } -- GitLab