[Intl] Add more tests for Intl.Segmenter

Bug: v8:6891
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I623f996c0d80cd23dcad6ffedac993678a2af959
Reviewed-on: https://chromium-review.googlesource.com/c/1289609
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Daniel Ehrenberg <littledan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56830}
This commit is contained in:
Frank Tang 2018-10-19 15:17:36 -07:00 committed by Commit Bot
parent b51053d89e
commit 67776adeac

View File

@ -29,10 +29,47 @@ for (let func of ["segment", "resolvedOptions"]) {
assertTrue(descriptor.configurable);
}
let prototype = Object.getPrototypeOf(seg.segment('text'));
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);
}