mirror of
https://github.com/tc39/test262.git
synced 2025-07-25 15:04:43 +02:00
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>
This commit is contained in:
parent
d5ac0c348a
commit
61339fd294
@ -4,28 +4,44 @@
|
|||||||
/*---
|
/*---
|
||||||
esid: sec-temporal.calendar.prototype.fields
|
esid: sec-temporal.calendar.prototype.fields
|
||||||
description: >
|
description: >
|
||||||
Temporal.Calendar.prototype.fields will take iterable of any size and any string
|
Temporal.Calendar.prototype.fields will throw when its input iterable yields an
|
||||||
and return Array of the same content.
|
invalid field.
|
||||||
info: |
|
info: |
|
||||||
## 12.4.21 Temporal.Calendar.prototype.fields ( fields )
|
## 12.4.21 Temporal.Calendar.prototype.fields ( fields )
|
||||||
1. Let calendar be the this value.
|
1. Let calendar be the this value.
|
||||||
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
|
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
|
||||||
3. Assert: calendar.[[Identifier]] is "iso8601".
|
4. Let iteratorRecord be ? Getiterator(fields, sync).
|
||||||
4. Let fieldNames be ? IterableToListOfType(fields, « String »).
|
5. Let fieldNames be a new empty List.
|
||||||
5. Return ! CreateArrayFromList(fieldNames).
|
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]
|
features: [Symbol, Symbol.iterator, Temporal, computed-property-names, generators]
|
||||||
includes: [compareArray.js]
|
|
||||||
---*/
|
---*/
|
||||||
let cal = new Temporal.Calendar("iso8601")
|
let cal = new Temporal.Calendar("iso8601")
|
||||||
|
let i = 0;
|
||||||
const fields = {
|
const fields = {
|
||||||
*[Symbol.iterator]() {
|
*[Symbol.iterator]() {
|
||||||
let i = 0;
|
// The first three are valid values
|
||||||
while (i++ < 1000001) {
|
yield "year";
|
||||||
yield "garbage " + i;
|
i++;
|
||||||
}
|
yield "month";
|
||||||
|
i++;
|
||||||
|
yield "monthCode";
|
||||||
|
i++;
|
||||||
|
// The fourth one is wrong and should throw after the next line.
|
||||||
|
yield "garbage";
|
||||||
|
// The following three lines should not be reached if the implemention
|
||||||
|
// correctly check the previous line.
|
||||||
|
i++;
|
||||||
|
yield "hour";
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(
|
assert.throws(RangeError, () => cal.fields(fields), "Garbage content");
|
||||||
compareArray(cal.fields(fields), Array.from(fields)),
|
// stop after the third one.
|
||||||
'compareArray(cal.fields(fields), Array.from(fields)) must return true'
|
assert.sameValue(i, 3);
|
||||||
);
|
|
||||||
|
56
test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js
vendored
Normal file
56
test/built-ins/Temporal/Calendar/prototype/fields/repeated-throw.js
vendored
Normal file
@ -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
test/built-ins/Temporal/Calendar/prototype/fields/reverse.js
vendored
Normal file
42
test/built-ins/Temporal/Calendar/prototype/fields/reverse.js
vendored
Normal file
@ -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');
|
Loading…
x
Reference in New Issue
Block a user