mirror of https://github.com/tc39/test262.git
Merge branch 'segmenter-v8' of git://github.com/Ms2ger/test262 into Ms2ger-segmenter-v8
* 'segmenter-v8' of git://github.com/Ms2ger/test262: Intl.Segmenter: Submit batch of V8 tests for the iterators. # Conflicts: # implementation-contributed/v8/intl/segmenter/segment-iterator-ownPropertyDescriptor.js
This commit is contained in:
commit
1fb8e8d22f
|
@ -1,11 +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 segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assertEquals(undefined, iter.breakType);
|
|
@ -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
|
||||
|
||||
const segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assertEquals("function", typeof iter.following);
|
||||
|
||||
assertThrows(() => iter.following("ABC"), RangeError);
|
||||
assertThrows(() => iter.following(null), RangeError);
|
||||
assertThrows(() => iter.following(1.4), RangeError);
|
||||
assertThrows(() => iter.following(-3), RangeError);
|
||||
|
||||
// 1.5.3.2 %SegmentIteratorPrototype%.following( [ from ] )
|
||||
// 3.b If from >= iterator.[[SegmentIteratorString]], throw a RangeError exception.
|
||||
assertDoesNotThrow(() => iter.following(text.length - 1));
|
||||
assertThrows(() => iter.following(text.length), RangeError);
|
||||
assertThrows(() => iter.following(text.length + 1), RangeError);
|
|
@ -1,11 +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 segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assertEquals("function", typeof iter.next);
|
|
@ -1,91 +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 seg = new Intl.Segmenter();
|
||||
let descriptor = Object.getOwnPropertyDescriptor(
|
||||
Intl.Segmenter, "supportedLocalesOf");
|
||||
assertTrue(descriptor.writable);
|
||||
assertFalse(descriptor.enumerable);
|
||||
assertTrue(descriptor.configurable);
|
||||
|
||||
// ecma402 #sec-Intl.Segmenter.prototype
|
||||
// Intl.Segmenter.prototype
|
||||
// The value of Intl.Segmenter.prototype is %SegmenterPrototype%.
|
||||
// This property has the attributes
|
||||
// { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
|
||||
descriptor = Object.getOwnPropertyDescriptor(Intl.Segmenter, "prototype");
|
||||
assertFalse(descriptor.writable);
|
||||
assertFalse(descriptor.enumerable);
|
||||
assertFalse(descriptor.configurable);
|
||||
|
||||
for (let func of ["segment", "resolvedOptions"]) {
|
||||
let descriptor = Object.getOwnPropertyDescriptor(
|
||||
Intl.Segmenter.prototype, func);
|
||||
assertTrue(descriptor.writable);
|
||||
assertFalse(descriptor.enumerable);
|
||||
assertTrue(descriptor.configurable);
|
||||
}
|
||||
|
||||
let segmentIterator = seg.segment('text');
|
||||
let prototype = Object.getPrototypeOf(segmentIterator);
|
||||
for (let func of ["next", "following", "preceding"]) {
|
||||
let descriptor = Object.getOwnPropertyDescriptor(prototype, func);
|
||||
assertTrue(descriptor.writable);
|
||||
assertFalse(descriptor.enumerable);
|
||||
assertTrue(descriptor.configurable);
|
||||
}
|
||||
|
||||
function checkGetterProperty(prototype, property) {
|
||||
let desc = Object.getOwnPropertyDescriptor(prototype, property);
|
||||
assertEquals(`get ${property}`, desc.get.name);
|
||||
assertEquals('function', typeof desc.get)
|
||||
assertEquals(undefined, desc.set);
|
||||
assertFalse(desc.enumerable);
|
||||
assertTrue(desc.configurable);
|
||||
}
|
||||
|
||||
// Test the descriptor is correct for properties.
|
||||
checkGetterProperty(prototype, 'position');
|
||||
checkGetterProperty(prototype, 'breakType');
|
||||
|
||||
// Test the SegmentIteratorPrototype methods are called with same
|
||||
// receiver and won't throw.
|
||||
assertDoesNotThrow(() => prototype.next.call(segmentIterator));
|
||||
assertDoesNotThrow(() => prototype.following.call(segmentIterator));
|
||||
assertDoesNotThrow(() => prototype.preceding.call(segmentIterator));
|
||||
|
||||
// Test the SegmentIteratorPrototype methods are called with a different
|
||||
// receiver and correctly throw.
|
||||
var otherReceivers = [
|
||||
1, 123.45, undefined, null, "string", true, false,
|
||||
Intl, Intl.Segmenter, Intl.Segmenter.prototype,
|
||||
prototype,
|
||||
new Intl.Segmenter(),
|
||||
new Intl.Collator(),
|
||||
new Intl.DateTimeFormat(),
|
||||
new Intl.NumberFormat(),
|
||||
];
|
||||
for (let rec of otherReceivers) {
|
||||
assertThrows(() => prototype.next.call(rec), TypeError);
|
||||
assertThrows(() => prototype.following.call(rec), TypeError);
|
||||
assertThrows(() => prototype.preceding.call(rec), TypeError);
|
||||
}
|
||||
|
||||
// Check the property of the return object of next()
|
||||
let nextReturn = segmentIterator.next();
|
||||
|
||||
function checkProperty(obj, property) {
|
||||
let desc = Object.getOwnPropertyDescriptor(obj, property);
|
||||
assertTrue(desc.writable);
|
||||
assertTrue(desc.enumerable);
|
||||
assertTrue(desc.configurable);
|
||||
}
|
||||
|
||||
checkProperty(nextReturn, 'done');
|
||||
checkProperty(nextReturn, 'value');
|
||||
checkProperty(nextReturn.value, 'segment');
|
||||
checkProperty(nextReturn.value, 'breakType');
|
||||
checkProperty(nextReturn.value, 'position');
|
|
@ -1,11 +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 segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assertEquals(0, iter.position);
|
|
@ -1,26 +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 segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assertEquals("function", typeof iter.preceding);
|
||||
|
||||
assertThrows(() => iter.preceding("ABC"), RangeError);
|
||||
assertThrows(() => iter.preceding(null), RangeError);
|
||||
assertThrows(() => iter.preceding(1.4), RangeError);
|
||||
assertThrows(() => iter.preceding(-3), RangeError);
|
||||
|
||||
// 1.5.3.3 %SegmentIteratorPrototype%.preceding( [ from ] )
|
||||
// 3.b If ... from = 0, throw a RangeError exception.
|
||||
assertThrows(() => iter.preceding(0), RangeError);
|
||||
|
||||
// 1.5.3.3 %SegmentIteratorPrototype%.preceding( [ from ] )
|
||||
// 3.b If from > iterator.[[SegmentIteratorString]] ... , throw a RangeError exception.
|
||||
assertDoesNotThrow(() => iter.preceding(text.length - 1));
|
||||
assertDoesNotThrow(() => iter.preceding(text.length));
|
||||
assertThrows(() => iter.preceding(text.length + 1), RangeError);
|
|
@ -1,19 +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 text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
for (const granularity of ["grapheme", "word", "sentence", "line"]) {
|
||||
const segmenter = new Intl.Segmenter("en", { granularity });
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assertEquals("number", typeof iter.position);
|
||||
assertEquals(0, iter.position);
|
||||
if (granularity === "grapheme") {
|
||||
assertEquals(undefined, iter.breakType);
|
||||
} else {
|
||||
assertEquals("string", typeof iter.breakType);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-segment-iterator-prototype
|
||||
description: Verifies the behavior for the iterators.
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
const otherReceivers = [
|
||||
1, 123.45, undefined, null, "string", true, false,
|
||||
Intl, Intl.Segmenter, Intl.Segmenter.prototype,
|
||||
prototype,
|
||||
new Intl.Segmenter(),
|
||||
new Intl.Collator(),
|
||||
new Intl.DateTimeFormat(),
|
||||
new Intl.NumberFormat(),
|
||||
];
|
||||
for (const rec of otherReceivers) {
|
||||
assert.throws(TypeError, () => prototype.next.call(rec));
|
||||
assert.throws(TypeError, () => prototype.following.call(rec));
|
||||
assert.throws(TypeError, () => prototype.preceding.call(rec));
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-segment-iterator-prototype
|
||||
description: Verifies the behavior for the iterators.
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
const segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assert.sameValue(iter.breakType, undefined);
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-segment-iterator-prototype
|
||||
description: Verifies the behavior for the iterators.
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
const segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assert.sameValue("function", typeof iter.following);
|
||||
|
||||
const tests = [
|
||||
["3", 4],
|
||||
["ABC", 1],
|
||||
[null, 1],
|
||||
[true, 2],
|
||||
[1.4, 2],
|
||||
[{ valueOf() { return 5; } }, 6],
|
||||
[0, 1],
|
||||
[text.length - 1, text.length],
|
||||
];
|
||||
|
||||
for (const [input, position] of tests) {
|
||||
assert.sameValue(iter.following(0 | input), false);
|
||||
assert.sameValue(iter.position, position, String(input));
|
||||
}
|
||||
|
||||
assert.throws(RangeError, () => iter.following(-3));
|
||||
// 1.5.3.2 %SegmentIteratorPrototype%.following( [ from ] )
|
||||
// 3.b If from >= iterator.[[SegmentIteratorString]], throw a RangeError exception.
|
||||
assert.throws(RangeError, () => iter.following(text.length));
|
||||
assert.throws(RangeError, () => iter.following(text.length + 1));
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-segment-iterator-prototype
|
||||
description: Verifies the behavior for the iterators.
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
for (const granularity of ["grapheme", "word", "sentence", "line"]) {
|
||||
const segmenter = new Intl.Segmenter("en", { granularity });
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assert.sameValue(typeof iter.position, "number");
|
||||
assert.sameValue(iter.position, 0);
|
||||
if (granularity === "grapheme") {
|
||||
assert.sameValue(iter.breakType, undefined);
|
||||
} else {
|
||||
assert.sameValue(typeof iter.breakType, "string");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-segment-iterator-prototype
|
||||
description: Verifies the behavior for the iterators.
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
const segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assert.sameValue(typeof iter.next, "function");
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-segment-iterator-prototype
|
||||
description: Verifies the behavior for the iterators.
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
const segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assert.sameValue(iter.position, 0);
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-segment-iterator-prototype
|
||||
description: Verifies the behavior for the iterators.
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
const segmenter = new Intl.Segmenter();
|
||||
const text = "Hello World, Test 123! Foo Bar. How are you?";
|
||||
const iter = segmenter.segment(text);
|
||||
|
||||
assert.sameValue("function", typeof iter.following);
|
||||
|
||||
const tests = [
|
||||
["3", 2],
|
||||
[true, 0],
|
||||
[1.4, 0],
|
||||
[{ valueOf() { return 5; } }, 4],
|
||||
[text.length - 1, text.length - 2],
|
||||
[text.length, text.length - 1],
|
||||
];
|
||||
|
||||
for (const [input, position] of tests) {
|
||||
assert.sameValue(iter.preceding(0 | input), false);
|
||||
assert.sameValue(iter.position, position, String(input));
|
||||
}
|
||||
|
||||
assert.throws(RangeError, () => iter.preceding("ABC"));
|
||||
assert.throws(RangeError, () => iter.preceding(null));
|
||||
assert.throws(RangeError, () => iter.preceding(1.4));
|
||||
assert.throws(RangeError, () => iter.preceding(-3));
|
||||
|
||||
// 1.5.3.3 %SegmentIteratorPrototype%.preceding( [ from ] )
|
||||
// 3.b If ... from = 0, throw a RangeError exception.
|
||||
assert.throws(RangeError, () => iter.preceding(0));
|
||||
|
||||
// 1.5.3.3 %SegmentIteratorPrototype%.preceding( [ from ] )
|
||||
// 3.b If from > iterator.[[SegmentIteratorString]] ... , throw a RangeError exception.
|
||||
assert.throws(RangeError, () => iter.preceding(text.length + 1));
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-segment-iterator-prototype
|
||||
description: Verifies the behavior for the iterators.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Intl.Segmenter]
|
||||
---*/
|
||||
|
||||
const prototype = Object.getPrototypeOf((new Intl.Segmenter()).segment('text'));
|
||||
for (const func of ["next", "following", "preceding"]) {
|
||||
verifyProperty(prototype, func, {
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
|
||||
for (const property of ["position", "breakType"]) {
|
||||
let desc = Object.getOwnPropertyDescriptor(prototype, property);
|
||||
assert.sameValue(desc.get.name, `get ${property}`);
|
||||
assert.sameValue(typeof desc.get, "function")
|
||||
assert.sameValue(desc.set, undefined);
|
||||
assert.sameValue(desc.enumerable, false);
|
||||
assert.sameValue(desc.configurable, true);
|
||||
}
|
Loading…
Reference in New Issue