From 4b25f6fae88203fa73c5a9aa6fdb0e47a8049770 Mon Sep 17 00:00:00 2001 From: Frank Yung-Fong Tang <41213225+FrankYFTang@users.noreply.github.com> Date: Wed, 1 May 2019 12:20:29 -0700 Subject: [PATCH] Add initial tests for Intl.DateTimeFormat formatRange and formatRangeToParts (#2134) --- features.txt | 4 ++ .../formatRange/date-is-infinity-throws.js | 70 +++++++++++++++++++ .../formatRange/date-is-nan-throws.js | 47 +++++++++++++ .../formatRange/date-undefined-throws.js | 42 +++++++++++ .../date-x-greater-than-y-throws.js | 32 +++++++++ .../prototype/formatRange/length.js | 17 +++++ .../prototype/formatRange/name.js | 15 ++++ .../formatRange/this-is-not-object-throws.js | 47 +++++++++++++ .../date-is-infinity-throws.js | 69 ++++++++++++++++++ .../formatRangeToParts/date-is-nan-throws.js | 47 +++++++++++++ .../date-undefined-throws.js | 41 +++++++++++ .../date-x-greater-than-y-throws.js | 31 ++++++++ .../prototype/formatRangeToParts/length.js | 17 +++++ .../prototype/formatRangeToParts/name.js | 15 ++++ .../this-is-not-object-throws.js | 47 +++++++++++++ 15 files changed, 541 insertions(+) create mode 100644 test/intl402/DateTimeFormat/prototype/formatRange/date-is-infinity-throws.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRange/date-is-nan-throws.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRange/date-undefined-throws.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRange/date-x-greater-than-y-throws.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRange/length.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRange/name.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRange/this-is-not-object-throws.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-is-infinity-throws.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-is-nan-throws.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-undefined-throws.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-x-greater-than-y-throws.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRangeToParts/length.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRangeToParts/name.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRangeToParts/this-is-not-object-throws.js diff --git a/features.txt b/features.txt index ca410bae32..81dc1c8712 100644 --- a/features.txt +++ b/features.txt @@ -96,6 +96,10 @@ Intl.NumberFormat-unified # https://github.com/tc39/proposal-intl-datetime-style Intl.DateTimeFormat-datetimestyle +# Intl.DateTimeFormat: formatRange and formatRangeToParts functions +# https://github.com/tc39/proposal-intl-DateTimeFormat-formatRange +Intl.DateTimeFormat-formatRange + # Global # https://github.com/tc39/proposal-global globalThis diff --git a/test/intl402/DateTimeFormat/prototype/formatRange/date-is-infinity-throws.js b/test/intl402/DateTimeFormat/prototype/formatRange/date-is-infinity-throws.js new file mode 100644 index 0000000000..54e5b96b4b --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/date-is-infinity-throws.js @@ -0,0 +1,70 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a RangeError if date arg is cast to an Infinity value +info: + Intl.DateTimeFormat.prototype.formatRange ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. + 4. If startDate is undefined or endDate is undefined, throw a RangeError exception. + 5. Let x be ? ToNumber(startDate). + 6. Let y be ? ToNumber(endDate). + 7. If x is greater than y, throw a RangeError exception. + 8. Return ? FormatDateTimeRange(dtf, x, y). + + FormatDateTimeRange ( dateTimeFormat, x, y ) + + 1. Let parts be ? PartitionDateTimeRangePattern(dateTimeFormat, 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. + + TimeClip ( time ) + 1. If time is not finite, return NaN. + +features: [Intl.DateTimeFormat-formatRange] +---*/ + +var dtf = new Intl.DateTimeFormat(); + +var date = new Date(); + +assert.throws(RangeError, function() { + dtf.formatRange(Infinity, date); +}, "+Infinity/date"); + +assert.throws(RangeError, function() { + dtf.formatRange(-Infinity, date); +}, "-Infinity/date"); + +assert.throws(RangeError, function() { + dtf.formatRange(date, Infinity); +}, "date/+Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRange(date, -Infinity); +}, "date/-Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRange(Infinity, Infinity); +}, "+Infinity/+Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRange(-Infinity, -Infinity); +}, "-Infinity/-Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRange(Infinity, -Infinity); +}, "+Infinity/-Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRange(-Infinity, Infinity); +}, "-Infinity/+Infinity"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRange/date-is-nan-throws.js b/test/intl402/DateTimeFormat/prototype/formatRange/date-is-nan-throws.js new file mode 100644 index 0000000000..9c20d6d456 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/date-is-nan-throws.js @@ -0,0 +1,47 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a RangeError if date arg is cast to NaN +info: + Intl.DateTimeFormat.prototype.formatRange ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. + 4. If startDate is undefined or endDate is undefined, throw a RangeError exception. + 5. Let x be ? ToNumber(startDate). + 6. Let y be ? ToNumber(endDate). + 7. If x is greater than y, throw a RangeError exception. + 8. Return ? FormatDateTimeRange(dtf, x, y). + + FormatDateTimeRange ( dateTimeFormat, x, y ) + + 1. Let parts be ? PartitionDateTimeRangePattern(dateTimeFormat, 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] +---*/ + +var dtf = new Intl.DateTimeFormat(); + +var date = new Date(); + +assert.throws(RangeError, function() { + dtf.formatRange(NaN, date); +}, "NaN/date"); + +assert.throws(RangeError, function() { + dtf.formatRange(date, NaN); +}, "date/NaN"); + +assert.throws(RangeError, function() { + dtf.formatRange(NaN, NaN); +}, "NaN/NaN"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRange/date-undefined-throws.js b/test/intl402/DateTimeFormat/prototype/formatRange/date-undefined-throws.js new file mode 100644 index 0000000000..dade376c43 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/date-undefined-throws.js @@ -0,0 +1,42 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a RangeError if startDate or endDate is undefined. +info: + Intl.DateTimeFormat.prototype.formatRange ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. + 4. If startDate is undefined or endDate is undefined, throw a RangeError exception. + 5. Let x be ? ToNumber(startDate). + 6. Let y be ? ToNumber(endDate). + +features: [Intl.DateTimeFormat-formatRange] +---*/ + +var dtf = new Intl.DateTimeFormat(); + +assert.throws(RangeError, function() { + dtf.formatRange(); // Not possible to poison this one +}, "no args"); + +var poison = { valueOf() { throw new Test262Error(); } }; + +assert.throws(RangeError, function() { + dtf.formatRange(undefined, poison); +}, "date/undefined"); + +assert.throws(RangeError, function() { + dtf.formatRange(poison, undefined); +}, "undefined/date"); + +assert.throws(RangeError, function() { + dtf.formatRange(poison); +}, "only one arg"); + +assert.throws(RangeError, function() { + dtf.formatRange(undefined, undefined); +}, "undefined/undefined"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRange/date-x-greater-than-y-throws.js b/test/intl402/DateTimeFormat/prototype/formatRange/date-x-greater-than-y-throws.js new file mode 100644 index 0000000000..33729fe9a8 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/date-x-greater-than-y-throws.js @@ -0,0 +1,32 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a RangeError if date x is greater than y. +info: + Intl.DateTimeFormat.prototype.formatRange ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. + 5. Let x be ? ToNumber(startDate). + 6. Let y be ? ToNumber(endDate). + 7. If x is greater than y, throw a RangeError exception. + +features: [Intl.DateTimeFormat-formatRange] +---*/ + +var dtf = new Intl.DateTimeFormat(); + +var x = new Date(); +var y = new Date(); +x.setDate(y.getDate() + 1); + +assert.throws(RangeError, function() { + dtf.formatRange(x, y); +}, "x > y"); + +assert.sameValue("string", typeof dtf.formatRange(x, x)); +assert.sameValue("string", typeof dtf.formatRange(y, y)); +assert.sameValue("string", typeof dtf.formatRange(y, x)); diff --git a/test/intl402/DateTimeFormat/prototype/formatRange/length.js b/test/intl402/DateTimeFormat/prototype/formatRange/length.js new file mode 100644 index 0000000000..0192ccfde3 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/length.js @@ -0,0 +1,17 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Intl.DateTimeFormat.prototype.formatRange.length. +includes: [propertyHelper.js] +features: [Intl.DateTimeFormat-formatRange] +---*/ + +assert.sameValue(Intl.DateTimeFormat.prototype.formatRange.length, 2); + +verifyProperty(Intl.DateTimeFormat.prototype.formatRange, 'length', { + value: 2, + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/intl402/DateTimeFormat/prototype/formatRange/name.js b/test/intl402/DateTimeFormat/prototype/formatRange/name.js new file mode 100644 index 0000000000..e842172a5e --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/name.js @@ -0,0 +1,15 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Intl.DateTimeFormat.prototype.formatRange.name value and descriptor. +includes: [propertyHelper.js] +features: [Intl.DateTimeFormat-formatRange] +---*/ +assert.sameValue(Intl.DateTimeFormat.prototype.formatRange.name, 'formatRange', + 'The value of `Intl.DateTimeFormat.prototype.formatRange.name` is `"formatRange"`' +); + +verifyNotEnumerable(Intl.DateTimeFormat.prototype.formatRange, 'name'); +verifyNotWritable(Intl.DateTimeFormat.prototype.formatRange, 'name'); +verifyConfigurable(Intl.DateTimeFormat.prototype.formatRange, 'name'); diff --git a/test/intl402/DateTimeFormat/prototype/formatRange/this-is-not-object-throws.js b/test/intl402/DateTimeFormat/prototype/formatRange/this-is-not-object-throws.js new file mode 100644 index 0000000000..7ae45cc0bb --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/this-is-not-object-throws.js @@ -0,0 +1,47 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a TypeError if this is not Object. +info: + Intl.DateTimeFormat.prototype.formatRange ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + +features: [Intl.DateTimeFormat-formatRange, Symbol] +---*/ + +let formatRange = Intl.DateTimeFormat.prototype.formatRange; +let d1 = new Date("1997-08-22T00:00"); +let d2 = new Date("1999-06-26T00:00"); + +assert.throws(TypeError, function() { + formatRange.call(undefined, d1, d2); +}, "undefined"); + +assert.throws(TypeError, function() { + formatRange.call(null, d1, d2); +}, "null"); + +assert.throws(TypeError, function() { + formatRange.call(42, d1, d2); +}, "number"); + +assert.throws(TypeError, function() { + formatRange.call("foo", d1, d2); +}, "string"); + +assert.throws(TypeError, function() { + formatRange.call(false, d1, d2); +}, "false"); + +assert.throws(TypeError, function() { + formatRange.call(true, d1, d2); +}, "true"); + +var s = Symbol('3'); +assert.throws(TypeError, function() { + formatRange.call(s, d1, d2); +}, "symbol"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-is-infinity-throws.js b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-is-infinity-throws.js new file mode 100644 index 0000000000..fd394977d4 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-is-infinity-throws.js @@ -0,0 +1,69 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a RangeError if date arg is cast to an Infinity value +info: + Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. + 4. If startDate is undefined or endDate is undefined, throw a RangeError exception. + 5. Let x be ? ToNumber(startDate). + 6. Let y be ? ToNumber(endDate). + 7. If x is greater than y, throw a RangeError exception. + 8. Return ? FormatDateTimeRangeToParts(dtf, x, y). + + FormatDateTimeRangeToParts ( dateTimeFormat, x, y ) + + 1. Let parts be ? PartitionDateTimeRangePattern(dateTimeFormat, 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. + + TimeClip ( time ) + 1. If time is not finite, return NaN. + +features: [Intl.DateTimeFormat-formatRange] +---*/ + +var dtf = new Intl.DateTimeFormat(); + +var date = new Date(); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(Infinity, date); +}, "+Infinity/date"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(-Infinity, date); +}, "-Infinity/date"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(date, Infinity); +}, "date/+Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(date, -Infinity); +}, "date/-Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(Infinity, Infinity); +}, "+Infinity/+Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(-Infinity, -Infinity); +}, "-Infinity/-Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(Infinity, -Infinity); +}, "+Infinity/-Infinity"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(-Infinity, Infinity); +}, "-Infinity/+Infinity"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-is-nan-throws.js b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-is-nan-throws.js new file mode 100644 index 0000000000..c70a2936dd --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-is-nan-throws.js @@ -0,0 +1,47 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a RangeError if date arg is cast to Nan +info: + Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. + 4. If startDate is undefined or endDate is undefined, throw a RangeError exception. + 5. Let x be ? ToNumber(startDate). + 6. Let y be ? ToNumber(endDate). + 7. If x is greater than y, throw a RangeError exception. + 8. Return ? FormatDateTimeRangeToParts(dtf, x, y). + + FormatDateTimeRangeToParts ( dateTimeFormat, x, y ) + + 1. Let parts be ? PartitionDateTimeRangePattern(dateTimeFormat, 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] +---*/ + +var dtf = new Intl.DateTimeFormat(); + +var date = new Date(); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(NaN, date); +}, "NaN/date"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(date, NaN); +}, "date/NaN"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(NaN, NaN); +}, "NaN/NaN"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-undefined-throws.js b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-undefined-throws.js new file mode 100644 index 0000000000..e5aff72519 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-undefined-throws.js @@ -0,0 +1,41 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a RangeError if startDate or endDate are undefined. +info: + Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. + 4. If startDate is undefined or endDate is undefined, throw a RangeError exception. + 5. Let x be ? ToNumber(startDate). + 6. Let y be ? ToNumber(endDate). + +features: [Intl.DateTimeFormat-formatRange] +---*/ +var dtf = new Intl.DateTimeFormat(); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(); // Not possible to poison this one +}, "no args"); + +var poison = { valueOf() { throw new Test262Error(); } }; + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(undefined, poison); +}, "date/undefined"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(poison, undefined); +}, "undefined/date"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(poison); +}, "only one arg"); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(undefined, undefined); +}, "undefined/undefined"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-x-greater-than-y-throws.js b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-x-greater-than-y-throws.js new file mode 100644 index 0000000000..73cd963b71 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/date-x-greater-than-y-throws.js @@ -0,0 +1,31 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a RangeError if date x is greater than y. +info: + Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. + 5. Let x be ? ToNumber(startDate). + 6. Let y be ? ToNumber(endDate). + 7. If x is greater than y, throw a RangeError exception. + +features: [Intl.DateTimeFormat-formatRange] +---*/ + +var dtf = new Intl.DateTimeFormat(); + +var x = new Date(); +var y = new Date(); +x.setDate(y.getDate() + 1); + +assert.throws(RangeError, function() { + dtf.formatRangeToParts(x, y); +}, "x > y"); +assert.sameValue("object", typeof dtf.formatRangeToParts(x, x)); +assert.sameValue("object", typeof dtf.formatRangeToParts(y, y)); +assert.sameValue("object", typeof dtf.formatRangeToParts(y, x)); diff --git a/test/intl402/DateTimeFormat/prototype/formatRangeToParts/length.js b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/length.js new file mode 100644 index 0000000000..541b9bdea4 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/length.js @@ -0,0 +1,17 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Intl.DateTimeFormat.prototype.formatRangeToParts.length. +includes: [propertyHelper.js] +features: [Intl.DateTimeFormat-formatRange] +---*/ + +assert.sameValue(Intl.DateTimeFormat.prototype.formatRangeToParts.length, 2); + +verifyProperty(Intl.DateTimeFormat.prototype.formatRangeToParts, 'length', { + value: 2, + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/intl402/DateTimeFormat/prototype/formatRangeToParts/name.js b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/name.js new file mode 100644 index 0000000000..142f4a6fa8 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/name.js @@ -0,0 +1,15 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Intl.DateTimeFormat.prototype.formatRangeToParts.name value and descriptor. +includes: [propertyHelper.js] +features: [Intl.DateTimeFormat-formatRange] +---*/ +assert.sameValue(Intl.DateTimeFormat.prototype.formatRangeToParts.name, 'formatRangeToParts', + 'The value of `Intl.DateTimeFormat.prototype.formatRangeToParts.name` is `"formatRangeToParts"`' +); + +verifyNotEnumerable(Intl.DateTimeFormat.prototype.formatRangeToParts, 'name'); +verifyNotWritable(Intl.DateTimeFormat.prototype.formatRangeToParts, 'name'); +verifyConfigurable(Intl.DateTimeFormat.prototype.formatRangeToParts, 'name'); diff --git a/test/intl402/DateTimeFormat/prototype/formatRangeToParts/this-is-not-object-throws.js b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/this-is-not-object-throws.js new file mode 100644 index 0000000000..9b1881d22c --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/this-is-not-object-throws.js @@ -0,0 +1,47 @@ +// Copyright 2019 Google, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: + Throws a TypeError if this is not Object. +info: + Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate , endDate ) + + 1. Let dtf be this value. + 2. If Type(dtf) is not Object, throw a TypeError exception. + +features: [Intl.DateTimeFormat-formatRange, Symbol] +---*/ + +let formatRangeToParts = Intl.DateTimeFormat.prototype.formatRangeToParts; +let d1 = new Date("1997-08-22T00:00"); +let d2 = new Date("1999-06-26T00:00"); + +assert.throws(TypeError, function() { + formatRangeToParts.call(undefined, d1, d2); +}, "undefined"); + +assert.throws(TypeError, function() { + formatRangeToParts.call(null, d1, d2); +}, "null"); + +assert.throws(TypeError, function() { + formatRangeToParts.call(42, d1, d2); +}, "number"); + +assert.throws(TypeError, function() { + formatRangeToParts.call("foo", d1, d2); +}, "string"); + +assert.throws(TypeError, function() { + formatRangeToParts.call(false, d1, d2); +}, "false"); + +assert.throws(TypeError, function() { + formatRangeToParts.call(true, d1, d2); +}, "true"); + +var s = Symbol('3'); +assert.throws(TypeError, function() { + formatRangeToParts.call(s, d1, d2); +}, "symbol");