summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Bargull <andre.bargull@gmail.com>2017-11-09 12:57:16 -0800
committerRick Waldron <waldron.rick@gmail.com>2018-01-25 14:04:44 -0500
commit40a7bd2401184cc85842608e1c90899122c274c0 (patch)
tree9c33db50c8917a2abde47bef3a5cbdda668c362b
parent7c5b5bf75031df8ffde722dfe76540c71d064814 (diff)
downloadqtdeclarative-testsuites-40a7bd2401184cc85842608e1c90899122c274c0.tar.gz
Add test cases for tc39/ecma402#194
-rw-r--r--harness/dateConstants.js3
-rw-r--r--test/intl402/DateTimeFormat/prototype/format/date-constructor-not-called.js36
-rw-r--r--test/intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries.js37
-rw-r--r--test/intl402/DateTimeFormat/prototype/format/time-clip-to-integer.js37
-rw-r--r--test/intl402/DateTimeFormat/prototype/formatToParts/date-constructor-not-called.js36
-rw-r--r--test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries.js37
-rw-r--r--test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer.js41
7 files changed, 227 insertions, 0 deletions
diff --git a/harness/dateConstants.js b/harness/dateConstants.js
index 14213b8b5..f9e9fca08 100644
--- a/harness/dateConstants.js
+++ b/harness/dateConstants.js
@@ -13,3 +13,6 @@ var date_1999_end = 946684799999;
var date_2000_start = 946684800000;
var date_2099_end = 4102444799999;
var date_2100_start = 4102444800000;
+
+var start_of_time = -8.64e15;
+var end_of_time = 8.64e15;
diff --git a/test/intl402/DateTimeFormat/prototype/format/date-constructor-not-called.js b/test/intl402/DateTimeFormat/prototype/format/date-constructor-not-called.js
new file mode 100644
index 000000000..1b0adf52c
--- /dev/null
+++ b/test/intl402/DateTimeFormat/prototype/format/date-constructor-not-called.js
@@ -0,0 +1,36 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-partitiondatetimepattern
+description: |
+ The Date constructor is not called to convert the input value.
+info: >
+ 12.1.5 DateTime Format Functions
+
+ ...
+ 3. If date is not provided or is undefined, then
+ ...
+ 4. Else,
+ a. Let x be ? ToNumber(date).
+ 5. Return FormatDateTime(dtf, x).
+
+ 12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
+
+ 1. Let x be TimeClip(x).
+ 2. If x is NaN, throw a RangeError exception.
+ 3. ...
+---*/
+
+var dtf = new Intl.DateTimeFormat();
+
+var dateTimeString = "2017-11-10T14:09:00.000Z";
+
+// |dateTimeString| is valid ISO-8601 style date/time string.
+assert.notSameValue(new Date(dateTimeString), NaN);
+
+// Ensure string input values are not converted to time values by calling the
+// Date constructor.
+assert.throws(RangeError, function() {
+ dtf.format(dateTimeString);
+});
diff --git a/test/intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries.js b/test/intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries.js
new file mode 100644
index 000000000..b8af0eb5d
--- /dev/null
+++ b/test/intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries.js
@@ -0,0 +1,37 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-partitiondatetimepattern
+description: |
+ TimeClip is applied when calling Intl.DateTimeFormat.prototype.format.
+info: >
+ 12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
+
+ 1. Let x be TimeClip(x).
+ 2. If x is NaN, throw a RangeError exception.
+ 3. ...
+
+ 20.3.1.15 TimeClip ( time )
+ ...
+ 2. If abs(time) > 8.64 × 10^15, return NaN.
+ ...
+
+includes: [dateConstants.js]
+---*/
+
+var dtf = new Intl.DateTimeFormat();
+
+// Test values near the start of the ECMAScript time range.
+assert.throws(RangeError, function() {
+ dtf.format(start_of_time - 1);
+});
+assert.sameValue(typeof dtf.format(start_of_time), "string");
+assert.sameValue(typeof dtf.format(start_of_time + 1), "string");
+
+// Test values near the end of the ECMAScript time range.
+assert.sameValue(typeof dtf.format(end_of_time - 1), "string");
+assert.sameValue(typeof dtf.format(end_of_time), "string");
+assert.throws(RangeError, function() {
+ dtf.format(end_of_time + 1);
+});
diff --git a/test/intl402/DateTimeFormat/prototype/format/time-clip-to-integer.js b/test/intl402/DateTimeFormat/prototype/format/time-clip-to-integer.js
new file mode 100644
index 000000000..243317606
--- /dev/null
+++ b/test/intl402/DateTimeFormat/prototype/format/time-clip-to-integer.js
@@ -0,0 +1,37 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-partitiondatetimepattern
+description: |
+ TimeClip applies ToInteger on its input value.
+info: >
+ 12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
+
+ 1. Let x be TimeClip(x).
+ 2. ...
+
+ 20.3.1.15 TimeClip ( time )
+ ...
+ 3. Let clippedTime be ! ToInteger(time).
+ 4. If clippedTime is -0, set clippedTime to +0.
+ 5. Return clippedTime.
+---*/
+
+// Switch to a time format instead of using DateTimeFormat's default date-only format.
+var dtf = new Intl.DateTimeFormat(undefined, {
+ hour: "numeric", minute: "numeric", second: "numeric"
+});
+
+var expected = dtf.format(0);
+
+assert.sameValue(dtf.format(-0.9), expected, "format(-0.9)");
+assert.sameValue(dtf.format(-0.5), expected, "format(-0.5)");
+assert.sameValue(dtf.format(-0.1), expected, "format(-0.1)");
+assert.sameValue(dtf.format(-Number.MIN_VALUE), expected, "format(-Number.MIN_VALUE)");
+assert.sameValue(dtf.format(-0), expected, "format(-0)");
+assert.sameValue(dtf.format(+0), expected, "format(+0)");
+assert.sameValue(dtf.format(Number.MIN_VALUE), expected, "format(Number.MIN_VALUE)");
+assert.sameValue(dtf.format(0.1), expected, "format(0.1)");
+assert.sameValue(dtf.format(0.5), expected, "format(0.5)");
+assert.sameValue(dtf.format(0.9), expected, "format(0.9)");
diff --git a/test/intl402/DateTimeFormat/prototype/formatToParts/date-constructor-not-called.js b/test/intl402/DateTimeFormat/prototype/formatToParts/date-constructor-not-called.js
new file mode 100644
index 000000000..66234557f
--- /dev/null
+++ b/test/intl402/DateTimeFormat/prototype/formatToParts/date-constructor-not-called.js
@@ -0,0 +1,36 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-partitiondatetimepattern
+description: |
+ The Date constructor is not called to convert the input value.
+info: >
+ 12.4.4 Intl.DateTimeFormat.prototype.formatToParts ( date )
+
+ ...
+ 4. If date is undefined, then
+ ...
+ 5. Else,
+ a. Let x be ? ToNumber(date).
+ 5. Return ? FormatDateTimeToParts(dtf, x).
+
+ 12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
+
+ 1. Let x be TimeClip(x).
+ 2. If x is NaN, throw a RangeError exception.
+ 3. ...
+---*/
+
+var dtf = new Intl.DateTimeFormat();
+
+var dateTimeString = "2017-11-10T14:09:00.000Z";
+
+// |dateTimeString| is valid ISO-8601 style date/time string.
+assert.notSameValue(new Date(dateTimeString), NaN);
+
+// Ensure string input values are not converted to time values by calling the
+// Date constructor.
+assert.throws(RangeError, function() {
+ dtf.formatToParts(dateTimeString);
+});
diff --git a/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries.js b/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries.js
new file mode 100644
index 000000000..850154178
--- /dev/null
+++ b/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries.js
@@ -0,0 +1,37 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-partitiondatetimepattern
+description: |
+ TimeClip is applied when calling Intl.DateTimeFormat.prototype.formatToParts.
+info: >
+ 12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
+
+ 1. Let x be TimeClip(x).
+ 2. If x is NaN, throw a RangeError exception.
+ 3. ...
+
+ 20.3.1.15 TimeClip ( time )
+ ...
+ 2. If abs(time) > 8.64 × 10^15, return NaN.
+ ...
+
+includes: [dateConstants.js]
+---*/
+
+var dtf = new Intl.DateTimeFormat();
+
+// Test values near the start of the ECMAScript time range.
+assert.throws(RangeError, function() {
+ dtf.formatToParts(start_of_time - 1);
+});
+assert.sameValue(typeof dtf.formatToParts(start_of_time), "object");
+assert.sameValue(typeof dtf.formatToParts(start_of_time + 1), "object");
+
+// Test values near the end of the ECMAScript time range.
+assert.sameValue(typeof dtf.formatToParts(end_of_time - 1), "object");
+assert.sameValue(typeof dtf.formatToParts(end_of_time), "object");
+assert.throws(RangeError, function() {
+ dtf.formatToParts(end_of_time + 1);
+});
diff --git a/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer.js b/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer.js
new file mode 100644
index 000000000..0b95ef68e
--- /dev/null
+++ b/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer.js
@@ -0,0 +1,41 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-partitiondatetimepattern
+description: |
+ TimeClip applies ToInteger on its input value.
+info: >
+ 12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
+
+ 1. Let x be TimeClip(x).
+ 2. ...
+
+ 20.3.1.15 TimeClip ( time )
+ ...
+ 3. Let clippedTime be ! ToInteger(time).
+ 4. If clippedTime is -0, set clippedTime to +0.
+ 5. Return clippedTime.
+---*/
+
+// Switch to a time format instead of using DateTimeFormat's default date-only format.
+var dtf = new Intl.DateTimeFormat(undefined, {
+ hour: "numeric", minute: "numeric", second: "numeric"
+});
+
+function formatAsString(dtf, time) {
+ return dtf.formatToParts(time).map(part => part.value).join("");
+}
+
+var expected = formatAsString(dtf, 0);
+
+assert.sameValue(formatAsString(dtf, -0.9), expected, "formatToParts(-0.9)");
+assert.sameValue(formatAsString(dtf, -0.5), expected, "formatToParts(-0.5)");
+assert.sameValue(formatAsString(dtf, -0.1), expected, "formatToParts(-0.1)");
+assert.sameValue(formatAsString(dtf, -Number.MIN_VALUE), expected, "formatToParts(-Number.MIN_VALUE)");
+assert.sameValue(formatAsString(dtf, -0), expected, "formatToParts(-0)");
+assert.sameValue(formatAsString(dtf, +0), expected, "formatToParts(+0)");
+assert.sameValue(formatAsString(dtf, Number.MIN_VALUE), expected, "formatToParts(Number.MIN_VALUE)");
+assert.sameValue(formatAsString(dtf, 0.1), expected, "formatToParts(0.1)");
+assert.sameValue(formatAsString(dtf, 0.5), expected, "formatToParts(0.5)");
+assert.sameValue(formatAsString(dtf, 0.9), expected, "formatToParts(0.9)");