v8/test/intl/regress-9747.js
Frank Tang 8d1b4774bf [Intl] Sync ListFormat to latest spec.
1. Add StringListFromIterable based on
https://tc39.es/proposal-intl-list-format/#sec-createstringlistfromiterable
2. Adjust other parts to sync with the new version.

Bug: v8:9747
Change-Id: I14202f2963463e6a3e9816209f087bfe8e73cb91
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1809902
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63899}
2019-09-19 20:02:53 +00:00

51 lines
1.3 KiB
JavaScript

// Copyright 2019 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.
let lf = new Intl.ListFormat("en");
// Test normal array
assertDoesNotThrow(() => lf.format(['a','b','c']));
assertThrows("lf.format(['a','b',3])", TypeError, "Iterable yielded 3 which is not a string");
// Test sparse array
let sparse = ['a','b'];
sparse[10] = 'c';
assertThrows("lf.format(sparse)", TypeError, "Iterable yielded undefined which is not a string");
// Test iterable of all String
let iterable_of_strings = {
[Symbol.iterator]() {
return this;
},
count: 0,
next() {
if (this.count++ < 4) {
return {done: false, value: String(this.count)};
}
return {done:true}
}
};
assertDoesNotThrow(() => lf.format(iterable_of_strings));
// Test iterable of none String throw TypeError
let iterable_of_strings_and_number = {
[Symbol.iterator]() {
return this;
},
count: 0,
next() {
this.count++;
if (this.count == 3) {
return {done:false, value: 3};
}
if (this.count < 5) {
return {done: false, value: String(this.count)};
}
return {done:true}
}
};
assertThrows("lf.format(iterable_of_strings_and_number)",
TypeError, "Iterable yielded 3 which is not a string");
assertEquals(3, iterable_of_strings_and_number.count);