mirror of https://github.com/tc39/test262.git
Add tests for Intl.DateTimeFormat formatRange and formatRangeToParts (#2139)
This commit is contained in:
parent
4d33170d0e
commit
0e8d1a29be
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2017-2019 André Bargull, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-partitiondatetimerangepattern
|
||||
description: |
|
||||
The Date constructor is not called to convert the input value.
|
||||
info: >
|
||||
Intl.DateTimeFormat.prototype.formatRange ( startDate , endDate )
|
||||
|
||||
5. Let x be ? ToNumber(startDate).
|
||||
6. Let y be ? ToNumber(endDate).
|
||||
8. Return ? FormatDateTimeRange(dtf, x, y).
|
||||
|
||||
PartitionDateTimeRangePattern ( dateTimeFormat, x, y )
|
||||
|
||||
1. Let x be TimeClip(x).
|
||||
2. If x is NaN, throw a RangeError exception.
|
||||
3. Let y be TimeClip(y).
|
||||
4. If y is NaN, throw a RangeError exception.
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const dtf = new Intl.DateTimeFormat();
|
||||
const dateTimeString = "2017-11-10T14:09:00.000Z";
|
||||
const date = new Date(dateTimeString);
|
||||
// |dateTimeString| is valid ISO-8601 style date/time string.
|
||||
assert.notSameValue(date, NaN);
|
||||
|
||||
// ToNumber() will try to parse the string as an integer and yield NaN, rather
|
||||
// than attempting to parse it like the Date constructor would.
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRange(dateTimeString, date);
|
||||
});
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRange(date, dateTimeString);
|
||||
});
|
46
test/intl402/DateTimeFormat/prototype/formatRange/argument-near-time-boundaries.js
vendored
Normal file
46
test/intl402/DateTimeFormat/prototype/formatRange/argument-near-time-boundaries.js
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2017-2019 André Bargull, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-partitiondatetimerangepattern
|
||||
description: |
|
||||
TimeClip is applied when calling Intl.DateTimeFormat.prototype.formatRange.
|
||||
info: >
|
||||
PartitionDateTimeRangePattern ( dateTimeFormat, x, y )
|
||||
|
||||
1. Let x be TimeClip(x).
|
||||
2. If x is NaN, throw a RangeError exception.
|
||||
3. Let y be TimeClip(y).
|
||||
4. If y is NaN, throw a RangeError exception.
|
||||
|
||||
TimeClip ( time )
|
||||
...
|
||||
2. If abs(time) > 8.64 × 10^15, return NaN.
|
||||
...
|
||||
|
||||
includes: [dateConstants.js]
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const dtf = new Intl.DateTimeFormat();
|
||||
const date = Date.now();
|
||||
|
||||
// Test values near the start of the ECMAScript time range.
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRange(start_of_time - 1, date);
|
||||
});
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRange(date, start_of_time - 1);
|
||||
});
|
||||
assert.sameValue(typeof dtf.formatRange(start_of_time, date), "string");
|
||||
assert.sameValue(typeof dtf.formatRange(start_of_time + 1, date), "string");
|
||||
|
||||
// Test values near the end of the ECMAScript time range.
|
||||
assert.sameValue(typeof dtf.formatRange(date, end_of_time - 1), "string");
|
||||
assert.sameValue(typeof dtf.formatRange(date, end_of_time), "string");
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRange(end_of_time + 1, date);
|
||||
});
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRange(date, end_of_time + 1);
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2017-2019 André Bargull, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-partitiondatetimerangepattern
|
||||
description: |
|
||||
TimeClip applies ToInteger on its input value.
|
||||
info: >
|
||||
Intl.DateTimeFormat.prototype.formatRange ( startDate , endDate )
|
||||
|
||||
5. Let x be ? ToNumber(startDate).
|
||||
6. Let y be ? ToNumber(endDate).
|
||||
|
||||
TimeClip ( time )
|
||||
...
|
||||
3. Let clippedTime be ! ToInteger(time).
|
||||
4. If clippedTime is -0, set clippedTime to +0.
|
||||
5. Return clippedTime.
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
// Switch to a time format instead of using DateTimeFormat's default date-only format.
|
||||
const dtf = new Intl.DateTimeFormat(undefined, {
|
||||
hour: "numeric", minute: "numeric", second: "numeric"
|
||||
});
|
||||
const date = Date.now();
|
||||
const expected = dtf.formatRange(0, date);
|
||||
|
||||
assert.sameValue(dtf.formatRange(-0.9, date), expected, "formatRange(-0.9)");
|
||||
assert.sameValue(dtf.formatRange(-0.5, date), expected, "formatRange(-0.5)");
|
||||
assert.sameValue(dtf.formatRange(-0.1, date), expected, "formatRange(-0.1)");
|
||||
assert.sameValue(dtf.formatRange(-Number.MIN_VALUE, date), expected, "formatRange(-Number.MIN_VALUE)");
|
||||
assert.sameValue(dtf.formatRange(-0, date), expected, "formatRange(-0)");
|
||||
assert.sameValue(dtf.formatRange(+0, date), expected, "formatRange(+0)");
|
||||
assert.sameValue(dtf.formatRange(Number.MIN_VALUE, date), expected, "formatRange(Number.MIN_VALUE)");
|
||||
assert.sameValue(dtf.formatRange(0.1, date), expected, "formatRange(0.1)");
|
||||
assert.sameValue(dtf.formatRange(0.5, date), expected, "formatRange(0.5)");
|
||||
assert.sameValue(dtf.formatRange(0.9, date), expected, "formatRange(0.9)");
|
54
test/intl402/DateTimeFormat/prototype/formatRange/argument-tonumber-throws.js
vendored
Normal file
54
test/intl402/DateTimeFormat/prototype/formatRange/argument-tonumber-throws.js
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright 2019 Igalia S.L. All rights reserved.
|
||||
// This code is governed by the license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Return abrupt completions from ToNumber(date)
|
||||
info: |
|
||||
Intl.DateTimeFormat.prototype.formatRange ( startDate , endDate )
|
||||
|
||||
5. Let x be ? ToNumber(startDate).
|
||||
6. Let y be ? ToNumber(endDate).
|
||||
features: [Symbol,Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const date = Date.now();
|
||||
|
||||
const objectValueOf = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
const objectToString = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
const dtf = new Intl.DateTimeFormat(["pt-BR"]);
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
dtf.formatRange(objectValueOf, date);
|
||||
}, "valueOf start");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
dtf.formatRange(date, objectValueOf);
|
||||
}, "valueOf end");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
dtf.formatRange(objectToString, date);
|
||||
}, "toString start");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
dtf.formatRange(date, objectToString);
|
||||
}, "toString end");
|
||||
|
||||
const s = Symbol('1');
|
||||
assert.throws(TypeError, function() {
|
||||
dtf.formatRange(s, date);
|
||||
}, "symbol start");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
dtf.formatRange(date, s);
|
||||
}, "symbol end");
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (C) 2012-2019 Mozilla Corporation, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-ecmascript-standard-built-in-objects
|
||||
description: >
|
||||
Tests that the Intl.DateTimeFormat.prototype.formatRange function meets the
|
||||
requirements for built-in objects defined by the ECMAScript Language
|
||||
Specification.
|
||||
includes: [isConstructor.js]
|
||||
features: [Reflect.construct,Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const formatRange = Intl.DateTimeFormat.prototype.formatRange;
|
||||
|
||||
assert.sameValue(Object.prototype.toString.call(formatRange), "[object Function]",
|
||||
"The [[Class]] internal property of a built-in function must be " +
|
||||
"\"Function\".");
|
||||
|
||||
assert(Object.isExtensible(formatRange),
|
||||
"Built-in objects must be extensible.");
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(formatRange), Function.prototype);
|
||||
|
||||
assert.sameValue(formatRange.hasOwnProperty("prototype"), false,
|
||||
"Built-in functions that aren't constructors must not have a prototype property.");
|
||||
|
||||
assert.sameValue(isConstructor(formatRange), false,
|
||||
"Built-in functions don't implement [[Construct]] unless explicitly specified.");
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2019 the V8 project authors, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-partitiondatetimerangepattern
|
||||
description: Basic tests for the en-US output of formatRange()
|
||||
info: >
|
||||
Intl.DateTimeFormat.prototype.formatRange ( startDate , endDate )
|
||||
|
||||
8. Return ? FormatDateTimeRange(dtf, x, y).
|
||||
locale: [en-US]
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const date1 = new Date("2019-01-03T00:00:00");
|
||||
const date2 = new Date("2019-01-05T00:00:00");
|
||||
const date3 = new Date("2019-03-04T00:00:00");
|
||||
const date4 = new Date("2020-03-04T00:00:00");
|
||||
|
||||
let dtf = new Intl.DateTimeFormat("en-US");
|
||||
assert.sameValue(dtf.formatRange(date1, date1), "1/3/2019");
|
||||
assert.sameValue(dtf.formatRange(date1, date2), "1/3/2019 – 1/5/2019");
|
||||
assert.sameValue(dtf.formatRange(date1, date3), "1/3/2019 – 3/4/2019");
|
||||
assert.sameValue(dtf.formatRange(date1, date4), "1/3/2019 – 3/4/2020");
|
||||
assert.sameValue(dtf.formatRange(date2, date3), "1/5/2019 – 3/4/2019");
|
||||
assert.sameValue(dtf.formatRange(date2, date4), "1/5/2019 – 3/4/2020");
|
||||
assert.sameValue(dtf.formatRange(date3, date4), "3/4/2019 – 3/4/2020");
|
||||
|
||||
dtf = new Intl.DateTimeFormat("en-US", {year: "numeric", month: "short", day: "numeric"});
|
||||
assert.sameValue(dtf.formatRange(date1, date1), "Jan 3, 2019");
|
||||
assert.sameValue(dtf.formatRange(date1, date2), "Jan 3 – 5, 2019");
|
||||
assert.sameValue(dtf.formatRange(date1, date3), "Jan 3 – Mar 4, 2019");
|
||||
assert.sameValue(dtf.formatRange(date1, date4), "Jan 3, 2019 – Mar 4, 2020");
|
||||
assert.sameValue(dtf.formatRange(date2, date3), "Jan 5 – Mar 4, 2019");
|
||||
assert.sameValue(dtf.formatRange(date2, date4), "Jan 5, 2019 – Mar 4, 2020");
|
||||
assert.sameValue(dtf.formatRange(date3, date4), "Mar 4, 2019 – Mar 4, 2020");
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2016-2019 Mozilla Corporation, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Property type and descriptor.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof Intl.DateTimeFormat.prototype.formatRange,
|
||||
'function',
|
||||
'`typeof Intl.DateTimeFormat.prototype.formatRange` is `function`'
|
||||
);
|
||||
|
||||
verifyProperty(Intl.DateTimeFormat.prototype, 'formatRange', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2019 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Throws a TypeError if this is not a DateTimeFormat object
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const formatRange = Intl.DateTimeFormat.prototype.formatRange;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
formatRange.call({});
|
||||
}, "{}");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
formatRange.call(new Date());
|
||||
}, "new Date()");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
formatRange.call(Intl.DateTimeFormat);
|
||||
}, "Intl.DateTimeFormat");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
formatRange.call(Intl.DateTimeFormat.prototype);
|
||||
}, "Intl.DateTimeFormat.prototype");
|
38
test/intl402/DateTimeFormat/prototype/formatRangeToParts/argument-date-string.js
vendored
Normal file
38
test/intl402/DateTimeFormat/prototype/formatRangeToParts/argument-date-string.js
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2017-2019 André Bargull, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-partitiondatetimerangepattern
|
||||
description: |
|
||||
The Date constructor is not called to convert the input value.
|
||||
info: >
|
||||
Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate , endDate )
|
||||
|
||||
5. Let x be ? ToNumber(startDate).
|
||||
6. Let y be ? ToNumber(endDate).
|
||||
8. Return ? FormatDateTimeRange(dtf, x, y).
|
||||
|
||||
PartitionDateTimeRangePattern ( dateTimeFormat, x, y )
|
||||
|
||||
1. Let x be TimeClip(x).
|
||||
2. If x is NaN, throw a RangeError exception.
|
||||
3. Let y be TimeClip(y).
|
||||
4. If y is NaN, throw a RangeError exception.
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const dtf = new Intl.DateTimeFormat();
|
||||
const dateTimeString = "2017-11-10T14:09:00.000Z";
|
||||
const date = new Date(dateTimeString);
|
||||
// |dateTimeString| is valid ISO-8601 style date/time string.
|
||||
assert.notSameValue(date, NaN);
|
||||
|
||||
// ToNumber() will try to parse the string as an integer and yield NaN, rather
|
||||
// than attempting to parse it like the Date constructor would.
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRangeToParts(dateTimeString, date);
|
||||
});
|
||||
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRangeToParts(date, dateTimeString);
|
||||
});
|
46
test/intl402/DateTimeFormat/prototype/formatRangeToParts/argument-near-time-boundaries.js
vendored
Normal file
46
test/intl402/DateTimeFormat/prototype/formatRangeToParts/argument-near-time-boundaries.js
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2017-2019 André Bargull, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-partitiondatetimerangepattern
|
||||
description: |
|
||||
TimeClip is applied when calling Intl.DateTimeFormat.prototype.formatRangeToParts.
|
||||
info: >
|
||||
PartitionDateTimeRangePattern ( dateTimeFormat, x, y )
|
||||
|
||||
1. Let x be TimeClip(x).
|
||||
2. If x is NaN, throw a RangeError exception.
|
||||
3. Let y be TimeClip(y).
|
||||
4. If y is NaN, throw a RangeError exception.
|
||||
|
||||
TimeClip ( time )
|
||||
...
|
||||
2. If abs(time) > 8.64 × 10^15, return NaN.
|
||||
...
|
||||
|
||||
includes: [dateConstants.js]
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const dtf = new Intl.DateTimeFormat();
|
||||
const date = Date.now();
|
||||
|
||||
// Test values near the start of the ECMAScript time range.
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRangeToParts(start_of_time - 1, date);
|
||||
});
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRangeToParts(date, start_of_time - 1);
|
||||
});
|
||||
assert.sameValue(typeof dtf.formatRangeToParts(start_of_time, date), "object");
|
||||
assert.sameValue(typeof dtf.formatRangeToParts(start_of_time + 1, date), "object");
|
||||
|
||||
// Test values near the end of the ECMAScript time range.
|
||||
assert.sameValue(typeof dtf.formatRangeToParts(date, end_of_time - 1), "object");
|
||||
assert.sameValue(typeof dtf.formatRangeToParts(date, end_of_time), "object");
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRangeToParts(end_of_time + 1, date);
|
||||
});
|
||||
assert.throws(RangeError, function() {
|
||||
dtf.formatRangeToParts(date, end_of_time + 1);
|
||||
});
|
53
test/intl402/DateTimeFormat/prototype/formatRangeToParts/argument-to-integer.js
vendored
Normal file
53
test/intl402/DateTimeFormat/prototype/formatRangeToParts/argument-to-integer.js
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2017-2019 André Bargull, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-partitiondatetimerangepattern
|
||||
description: |
|
||||
TimeClip applies ToInteger on its input value.
|
||||
info: >
|
||||
Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate , endDate )
|
||||
|
||||
5. Let x be ? ToNumber(startDate).
|
||||
6. Let y be ? ToNumber(endDate).
|
||||
|
||||
TimeClip ( time )
|
||||
...
|
||||
3. Let clippedTime be ! ToInteger(time).
|
||||
4. If clippedTime is -0, set clippedTime to +0.
|
||||
5. Return clippedTime.
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
function* zip(a, b) {
|
||||
assert.sameValue(a.length, b.length);
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
yield [i, a[i], b[i]];
|
||||
}
|
||||
}
|
||||
|
||||
function compare(actual, expected, message) {
|
||||
for (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
|
||||
assert.sameValue(actualEntry.type, expectedEntry.type, `${message}: type for entry ${i}`);
|
||||
assert.sameValue(actualEntry.value, expectedEntry.value, `${message}: value for entry ${i}`);
|
||||
assert.sameValue(actualEntry.source, expectedEntry.source, `${message}: source for entry ${i}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Switch to a time format instead of using DateTimeFormat's default date-only format.
|
||||
const dtf = new Intl.DateTimeFormat(undefined, {
|
||||
hour: "numeric", minute: "numeric", second: "numeric"
|
||||
});
|
||||
const date = Date.now();
|
||||
const expected = dtf.formatRangeToParts(0, date);
|
||||
|
||||
compare(dtf.formatRangeToParts(-0.9, date), expected, "formatRangeToParts(-0.9)");
|
||||
compare(dtf.formatRangeToParts(-0.5, date), expected, "formatRangeToParts(-0.5)");
|
||||
compare(dtf.formatRangeToParts(-0.1, date), expected, "formatRangeToParts(-0.1)");
|
||||
compare(dtf.formatRangeToParts(-Number.MIN_VALUE, date), expected, "formatRangeToParts(-Number.MIN_VALUE)");
|
||||
compare(dtf.formatRangeToParts(-0, date), expected, "formatRangeToParts(-0)");
|
||||
compare(dtf.formatRangeToParts(+0, date), expected, "formatRangeToParts(+0)");
|
||||
compare(dtf.formatRangeToParts(Number.MIN_VALUE, date), expected, "formatRangeToParts(Number.MIN_VALUE)");
|
||||
compare(dtf.formatRangeToParts(0.1, date), expected, "formatRangeToParts(0.1)");
|
||||
compare(dtf.formatRangeToParts(0.5, date), expected, "formatRangeToParts(0.5)");
|
||||
compare(dtf.formatRangeToParts(0.9, date), expected, "formatRangeToParts(0.9)");
|
54
test/intl402/DateTimeFormat/prototype/formatRangeToParts/argument-tonumber-throws.js
vendored
Normal file
54
test/intl402/DateTimeFormat/prototype/formatRangeToParts/argument-tonumber-throws.js
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright 2019 Igalia S.L. All rights reserved.
|
||||
// This code is governed by the license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Return abrupt completions from ToNumber(date)
|
||||
info: |
|
||||
Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate , endDate )
|
||||
|
||||
5. Let x be ? ToNumber(startDate).
|
||||
6. Let y be ? ToNumber(endDate).
|
||||
features: [Symbol,Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const date = Date.now();
|
||||
|
||||
const objectValueOf = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
const objectToString = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
const dtf = new Intl.DateTimeFormat(["pt-BR"]);
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
dtf.formatRangeToParts(objectValueOf, date);
|
||||
}, "valueOf start");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
dtf.formatRangeToParts(date, objectValueOf);
|
||||
}, "valueOf end");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
dtf.formatRangeToParts(objectToString, date);
|
||||
}, "toString start");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
dtf.formatRangeToParts(date, objectToString);
|
||||
}, "toString end");
|
||||
|
||||
const s = Symbol('1');
|
||||
assert.throws(TypeError, function() {
|
||||
dtf.formatRangeToParts(s, date);
|
||||
}, "symbol start");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
dtf.formatRangeToParts(date, s);
|
||||
}, "symbol end");
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (C) 2012-2019 Mozilla Corporation, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-ecmascript-standard-built-in-objects
|
||||
description: >
|
||||
Tests that the Intl.DateTimeFormat.prototype.formatRangeToParts function meets the
|
||||
requirements for built-in objects defined by the ECMAScript Language
|
||||
Specification.
|
||||
includes: [isConstructor.js]
|
||||
features: [Reflect.construct,Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const formatRangeToParts = Intl.DateTimeFormat.prototype.formatRangeToParts;
|
||||
|
||||
assert.sameValue(Object.prototype.toString.call(formatRangeToParts), "[object Function]",
|
||||
"The [[Class]] internal property of a built-in function must be " +
|
||||
"\"Function\".");
|
||||
|
||||
assert(Object.isExtensible(formatRangeToParts),
|
||||
"Built-in objects must be extensible.");
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(formatRangeToParts), Function.prototype);
|
||||
|
||||
assert.sameValue(formatRangeToParts.hasOwnProperty("prototype"), false,
|
||||
"Built-in functions that aren't constructors must not have a prototype property.");
|
||||
|
||||
assert.sameValue(isConstructor(formatRangeToParts), false,
|
||||
"Built-in functions don't implement [[Construct]] unless explicitly specified.");
|
|
@ -0,0 +1,199 @@
|
|||
// Copyright (C) 2019 the V8 project authors, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-partitiondatetimerangepattern
|
||||
description: Basic tests for the en-US output of formatRangeToParts()
|
||||
info: >
|
||||
Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate , endDate )
|
||||
|
||||
8. Return ? FormatDateTimeRange(dtf, x, y).
|
||||
locale: [en-US]
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
function* zip(a, b) {
|
||||
assert.sameValue(a.length, b.length);
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
yield [i, a[i], b[i]];
|
||||
}
|
||||
}
|
||||
|
||||
function compare(actual, expected) {
|
||||
for (const [i, actualEntry, expectedEntry] of zip(actual, expected)) {
|
||||
assert.sameValue(actualEntry.type, expectedEntry.type, `type for entry ${i}`);
|
||||
assert.sameValue(actualEntry.value, expectedEntry.value, `value for entry ${i}`);
|
||||
assert.sameValue(actualEntry.source, expectedEntry.source, `source for entry ${i}`);
|
||||
}
|
||||
}
|
||||
|
||||
const date1 = new Date("2019-01-03T00:00:00");
|
||||
const date2 = new Date("2019-01-05T00:00:00");
|
||||
const date3 = new Date("2019-03-04T00:00:00");
|
||||
const date4 = new Date("2020-03-04T00:00:00");
|
||||
|
||||
let dtf = new Intl.DateTimeFormat("en-US");
|
||||
compare(dtf.formatRangeToParts(date1, date1), [
|
||||
{ type: "month", value: "1", source: "shared" },
|
||||
{ type: "literal", value: "/", source: "shared" },
|
||||
{ type: "day", value: "3", source: "shared" },
|
||||
{ type: "literal", value: "/", source: "shared" },
|
||||
{ type: "year", value: "2019", source: "shared" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date1, date2), [
|
||||
{ type: "month", value: "1", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "day", value: "3", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "year", value: "2019", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "1", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "day", value: "5", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "year", value: "2019", source: "endRange" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date1, date3), [
|
||||
{ type: "month", value: "1", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "day", value: "3", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "year", value: "2019", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "3", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "year", value: "2019", source: "endRange" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date1, date4), [
|
||||
{ type: "month", value: "1", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "day", value: "3", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "year", value: "2019", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "3", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "year", value: "2020", source: "endRange" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date2, date3), [
|
||||
{ type: "month", value: "1", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "day", value: "5", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "year", value: "2019", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "3", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "year", value: "2019", source: "endRange" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date2, date4), [
|
||||
{ type: "month", value: "1", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "day", value: "5", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "year", value: "2019", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "3", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "year", value: "2020", source: "endRange" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date3, date4), [
|
||||
{ type: "month", value: "3", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "day", value: "4", source: "startRange" },
|
||||
{ type: "literal", value: "/", source: "startRange" },
|
||||
{ type: "year", value: "2019", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "3", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: "/", source: "endRange" },
|
||||
{ type: "year", value: "2020", source: "endRange" },
|
||||
]);
|
||||
|
||||
dtf = new Intl.DateTimeFormat("en-US", {year: "numeric", month: "short", day: "numeric"});
|
||||
compare(dtf.formatRangeToParts(date1, date1), [
|
||||
{ type: "month", value: "Jan", source: "shared" },
|
||||
{ type: "literal", value: " ", source: "shared" },
|
||||
{ type: "day", value: "3", source: "shared" },
|
||||
{ type: "literal", value: ", ", source: "shared" },
|
||||
{ type: "year", value: "2019", source: "shared" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date1, date2), [
|
||||
{ type: "month", value: "Jan", source: "shared" },
|
||||
{ type: "literal", value: " ", source: "shared" },
|
||||
{ type: "day", value: "3", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "day", value: "5", source: "endRange" },
|
||||
{ type: "literal", value: ", ", source: "shared" },
|
||||
{ type: "year", value: "2019", source: "shared" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date1, date3), [
|
||||
{ type: "month", value: "Jan", source: "startRange" },
|
||||
{ type: "literal", value: " ", source: "startRange" },
|
||||
{ type: "day", value: "3", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "Mar", source: "endRange" },
|
||||
{ type: "literal", value: " ", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: ", ", source: "shared" },
|
||||
{ type: "year", value: "2019", source: "shared" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date1, date4), [
|
||||
{ type: "month", value: "Jan", source: "startRange" },
|
||||
{ type: "literal", value: " ", source: "startRange" },
|
||||
{ type: "day", value: "3", source: "startRange" },
|
||||
{ type: "literal", value: ", ", source: "startRange" },
|
||||
{ type: "year", value: "2019", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "Mar", source: "endRange" },
|
||||
{ type: "literal", value: " ", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: ", ", source: "endRange" },
|
||||
{ type: "year", value: "2020", source: "endRange" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date2, date3), [
|
||||
{ type: "month", value: "Jan", source: "startRange" },
|
||||
{ type: "literal", value: " ", source: "startRange" },
|
||||
{ type: "day", value: "5", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "Mar", source: "endRange" },
|
||||
{ type: "literal", value: " ", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: ", ", source: "shared" },
|
||||
{ type: "year", value: "2019", source: "shared" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date2, date4), [
|
||||
{ type: "month", value: "Jan", source: "startRange" },
|
||||
{ type: "literal", value: " ", source: "startRange" },
|
||||
{ type: "day", value: "5", source: "startRange" },
|
||||
{ type: "literal", value: ", ", source: "startRange" },
|
||||
{ type: "year", value: "2019", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "Mar", source: "endRange" },
|
||||
{ type: "literal", value: " ", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: ", ", source: "endRange" },
|
||||
{ type: "year", value: "2020", source: "endRange" },
|
||||
]);
|
||||
compare(dtf.formatRangeToParts(date3, date4), [
|
||||
{ type: "month", value: "Mar", source: "startRange" },
|
||||
{ type: "literal", value: " ", source: "startRange" },
|
||||
{ type: "day", value: "4", source: "startRange" },
|
||||
{ type: "literal", value: ", ", source: "startRange" },
|
||||
{ type: "year", value: "2019", source: "startRange" },
|
||||
{ type: "literal", value: " \u2013 ", source: "shared" },
|
||||
{ type: "month", value: "Mar", source: "endRange" },
|
||||
{ type: "literal", value: " ", source: "endRange" },
|
||||
{ type: "day", value: "4", source: "endRange" },
|
||||
{ type: "literal", value: ", ", source: "endRange" },
|
||||
{ type: "year", value: "2020", source: "endRange" },
|
||||
]);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2016-2019 Mozilla Corporation, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Property type and descriptor.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof Intl.DateTimeFormat.prototype.formatRangeToParts,
|
||||
'function',
|
||||
'`typeof Intl.DateTimeFormat.prototype.formatRangeToParts` is `function`'
|
||||
);
|
||||
|
||||
verifyProperty(Intl.DateTimeFormat.prototype, 'formatRangeToParts', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2019 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Throws a TypeError if this is not a DateTimeFormat object
|
||||
features: [Intl.DateTimeFormat-formatRange]
|
||||
---*/
|
||||
|
||||
const formatRangeToParts = Intl.DateTimeFormat.prototype.formatRangeToParts;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
formatRangeToParts.call({});
|
||||
}, "{}");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
formatRangeToParts.call(new Date());
|
||||
}, "new Date()");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
formatRangeToParts.call(Intl.DateTimeFormat);
|
||||
}, "Intl.DateTimeFormat");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
formatRangeToParts.call(Intl.DateTimeFormat.prototype);
|
||||
}, "Intl.DateTimeFormat.prototype");
|
Loading…
Reference in New Issue