mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 07:25:15 +02:00
Add more tests for ListFormat (#2387)
* add tests for ListFormat address https://github.com/tc39/test262/issues/2386 * add test for formatToParts(undefined) * test GetIterator throw error * test formatToParts while GetIterator throws error * test formatToParts while step_iterator throw * test format while iteratorStep throw * fix object name * test format while IteratorValue throws * test formatToParts while iteratorValue throws * test formatToParts while iteratorClose call return * check format with iteratorClose calls return
This commit is contained in:
parent
2715f312db
commit
8f6369d1c4
27
test/intl402/ListFormat/prototype/format/iterable-getiterator-throw.js
vendored
Normal file
27
test/intl402/ListFormat/prototype/format/iterable-getiterator-throw.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.format() while the GetIterator
|
||||||
|
throws error.
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
2. Let iteratorRecord be ? GetIterator(iterable).
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function CustomError() {}
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
// Test the failure case.
|
||||||
|
let get_iterator_throw_error = {
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
throw new CustomError();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(CustomError,
|
||||||
|
()=> {lf.format(get_iterator_throw_error)});
|
55
test/intl402/ListFormat/prototype/format/iterable-iteratorclose.js
vendored
Normal file
55
test/intl402/ListFormat/prototype/format/iterable-iteratorclose.js
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.format() and check the IteratorClose
|
||||||
|
calls return.
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
2. Let iteratorRecord be ? GetIterator(iterable).
|
||||||
|
3. Let list be a new empty List.
|
||||||
|
4. Let next be true.
|
||||||
|
5. Repeat, while next is not false
|
||||||
|
a. Set next to ? IteratorStep(iteratorRecord).
|
||||||
|
b. If next is not false, then
|
||||||
|
i. Let nextValue be ? IteratorValue(next).
|
||||||
|
ii. If Type(nextValue) is not String, then
|
||||||
|
1. Let error be ThrowCompletion(a newly created TypeError object).
|
||||||
|
2. Return ? IteratorClose(iteratorRecord, error).
|
||||||
|
iii. Append nextValue to the end of the List list.
|
||||||
|
6. Return list.
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
// Test the failure case.
|
||||||
|
let iterator_close_call_return = {
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
"return"() {
|
||||||
|
this.returnIsCalled = true;
|
||||||
|
assert.sameValue(this.count, 3);
|
||||||
|
},
|
||||||
|
count: 0,
|
||||||
|
returnIsCalled: false,
|
||||||
|
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}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(TypeError,
|
||||||
|
()=> {lf.format(iterator_close_call_return)},
|
||||||
|
"Iterable yielded 3 which is not a string");
|
||||||
|
assert.sameValue(iterator_close_call_return.count, 3);
|
||||||
|
assert.sameValue(iterator_close_call_return.returnIsCalled, true);
|
41
test/intl402/ListFormat/prototype/format/iterable-iteratorstep-throw.js
vendored
Normal file
41
test/intl402/ListFormat/prototype/format/iterable-iteratorstep-throw.js
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.format() while iteratorStep throws error.
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
2. Let iteratorRecord be ? GetIterator(iterable).
|
||||||
|
3. Let list be a new empty List.
|
||||||
|
4. Let next be true.
|
||||||
|
5. Repeat, while next is not false
|
||||||
|
a. Set next to ? IteratorStep(iteratorRecord).
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
---*/
|
||||||
|
function CustomError() {}
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
// Test the failure case.
|
||||||
|
let iterator_step_throw = {
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
count: 0,
|
||||||
|
next() {
|
||||||
|
this.count++;
|
||||||
|
if (this.count == 3) {
|
||||||
|
throw new CustomError();
|
||||||
|
}
|
||||||
|
if (this.count < 5) {
|
||||||
|
return {done: false, value: String(this.count)};
|
||||||
|
}
|
||||||
|
return {done:true}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(CustomError,
|
||||||
|
()=> {lf.format(iterator_step_throw)});
|
||||||
|
assert.sameValue(iterator_step_throw.count, 3);
|
44
test/intl402/ListFormat/prototype/format/iterable-iteratorvalue-throw.js
vendored
Normal file
44
test/intl402/ListFormat/prototype/format/iterable-iteratorvalue-throw.js
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.format() while iteratorValue throws error.
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
2. Let iteratorRecord be ? GetIterator(iterable).
|
||||||
|
3. Let list be a new empty List.
|
||||||
|
4. Let next be true.
|
||||||
|
5. Repeat, while next is not false
|
||||||
|
a. Set next to ? IteratorStep(iteratorRecord).
|
||||||
|
b. If next is not false, then
|
||||||
|
i. Let nextValue be ? IteratorValue(next).
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function CustomError() {}
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
// Test the failure case.
|
||||||
|
let iterator_value_throw = {
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
count: 0,
|
||||||
|
next() {
|
||||||
|
this.count++;
|
||||||
|
if (this.count == 3) {
|
||||||
|
return {done: false, get value() { throw new CustomError() }};
|
||||||
|
}
|
||||||
|
if (this.count < 5) {
|
||||||
|
return {done: false, value: String(this.count)};
|
||||||
|
}
|
||||||
|
return {done:true}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(CustomError,
|
||||||
|
()=> {lf.format(iterator_value_throw)});
|
||||||
|
assert.sameValue(iterator_value_throw.count, 3);
|
17
test/intl402/ListFormat/prototype/format/iterable-undefined.js
vendored
Normal file
17
test/intl402/ListFormat/prototype/format/iterable-undefined.js
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.format(undefined).
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
|
||||||
|
assert.sameValue("", lf.format(undefined));
|
27
test/intl402/ListFormat/prototype/formatToParts/iterable-getiterator-throw.js
vendored
Normal file
27
test/intl402/ListFormat/prototype/formatToParts/iterable-getiterator-throw.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.formatToParts() while the GetIterator
|
||||||
|
throws error.
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
2. Let iteratorRecord be ? GetIterator(iterable).
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function CustomError() {}
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
// Test the failure case.
|
||||||
|
let get_iterator_throw_error = {
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
throw new CustomError();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(CustomError,
|
||||||
|
()=> {lf.formatToParts(get_iterator_throw_error)});
|
55
test/intl402/ListFormat/prototype/formatToParts/iterable-iteratorclose.js
vendored
Normal file
55
test/intl402/ListFormat/prototype/formatToParts/iterable-iteratorclose.js
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.formatToParts() and check the IteratorClose
|
||||||
|
calls return.
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
2. Let iteratorRecord be ? GetIterator(iterable).
|
||||||
|
3. Let list be a new empty List.
|
||||||
|
4. Let next be true.
|
||||||
|
5. Repeat, while next is not false
|
||||||
|
a. Set next to ? IteratorStep(iteratorRecord).
|
||||||
|
b. If next is not false, then
|
||||||
|
i. Let nextValue be ? IteratorValue(next).
|
||||||
|
ii. If Type(nextValue) is not String, then
|
||||||
|
1. Let error be ThrowCompletion(a newly created TypeError object).
|
||||||
|
2. Return ? IteratorClose(iteratorRecord, error).
|
||||||
|
iii. Append nextValue to the end of the List list.
|
||||||
|
6. Return list.
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
// Test the failure case.
|
||||||
|
let iterator_close_call_return = {
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
"return"() {
|
||||||
|
this.returnIsCalled = true;
|
||||||
|
assert.sameValue(this.count, 3);
|
||||||
|
},
|
||||||
|
count: 0,
|
||||||
|
returnIsCalled: false,
|
||||||
|
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}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(TypeError,
|
||||||
|
()=> {lf.formatToParts(iterator_close_call_return)},
|
||||||
|
"Iterable yielded 3 which is not a string");
|
||||||
|
assert.sameValue(iterator_close_call_return.count, 3);
|
||||||
|
assert.sameValue(iterator_close_call_return.returnIsCalled, true);
|
42
test/intl402/ListFormat/prototype/formatToParts/iterable-iteratorstep-throw.js
vendored
Normal file
42
test/intl402/ListFormat/prototype/formatToParts/iterable-iteratorstep-throw.js
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.formatToParts() while iteratorStep throws error.
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
2. Let iteratorRecord be ? GetIterator(iterable).
|
||||||
|
3. Let list be a new empty List.
|
||||||
|
4. Let next be true.
|
||||||
|
5. Repeat, while next is not false
|
||||||
|
a. Set next to ? IteratorStep(iteratorRecord).
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function CustomError() {}
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
// Test the failure case.
|
||||||
|
let iterator_step_throw = {
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
count: 0,
|
||||||
|
next() {
|
||||||
|
this.count++;
|
||||||
|
if (this.count == 3) {
|
||||||
|
throw new CustomError();
|
||||||
|
}
|
||||||
|
if (this.count < 5) {
|
||||||
|
return {done: false, value: String(this.count)};
|
||||||
|
}
|
||||||
|
return {done:true}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(CustomError,
|
||||||
|
()=> {lf.formatToParts(iterator_step_throw)});
|
||||||
|
assert.sameValue(iterator_step_throw.count, 3);
|
44
test/intl402/ListFormat/prototype/formatToParts/iterable-iteratorvalue-throw.js
vendored
Normal file
44
test/intl402/ListFormat/prototype/formatToParts/iterable-iteratorvalue-throw.js
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.formatToParts() while iteratorValue throws error.
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
2. Let iteratorRecord be ? GetIterator(iterable).
|
||||||
|
3. Let list be a new empty List.
|
||||||
|
4. Let next be true.
|
||||||
|
5. Repeat, while next is not false
|
||||||
|
a. Set next to ? IteratorStep(iteratorRecord).
|
||||||
|
b. If next is not false, then
|
||||||
|
i. Let nextValue be ? IteratorValue(next).
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function CustomError() {}
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
// Test the failure case.
|
||||||
|
let iterator_value_throw = {
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
count: 0,
|
||||||
|
next() {
|
||||||
|
this.count++;
|
||||||
|
if (this.count == 3) {
|
||||||
|
return {done: false, get value() { throw new CustomError() }};
|
||||||
|
}
|
||||||
|
if (this.count < 5) {
|
||||||
|
return {done: false, value: String(this.count)};
|
||||||
|
}
|
||||||
|
return {done:true}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(CustomError,
|
||||||
|
()=> {lf.formatToParts(iterator_value_throw)});
|
||||||
|
assert.sameValue(iterator_value_throw.count, 3);
|
18
test/intl402/ListFormat/prototype/formatToParts/iterable-undefined.js
vendored
Normal file
18
test/intl402/ListFormat/prototype/formatToParts/iterable-undefined.js
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-Intl.ListFormat.prototype.format
|
||||||
|
description: Checks the behavior of Abstract Operation StringListFromIterable
|
||||||
|
called by Intl.ListFormat.prototype.formatToParts(undefined).
|
||||||
|
info: |
|
||||||
|
StringListFromIterable
|
||||||
|
1. If iterable is undefined, then
|
||||||
|
a. Return a new empty List.
|
||||||
|
features: [Intl.ListFormat]
|
||||||
|
includes: [compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let lf = new Intl.ListFormat();
|
||||||
|
|
||||||
|
assert(compareArray([], lf.formatToParts(undefined)));
|
Loading…
x
Reference in New Issue
Block a user