2018-10-06 08:53:28 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
assertEquals("function", typeof Intl.Segmenter.prototype.segment);
|
2018-10-18 07:59:28 +00:00
|
|
|
assertEquals(1, Intl.Segmenter.prototype.segment.length);
|
|
|
|
|
|
|
|
let seg = new Intl.Segmenter("en", {granularity: "word"})
|
2020-07-29 15:06:31 +00:00
|
|
|
let segments;
|
2018-10-18 07:59:28 +00:00
|
|
|
|
|
|
|
// test with 0 args
|
2020-07-29 15:06:31 +00:00
|
|
|
assertDoesNotThrow(() => segments = seg.segment())
|
2018-10-18 07:59:28 +00:00
|
|
|
// test with 1 arg
|
2020-07-29 15:06:31 +00:00
|
|
|
assertDoesNotThrow(() => segments = seg.segment("hello"))
|
|
|
|
assertEquals("hello", segments.containing(0).input);
|
2018-10-18 07:59:28 +00:00
|
|
|
// test with 2 args
|
2020-07-29 15:06:31 +00:00
|
|
|
assertDoesNotThrow(() => segments = seg.segment("hello world"))
|
|
|
|
assertEquals("hello world", segments.containing(0).input);
|
2018-10-18 07:59:28 +00:00
|
|
|
|
|
|
|
// test with other types
|
2020-07-29 15:06:31 +00:00
|
|
|
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)
|