diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/breakable-input.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/breakable-input.js')
-rw-r--r-- | js/src/tests/test262/intl402/Segmenter/prototype/segment/containing/breakable-input.js | 56 |
1 files changed, 56 insertions, 0 deletions
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); |