Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync test of Temporal.Calendar.p*.fields to 1750 #3188

Merged
merged 15 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions test/built-ins/Temporal/Calendar/prototype/fields/long-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,33 @@ info: |
## 12.4.21 Temporal.Calendar.prototype.fields ( fields )
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. Let fieldNames be ? IterableToListOfType(fields, « String »).
5. Return ! CreateArrayFromList(fieldNames).
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")
let i = 0;
const fields = {
*[Symbol.iterator]() {
let i = 0;
while (i++ < 1000001) {
yield "garbage " + i;
}
// The first three are valid values
yield "year";
i++;
yield "month";
i++;
yield "monthCode";
i++;
// The fourth one is wrong
yield "garbage";
}
}
assert(
compareArray(cal.fields(fields), Array.from(fields)),
'compareArray(cal.fields(fields), Array.from(fields)) must return true'
);
assert.throws(RangeError, () => cal.fields(fields), "Garbage content");
// stop after the third one.
assert.sameValue(i, 3);
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 take iterable of any size and any string
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
and return Array of the same content.
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");
42 changes: 42 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/fields/reverse.js
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 take iterable of any size and any string
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
and return Array of the same content.
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');