From bd685e552ca06be2a4ff7dcc9109de0b3a5470da Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 21 Mar 2017 18:26:36 +0100 Subject: [PATCH 1/3] Tests for "Invalid Date" in more cases Following the proposed specification in https://github.com/tc39/ecma262/pull/848 --- .../Date/prototype/toDateString/invalid-date.js | 17 +++++++++++++++++ .../Date/prototype/toTimeString/invalid-date.js | 17 +++++++++++++++++ .../Date/prototype/toUTCString/invalid-date.js | 16 ++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 test/built-ins/Date/prototype/toDateString/invalid-date.js create mode 100644 test/built-ins/Date/prototype/toTimeString/invalid-date.js create mode 100644 test/built-ins/Date/prototype/toUTCString/invalid-date.js diff --git a/test/built-ins/Date/prototype/toDateString/invalid-date.js b/test/built-ins/Date/prototype/toDateString/invalid-date.js new file mode 100644 index 00000000000..30a01cda0c0 --- /dev/null +++ b/test/built-ins/Date/prototype/toDateString/invalid-date.js @@ -0,0 +1,17 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.todatestring +description: Invalid Dates are rendered as "Invalid Date" +info: > + Date.prototype.toDateString ( ) + + ... + 3. If tv is NaN, return "Invalid Date". + ... +---*/ + +assert.sameValue(new Date(NaN).toDateString(), "Invalid Date"); + + diff --git a/test/built-ins/Date/prototype/toTimeString/invalid-date.js b/test/built-ins/Date/prototype/toTimeString/invalid-date.js new file mode 100644 index 00000000000..426dd9cb9df --- /dev/null +++ b/test/built-ins/Date/prototype/toTimeString/invalid-date.js @@ -0,0 +1,17 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totimestring +description: Invalid Dates are rendered as "Invalid Date" +info: > + Date.prototype.toTimeString ( ) + + ... + 3. If tv is NaN, return "Invalid Date". + ... +---*/ + +assert.sameValue(new Date(NaN).toTimeString(), "Invalid Date"); + + diff --git a/test/built-ins/Date/prototype/toUTCString/invalid-date.js b/test/built-ins/Date/prototype/toUTCString/invalid-date.js new file mode 100644 index 00000000000..774fd69d727 --- /dev/null +++ b/test/built-ins/Date/prototype/toUTCString/invalid-date.js @@ -0,0 +1,16 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.toutcstring +description: Invalid Dates are rendered as "Invalid Date" +info: > + Date.prototype.toUTCString ( ) + + ... + 3. If tv is NaN, return "Invalid Date". + ... +---*/ + +assert.sameValue(new Date(NaN).toUTCString(), "Invalid Date"); + From 99fa2a6c9e5e3f5591ec00154a5251e15ebb3a97 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 23 Mar 2017 12:19:37 +0100 Subject: [PATCH 2/3] Add tests for the formats of toString functions --- .../Date/prototype/toDateString/format.js | 19 +++++++++++ .../Date/prototype/toString/format.js | 20 ++++++++++++ .../Date/prototype/toTimeString/format.js | 15 +++++++++ .../Date/prototype/toUTCString/day-names.js | 22 +++++++++++++ .../Date/prototype/toUTCString/format.js | 18 +++++++++++ .../Date/prototype/toUTCString/month-names.js | 32 +++++++++++++++++++ 6 files changed, 126 insertions(+) create mode 100644 test/built-ins/Date/prototype/toDateString/format.js create mode 100644 test/built-ins/Date/prototype/toString/format.js create mode 100644 test/built-ins/Date/prototype/toTimeString/format.js create mode 100644 test/built-ins/Date/prototype/toUTCString/day-names.js create mode 100644 test/built-ins/Date/prototype/toUTCString/format.js create mode 100644 test/built-ins/Date/prototype/toUTCString/month-names.js diff --git a/test/built-ins/Date/prototype/toDateString/format.js b/test/built-ins/Date/prototype/toDateString/format.js new file mode 100644 index 00000000000..540ff38855c --- /dev/null +++ b/test/built-ins/Date/prototype/toDateString/format.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.todatestring +description: Test the format of the date from toDateString +info: > + Date.prototype.toDateString ( ) + + 5. Return DateString(_t_). +---*/ + +let dateRegExp = /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2} [0-9]{4}$/ +let match = dateRegExp.exec(new Date().toDateString()); +assert.notSameValue(null, match); + +// Years are padded to the left with zeroes +match = stringRegExp.exec(new Date('0020-01-01T00:00:00Z').toDateString()); +assert.notSameValue(null, match); diff --git a/test/built-ins/Date/prototype/toString/format.js b/test/built-ins/Date/prototype/toString/format.js new file mode 100644 index 00000000000..e414cf65e25 --- /dev/null +++ b/test/built-ins/Date/prototype/toString/format.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.tostring +description: Test the format of the time from toString +info: > + Runtime Semantics: ToDateString( _tv_ ) + + 4. Return the String value formed by concatenating DateString(_t_), `" "`, TimeString(_t_), and TimeZoneString(_tv_). + +---*/ + +let stringRegExp = /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2} [0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} GMT[+-][0-9]{4}( \(.+\))?$/ +let match = stringRegExp.exec(new Date().toString()); +assert.notSameValue(null, match); + +// Years are padded to the left with zeroes +match = stringRegExp.exec(new Date('0020-01-01T00:00:00Z').toString()); +assert.notSameValue(null, match); diff --git a/test/built-ins/Date/prototype/toTimeString/format.js b/test/built-ins/Date/prototype/toTimeString/format.js new file mode 100644 index 00000000000..3a71efdcfbe --- /dev/null +++ b/test/built-ins/Date/prototype/toTimeString/format.js @@ -0,0 +1,15 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totimestring +description: Test the format of the time from toTimeString +info: > + Date.prototype.toTimeString ( ) + + 5. Return the String value formed by concatenating TimeString(_t_) and TimeZoneString(_tv_). +---*/ + +let timeRegExp = /^[0-9]{2}:[0-9]{2}:[0-9]{2} GMT[+-][0-9]{4}( \(.+\))?$/ +let match = timeRegExp.exec(new Date().toTimeString()); +assert.notSameValue(null, match); diff --git a/test/built-ins/Date/prototype/toUTCString/day-names.js b/test/built-ins/Date/prototype/toUTCString/day-names.js new file mode 100644 index 00000000000..ce9cdfaabe3 --- /dev/null +++ b/test/built-ins/Date/prototype/toUTCString/day-names.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-todatestring-day-names +description: Test the names of days +---*/ + +assert.sameValue("Sun, 23 Mar 2014 00:00:00 GMT", + (new Date("2014-03-23T00:00:00Z")).toUTCString()); +assert.sameValue("Mon, 24 Mar 2014 00:00:00 GMT", + (new Date("2014-03-24T00:00:00Z")).toUTCString()); +assert.sameValue("Tue, 25 Mar 2014 00:00:00 GMT", + (new Date("2014-03-25T00:00:00Z")).toUTCString()); +assert.sameValue("Wed, 26 Mar 2014 00:00:00 GMT", + (new Date("2014-03-26T00:00:00Z")).toUTCString()); +assert.sameValue("Thu, 27 Mar 2014 00:00:00 GMT", + (new Date("2014-03-27T00:00:00Z")).toUTCString()); +assert.sameValue("Fri, 28 Mar 2014 00:00:00 GMT", + (new Date("2014-03-28T00:00:00Z")).toUTCString()); +assert.sameValue("Sat, 29 Mar 2014 00:00:00 GMT", + (new Date("2014-03-29T00:00:00Z")).toUTCString()); diff --git a/test/built-ins/Date/prototype/toUTCString/format.js b/test/built-ins/Date/prototype/toUTCString/format.js new file mode 100644 index 00000000000..3e0ba9ceaa7 --- /dev/null +++ b/test/built-ins/Date/prototype/toUTCString/format.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.toutcstring +description: Test the format of the date from toUTCString +info: > + Date.prototype.toUTCString ( ) + + 4. Return the String value formed by concatenating DateString(_tv_, `", "`), `" "`, and TimeString(_tv_). +---*/ + +let utcRegExp = /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat), [0-9]{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} GMT$/ +let match = utcRegExp.exec(new Date().toUTCString()); +assert.notSameValue(null, match); + +// Years are padded to the left with zeroes +assert.sameValue('Wed, 01 Jan 0020 00:00:00 GMT', new Date('0020-01-01T00:00:00Z').toUTCString()); diff --git a/test/built-ins/Date/prototype/toUTCString/month-names.js b/test/built-ins/Date/prototype/toUTCString/month-names.js new file mode 100644 index 00000000000..a50dc18b366 --- /dev/null +++ b/test/built-ins/Date/prototype/toUTCString/month-names.js @@ -0,0 +1,32 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-todatestring-month-names +description: Test the names of months +---*/ + +assert.sameValue("Wed, 01 Jan 2014 00:00:00 GMT", + (new Date("2014-01-01T00:00:00Z")).toUTCString()); +assert.sameValue("Sat, 01 Feb 2014 00:00:00 GMT", + (new Date("2014-02-01T00:00:00Z")).toUTCString()); +assert.sameValue("Sat, 01 Mar 2014 00:00:00 GMT", + (new Date("2014-03-01T00:00:00Z")).toUTCString()); +assert.sameValue("Tue, 01 Apr 2014 00:00:00 GMT", + (new Date("2014-04-01T00:00:00Z")).toUTCString()); +assert.sameValue("Thu, 01 May 2014 00:00:00 GMT", + (new Date("2014-05-01T00:00:00Z")).toUTCString()); +assert.sameValue("Sun, 01 Jun 2014 00:00:00 GMT", + (new Date("2014-06-01T00:00:00Z")).toUTCString()); +assert.sameValue("Tue, 01 Jul 2014 00:00:00 GMT", + (new Date("2014-07-01T00:00:00Z")).toUTCString()); +assert.sameValue("Fri, 01 Aug 2014 00:00:00 GMT", + (new Date("2014-08-01T00:00:00Z")).toUTCString()); +assert.sameValue("Mon, 01 Sep 2014 00:00:00 GMT", + (new Date("2014-09-01T00:00:00Z")).toUTCString()); +assert.sameValue("Wed, 01 Oct 2014 00:00:00 GMT", + (new Date("2014-10-01T00:00:00Z")).toUTCString()); +assert.sameValue("Sat, 01 Nov 2014 00:00:00 GMT", + (new Date("2014-11-01T00:00:00Z")).toUTCString()); +assert.sameValue("Mon, 01 Dec 2014 00:00:00 GMT", + (new Date("2014-12-01T00:00:00Z")).toUTCString()); From 2f3787936b2024045a764fb61bf0f92cfa66cbe3 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 15 Jun 2017 06:25:17 +0200 Subject: [PATCH 3/3] Fix typo from review --- test/built-ins/Date/prototype/toDateString/format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Date/prototype/toDateString/format.js b/test/built-ins/Date/prototype/toDateString/format.js index 540ff38855c..e14135453ac 100644 --- a/test/built-ins/Date/prototype/toDateString/format.js +++ b/test/built-ins/Date/prototype/toDateString/format.js @@ -15,5 +15,5 @@ let match = dateRegExp.exec(new Date().toDateString()); assert.notSameValue(null, match); // Years are padded to the left with zeroes -match = stringRegExp.exec(new Date('0020-01-01T00:00:00Z').toDateString()); +match = dateRegExp.exec(new Date('0020-01-01T00:00:00Z').toDateString()); assert.notSameValue(null, match);