-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync test of Temporal.Calendar.p*.fields to 1750 (#3188)
* Sync test of Temporal.Calendar.p*.fields to 1750 https://github.com/tc39/proposal-temporal/pull * add more test * add more tests for T*.Calendar.p*.fields * Update test/built-ins/Temporal/Calendar/prototype/fields/long-input.js Co-authored-by: Ms2ger <Ms2ger@gmail.com> * Update test/built-ins/Temporal/Calendar/prototype/fields/long-input.js Co-authored-by: Ms2ger <Ms2ger@gmail.com> * Update test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js Co-authored-by: Ms2ger <Ms2ger@gmail.com> * Update test/built-ins/Temporal/Calendar/prototype/fields/reverse.js Co-authored-by: Ms2ger <Ms2ger@gmail.com> * Update test/built-ins/Temporal/Calendar/prototype/fields/reverse.js Co-authored-by: Ms2ger <Ms2ger@gmail.com> * Remove loop * Update test/built-ins/Temporal/Calendar/prototype/fields/long-input.js Co-authored-by: Ms2ger <Ms2ger@gmail.com> * Update long-input.js * Update repeated-throw.js * Update reverse.js * ensure the implementation check the content make sure the validation does not happen after the looping the generator * add test to check all valid field value Co-authored-by: Ms2ger <Ms2ger@gmail.com>
- Loading branch information
1 parent
d5ac0c3
commit 61339fd
Showing
3 changed files
with
128 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.fields | ||
description: > | ||
Temporal.Calendar.prototype.fields will throw if its input iterable yields | ||
the same value twice. | ||
info: | | ||
## 12.4.21 Temporal.Calendar.prototype.fields ( fields ) | ||
1. Let calendar be the this value. | ||
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). | ||
4. Let iteratorRecord be ? Getiterator(fields, sync). | ||
5. Let fieldNames be a new empty List. | ||
6. Let next be true. | ||
7. 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). | ||
iii. If fieldNames contains nextValue, then | ||
1. Let completion be ThrowCompletion(a newly created RangeError object). | ||
2. Return ? IteratorClose(iteratorRecord, completion). | ||
features: [Symbol, Symbol.iterator, Temporal, computed-property-names, generators] | ||
---*/ | ||
let cal = new Temporal.Calendar("iso8601") | ||
let i = 0; | ||
const fields = { | ||
*[Symbol.iterator]() { | ||
yield "month"; | ||
i++; | ||
yield "year"; | ||
i++; | ||
yield "year"; | ||
i++; | ||
} | ||
} | ||
assert.throws( | ||
RangeError, () => cal.fields(fields), "repeated valid value should throw"); | ||
assert.sameValue(i, 2, "Should stop at 2"); | ||
|
||
// Test all valid value will throw while repeate | ||
[ "nanosecond", "microsecond", "millisecond", "second", | ||
"minute", "hour", "day", "monthCode", "month", "year" ].forEach((f) => { | ||
i = 0; | ||
const fields2 = { | ||
*[Symbol.iterator]() { | ||
yield f; | ||
i++; | ||
yield f; | ||
i++; | ||
} | ||
} | ||
assert.throws( | ||
RangeError, () => cal.fields(fields2), "repeated valid value should throw"); | ||
assert.sameValue(i, 1, "Should stop at 1"); | ||
}); |
42 changes: 42 additions & 0 deletions
42
test/built-ins/Temporal/Calendar/prototype/fields/reverse.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2021 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.fields | ||
description: > | ||
Temporal.Calendar.prototype.fields will return the iterable in array if all | ||
input are valid regardless of it's order. | ||
info: | | ||
## 12.4.21 Temporal.Calendar.prototype.fields ( fields ) | ||
1. Let calendar be the this value. | ||
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). | ||
4. Let iteratorRecord be ? Getiterator(fields, sync). | ||
5. Let fieldNames be a new empty List. | ||
6. Let next be true. | ||
7. 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). | ||
iv. If nextValue is not one of "year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond", then | ||
1. Let completion be ThrowCompletion(a newly created RangeError object). | ||
2. Return ? IteratorClose(iteratorRecord, completion). | ||
features: [Symbol, Symbol.iterator, Temporal, computed-property-names, generators] | ||
includes: [compareArray.js] | ||
---*/ | ||
let cal = new Temporal.Calendar("iso8601") | ||
const fields = { | ||
*[Symbol.iterator]() { | ||
yield "nanosecond"; | ||
yield "microsecond"; | ||
yield "millisecond"; | ||
yield "second"; | ||
yield "minute"; | ||
yield "hour"; | ||
yield "day"; | ||
yield "monthCode"; | ||
yield "month"; | ||
yield "year"; | ||
} | ||
} | ||
assert.compareArray(cal.fields(fields), Array.from(fields), | ||
'valid fields should be supported even if they are in reversed order of the spec'); |