ac8b5b919e
Spec: http://tc39.github.io/proposal-intl-list-format/ Design Doc: go/add-intl.listformat-to-v8 Test: intl/list-format/* R=gsathya@chromium.org, mvstanton@chromium.org Bug: v8:7871 Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng Change-Id: I0dfb91b7806007e4f02f3b0438c30528c8143081 Reviewed-on: https://chromium-review.googlesource.com/1124343 Commit-Queue: Frank Tang <ftang@chromium.org> Reviewed-by: Daniel Ehrenberg <littledan@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#54668}
109 lines
2.9 KiB
JavaScript
109 lines
2.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-list-format
|
|
|
|
// ListFormat constructor can't be called as function.
|
|
assertThrows(() => Intl.ListFormat(['sr']), TypeError);
|
|
|
|
// Non-string locale.
|
|
// assertThrows(() => new Intl.ListFormat(5), TypeError);
|
|
|
|
// Invalid locale string.
|
|
assertThrows(() => new Intl.ListFormat(['abcdefghi']), RangeError);
|
|
|
|
assertDoesNotThrow(() => new Intl.ListFormat(['sr'], {}), TypeError);
|
|
|
|
assertDoesNotThrow(() => new Intl.ListFormat([], {}));
|
|
|
|
assertDoesNotThrow(() => new Intl.ListFormat(['fr', 'ar'], {}));
|
|
|
|
assertDoesNotThrow(() => new Intl.ListFormat({0: 'ja', 1:'fr'}, {}));
|
|
|
|
assertDoesNotThrow(() => new Intl.ListFormat({1: 'ja', 2:'fr'}, {}));
|
|
|
|
assertDoesNotThrow(() => new Intl.ListFormat(['sr']));
|
|
|
|
assertDoesNotThrow(() => new Intl.ListFormat());
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(
|
|
['sr'], {
|
|
style: 'short',
|
|
type: 'unit'
|
|
}));
|
|
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'conjunction'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'disjunction'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'unit'}));
|
|
|
|
assertThrows(
|
|
() => new Intl.ListFormat(['sr'], {type: 'standard'}),
|
|
RangeError);
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {style: 'long'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {style: 'short'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {style: 'narrow'}));
|
|
|
|
assertThrows(
|
|
() => new Intl.ListFormat(['sr'], {style: 'giant'}),
|
|
RangeError);
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'conjunction', style: 'long'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'conjunction', style: 'short'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'conjunction', style: 'narrow'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'long'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'short'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'narrow'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'unit', style: 'long'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'unit', style: 'short'}));
|
|
|
|
assertDoesNotThrow(
|
|
() => new Intl.ListFormat(['sr'], {type: 'unit', style: 'narrow'}));
|
|
|
|
// Throws only once during construction.
|
|
// Check for all getters to prevent regression.
|
|
// Preserve the order of getter initialization.
|
|
let getCount = 0;
|
|
let style = -1;
|
|
let type = -1;
|
|
|
|
new Intl.ListFormat(['en-US'], {
|
|
get style() {
|
|
style = ++getCount;
|
|
},
|
|
get type() {
|
|
type = ++getCount;
|
|
}
|
|
});
|
|
|
|
assertEquals(1, type);
|
|
assertEquals(2, style);
|