v8/test/intl/segmenter/segment-line-following-modes.js
Frank Tang db6db6ed8f [Intl] Add more tests for Intl.Segmenter
Bug: v8:6891
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I0b82b194cb7089aeaa322ed4e45008db6890e7a1
Reviewed-on: https://chromium-review.googlesource.com/c/1266995
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56704}
2018-10-16 15:17:09 +00:00

58 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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
"ABCDEFGHI〜JKLMNO",
// 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・DEFGHIJKL・MNO‼PQR",
// centered punctuation marks:
// ⁇ U+2047, ⁈ U+2048, ⁉ U+2049, U+FF01, U+FF1F
"ABC⁇DEF⁈GHI⁉JKLMNOPQR",
]) {
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
assertEquals(breakCounts["en-loose"], breakCounts["en-normal"]);
assertEquals(breakCounts["fr-loose"], breakCounts["fr-normal"]);
assertEquals(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"]);