mirror of https://github.com/tc39/test262.git
Add more tests for Intl.Segmenter
This commit is contained in:
parent
9c754bc3ce
commit
085cb50b25
|
@ -0,0 +1,26 @@
|
|||
// 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
|
||||
description:
|
||||
Return abrupt completion from GetOption localeMatcher
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
|
||||
13. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme").
|
||||
|
||||
GetOption ( options, property, type, values, fallback )
|
||||
1. Let value be ? Get(options, property).
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
|
||||
var options = {};
|
||||
Object.defineProperty(options, 'localeMatcher', {
|
||||
get() { throw new Test262Error(); },
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new Intl.DisplayNames(undefined, options);
|
||||
});
|
|
@ -7,7 +7,7 @@ description: Checks handling of invalid value for the style option to the Segmen
|
|||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
|
||||
13. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence", "line" », "grapheme").
|
||||
13. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme").
|
||||
14. Set segmenter.[[SegmenterGranularity]] to granularity.
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
@ -26,6 +26,7 @@ const invalidOptions = [
|
|||
"Sentence",
|
||||
"SENTENCE",
|
||||
"sentence\0",
|
||||
"line",
|
||||
"Line",
|
||||
"LINE",
|
||||
"line\0",
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
// 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
|
||||
description:
|
||||
Return abrupt completion from GetOption localeMatcher
|
||||
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
|
||||
13. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme").
|
||||
|
||||
GetOption ( options, property, type, values, fallback )
|
||||
1. Let value be ? Get(options, property).
|
||||
features: [Intl.Segmenter, Symbol]
|
||||
---*/
|
||||
|
||||
var options = {
|
||||
localeMatcher: {
|
||||
toString() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new Intl.Segmenter(undefined, options);
|
||||
}, 'from toString');
|
||||
|
||||
options.localeMatcher = {
|
||||
toString: undefined,
|
||||
valueOf() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new Intl.Segmenter(undefined, options);
|
||||
}, 'from valueOf');
|
||||
|
||||
options.localeMatcher = {
|
||||
[Symbol.toPrimitive]() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new Intl.Segmenter(undefined, options);
|
||||
}, 'from ToPrimitive');
|
||||
|
||||
options.localeMatcher = Symbol();
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
new Intl.Segmenter(undefined, options);
|
||||
}, 'symbol value');
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-intl.segmenter
|
||||
description: >
|
||||
Return abrupt completion from GetOption localeMatcher
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
...
|
||||
4. If options is undefined, then
|
||||
a. Let options be ObjectCreate(null).
|
||||
5. Else
|
||||
a. Let options be ? ToObject(options).
|
||||
...
|
||||
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||
GetOption ( options, property, type, values, fallback )
|
||||
1. Let value be ? Get(options, property).
|
||||
...
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
var options = {};
|
||||
Object.defineProperty(options, 'localeMatcher', {
|
||||
get() { throw new Test262Error(); },
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new Intl.Segmenter(undefined, options);
|
||||
});
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-intl.segmenter
|
||||
description: >
|
||||
Return abrupt completion from GetOption localeMatcher
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
|
||||
...
|
||||
4. If options is undefined, then
|
||||
a. Let options be ObjectCreate(null).
|
||||
5. Else
|
||||
a. Let options be ? ToObject(options).
|
||||
...
|
||||
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||
|
||||
GetOption ( options, property, type, values, fallback )
|
||||
|
||||
1. Let value be ? Get(options, property).
|
||||
...
|
||||
features: [Intl.Segmenter, Symbol]
|
||||
---*/
|
||||
|
||||
var options = {
|
||||
localeMatcher: {
|
||||
toString() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new Intl.Segmenter(undefined, options);
|
||||
}, 'from toString');
|
||||
|
||||
options.localeMatcher = {
|
||||
toString: undefined,
|
||||
valueOf() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new Intl.Segmenter(undefined, options);
|
||||
}, 'from valueOf');
|
||||
|
||||
options.localeMatcher = {
|
||||
[Symbol.toPrimitive]() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
new Intl.Segmenter(undefined, options);
|
||||
}, 'from ToPrimitive');
|
||||
|
||||
options.localeMatcher = Symbol();
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
new Intl.Segmenter(undefined, options);
|
||||
}, 'symbol value');
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-intl.segmenter
|
||||
description: >
|
||||
Valid options for localeMatcher
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
|
||||
...
|
||||
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||
...
|
||||
|
||||
GetOption ( options, property, type, values, fallback )
|
||||
|
||||
1. Let value be ? Get(options, property).
|
||||
...
|
||||
features: [Intl.Segmenter]
|
||||
locale: [en]
|
||||
---*/
|
||||
|
||||
// results for option values verified in the tests for resolvedOptions
|
||||
|
||||
const localeMatchers = [
|
||||
undefined,
|
||||
'lookup',
|
||||
'best fit'
|
||||
];
|
||||
|
||||
localeMatchers.forEach(localeMatcher => {
|
||||
const obj = new Intl.Segmenter();
|
||||
|
||||
assert(obj instanceof Intl.Segmenter, `instanceof check - ${localeMatcher}`);
|
||||
assert.sameValue(Object.getPrototypeOf(obj), Intl.Segmenter.prototype, `proto check - ${localeMatcher}`);
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-intl.Segmenter
|
||||
description: >
|
||||
Throws TypeError if options is null
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
|
||||
...
|
||||
4. If options is undefined, then
|
||||
a. Let options be ObjectCreate(null).
|
||||
5. Else
|
||||
a. Let options be ? ToObject(options).
|
||||
...
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
new Intl.DisplayNames(undefined, null);
|
||||
}, 'null');
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-intl.segmenter
|
||||
description: >
|
||||
Return abrupt from Get Prototype from a custom NewTarget
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
|
||||
...
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
...
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
features: [Intl.Segmenter, Reflect, Proxy]
|
||||
---*/
|
||||
|
||||
var custom = new Proxy(new Function(), {
|
||||
get(target, key) {
|
||||
if (key === 'prototype') {
|
||||
throw new Test262Error();
|
||||
}
|
||||
|
||||
return target[key];
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, () => {
|
||||
Reflect.construct(Intl.Segmenter, [], custom);
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-intl.segmenter
|
||||
description: >
|
||||
Custom Prototype of the returned object based on the NewTarget
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
|
||||
...
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
...
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
features: [Intl.Segmenter, Reflect]
|
||||
---*/
|
||||
|
||||
var custom = new Function();
|
||||
custom.prototype = {};
|
||||
|
||||
const obj = Reflect.construct(Intl.Segmenter, [], custom);
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(obj), custom.prototype);
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-intl.segmenter
|
||||
description: >
|
||||
Prototype of the returned object is Segmenter.prototype
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
var obj = new Intl.Segmenter();
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(obj), Intl.Segmenter.prototype);
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2019 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-intl.segmenter
|
||||
description: Default [[Prototype]] value derived from realm of the NewTarget.
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
|
||||
...
|
||||
15. Return segmenter.
|
||||
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||
...
|
||||
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||
3. Return ObjectCreate(proto, internalSlotsList).
|
||||
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||
...
|
||||
3. Let proto be ? Get(constructor, 'prototype').
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
|
||||
5. Return proto.
|
||||
features: [cross-realm, Reflect, Symbol, Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
var other = $262.createRealm().global;
|
||||
var newTarget = new other.Function();
|
||||
var sgm;
|
||||
|
||||
newTarget.prototype = undefined;
|
||||
sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is undefined');
|
||||
|
||||
newTarget.prototype = null;
|
||||
sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is null');
|
||||
|
||||
newTarget.prototype = false;
|
||||
sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Boolean');
|
||||
|
||||
newTarget.prototype = 'str';
|
||||
sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a String');
|
||||
|
||||
newTarget.prototype = Symbol();
|
||||
sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Symbol');
|
||||
|
||||
newTarget.prototype = 1;
|
||||
sgm = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(sgm), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Number');
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2019 Leo Balter. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-intl.segmenter.prototype-@@tostringtag
|
||||
description: >
|
||||
Property descriptor of Segmenter.prototype[@@toStringTag]
|
||||
info: |
|
||||
The initial value of the @@toStringTag property is the string value "Intl.Segmenter".
|
||||
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Intl.Segmenter, Symbol.toStringTag]
|
||||
---*/
|
||||
|
||||
verifyProperty(Intl.Segmenter.prototype, Symbol.toStringTag, {
|
||||
value: "Intl.Segmenter",
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -0,0 +1,27 @@
|
|||
// 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 )
|
||||
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("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));
|
|
@ -0,0 +1,56 @@
|
|||
// 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).
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
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");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,46 @@
|
|||
// 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.
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
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);})
|
||||
});
|
||||
});
|
|
@ -0,0 +1,57 @@
|
|||
// 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: [propertyHelper.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 < " + input.length);
|
||||
assert.sameValue("string", typeof result.input, msg + "input");
|
||||
assert.sameValue(undefined, result.isWordLike,
|
||||
msg + "isWordLike should be undefined");
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// 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
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
// 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
|
||||
});
|
|
@ -0,0 +1,64 @@
|
|||
// 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.
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
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",
|
||||
];
|
||||
|
||||
// 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");
|
||||
});
|
|
@ -0,0 +1,51 @@
|
|||
// 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.
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
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",
|
||||
];
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
// 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"
|
||||
);
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
// 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).
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,54 @@
|
|||
// 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: [propertyHelper.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");
|
||||
}
|
||||
});
|
|
@ -0,0 +1,67 @@
|
|||
// 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.
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
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",
|
||||
];
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,36 @@
|
|||
// 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);
|
|
@ -0,0 +1,47 @@
|
|||
// 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);
|
|
@ -0,0 +1,52 @@
|
|||
// 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);
|
Loading…
Reference in New Issue