4f87e1a045
This is a reland of 482c3bbf1e
Original change's description:
> [Intl] Sync Intl.Segmenter to latest version
>
> https://tc39.es/proposal-intl-segmenter/
>
> TC39 passed Intl.Segmenter to stage 3 in Jul 21.
> This CL move our earlier prototype to the current spec.
>
> Bug: v8:6891
> Change-Id: I07234beed54f671c26bdbfb3983c5bc2fa5a29b0
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2219413
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Reviewed-by: Frank Tang <ftang@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Commit-Queue: Frank Tang <ftang@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#69080}
Bug: v8:6891
Change-Id: Ie3a02d8ddf6f95f0632f97b38b613b185abeb592
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2321118
Reviewed-by: Frank Tang <ftang@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69153}
42 lines
1.9 KiB
JavaScript
42 lines
1.9 KiB
JavaScript
// 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
|
|
|
|
assertEquals("function", typeof Intl.Segmenter.prototype.segment);
|
|
assertEquals(1, Intl.Segmenter.prototype.segment.length);
|
|
|
|
let seg = new Intl.Segmenter("en", {granularity: "word"})
|
|
let segments;
|
|
|
|
// test with 0 args
|
|
assertDoesNotThrow(() => segments = seg.segment())
|
|
// test with 1 arg
|
|
assertDoesNotThrow(() => segments = seg.segment("hello"))
|
|
assertEquals("hello", segments.containing(0).input);
|
|
// test with 2 args
|
|
assertDoesNotThrow(() => segments = seg.segment("hello world"))
|
|
assertEquals("hello world", segments.containing(0).input);
|
|
|
|
// test with other types
|
|
assertDoesNotThrow(() => segments = seg.segment(undefined))
|
|
assertEquals("undefined", segments.containing(0).input);
|
|
assertDoesNotThrow(() => segments = seg.segment(null))
|
|
assertEquals("null", segments.containing(0).input);
|
|
assertDoesNotThrow(() => segments = seg.segment(true))
|
|
assertEquals("true", segments.containing(0).input);
|
|
assertDoesNotThrow(() => segments = seg.segment(false))
|
|
assertEquals("false", segments.containing(0).input);
|
|
assertDoesNotThrow(() => segments = seg.segment(1234))
|
|
assertEquals("1234", segments.containing(0).input);
|
|
assertDoesNotThrow(() => segments = seg.segment(3.1415926))
|
|
assertEquals("3.1415926", segments.containing(0).input);
|
|
assertDoesNotThrow(() => segments = seg.segment(98765432109876543210987654321n))
|
|
assertEquals("98765432109876543210987654321", segments.containing(0).input);
|
|
assertDoesNotThrow(() => segments = seg.segment(["hello","world"]))
|
|
assertEquals("hello,world", segments.containing(0).input);
|
|
assertDoesNotThrow(() => segments = seg.segment({k: 'v'}))
|
|
assertEquals("[object Object]", segments.containing(0).input);
|
|
assertThrows(() => segments = seg.segment(Symbol()), TypeError)
|