Skip to content
Snippets Groups Projects
Commit acebbcae authored by Mike Pennisi's avatar Mike Pennisi
Browse files

Add tests for Date.prototype methods

parent 8918e860
Branches
No related tags found
No related merge requests found
Showing
with 633 additions and 0 deletions
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getdate
es6id: 20.3.4.2
description: Return value for invalid date
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
---*/
assert.sameValue(new Date(NaN).getDate(), NaN);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getdate
es6id: 20.3.4.2
description: >
Behavior when "this" value is an Object without a [[DateValue]] internal slot
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
---*/
var getDate = Date.prototype.getDate;
var args = (function() { return arguments; }());
assert.sameValue(typeof getDate, 'function');
assert.throws(TypeError, function() {
getDate.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
getDate.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
getDate.call(args);
}, 'arguments exotic object');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getdate
es6id: 20.3.4.2
description: Behavior when "this" value is not an Object
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
features: [Symbol]
---*/
var getDate = Date.prototype.getDate;
var symbol = Symbol();
assert.sameValue(typeof getDate, 'function');
assert.throws(TypeError, function() {
getDate.call(0);
}, 'number');
assert.throws(TypeError, function() {
getDate.call(true);
}, 'boolean');
assert.throws(TypeError, function() {
getDate.call(null);
}, 'null');
assert.throws(TypeError, function() {
getDate.call(undefined);
}, 'undefined');
assert.throws(TypeError, function() {
getDate.call('');
}, 'string');
assert.throws(TypeError, function() {
getDate.call(symbol);
}, 'symbol');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getdate
es6id: 20.3.4.2
description: Return value for valid dates
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
3. Return DateFromTime(LocalTime(t)).
---*/
assert.sameValue(new Date(2016, 6, 6).getDate(), 6, 'first millisecond');
assert.sameValue(
new Date(2016, 6, 6, 0, 0, 0, -1).getDate(), 5, 'previous millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 23, 59, 59, 999).getDate(), 6, 'final millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 23, 59, 59, 1000).getDate(), 7, 'subsequent millisecond'
);
assert.sameValue(
new Date(2016, 1, 29).getDate(), 29, 'first millisecond (month boundary)'
);
assert.sameValue(
new Date(2016, 1, 29, 0, 0, 0, -1).getDate(),
28,
'previous millisecond (month boundary)'
);
assert.sameValue(
new Date(2016, 1, 29, 23, 59, 59, 999).getDate(),
29,
'final millisecond (month boundary)'
);
assert.sameValue(
new Date(2016, 1, 29, 23, 59, 59, 1000).getDate(),
1,
'subsequent millisecond (month boundary)'
);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getday
es6id: 20.3.4.3
description: Return value for invalid date
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
---*/
assert.sameValue(new Date(NaN).getDay(), NaN);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getday
es6id: 20.3.4.3
description: >
Behavior when "this" value is an Object without a [[DateValue]] internal slot
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
---*/
var getDay = Date.prototype.getDay;
var args = (function() { return arguments; }());
assert.sameValue(typeof getDay, 'function');
assert.throws(TypeError, function() {
getDay.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
getDay.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
getDay.call(args);
}, 'arguments exotic object');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getday
es6id: 20.3.4.3
description: Behavior when "this" value is not an Object
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
features: [Symbol]
---*/
var getDay = Date.prototype.getDay;
var symbol = Symbol();
assert.sameValue(typeof getDay, 'function');
assert.throws(TypeError, function() {
getDay.call(0);
}, 'number');
assert.throws(TypeError, function() {
getDay.call(true);
}, 'boolean');
assert.throws(TypeError, function() {
getDay.call(null);
}, 'null');
assert.throws(TypeError, function() {
getDay.call(undefined);
}, 'undefined');
assert.throws(TypeError, function() {
getDay.call('');
}, 'string');
assert.throws(TypeError, function() {
getDay.call(symbol);
}, 'symbol');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getday
es6id: 20.3.4.3
description: Return value for valid dates
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
3. Return WeekDay(LocalTime(t)).
---*/
assert.sameValue(new Date(2016, 6, 6).getDay(), 3, 'first millisecond');
assert.sameValue(
new Date(2016, 6, 6, 0, 0, 0, -1).getDay(), 2, 'previous millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 23, 59, 59, 999).getDay(), 3, 'final millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 23, 59, 59, 1000).getDay(), 4, 'subsequent millisecond'
);
assert.sameValue(
new Date(2016, 6, 9).getDay(), 6, 'first millisecond (week boundary)'
);
assert.sameValue(
new Date(2016, 6, 9, 0, 0, 0, -1).getDay(),
5,
'previous millisecond (week boundary)'
);
assert.sameValue(
new Date(2016, 6, 9, 23, 59, 59, 999).getDay(),
6,
'final millisecond (week boundary)'
);
assert.sameValue(
new Date(2016, 6, 9, 23, 59, 59, 1000).getDay(),
0,
'subsequent millisecond (week boundary)'
);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getfullyear
es6id: 20.3.4.4
description: Return value for invalid date
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
---*/
assert.sameValue(new Date(NaN).getFullYear(), NaN);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getfullyear
es6id: 20.3.4.4
description: >
Behavior when "this" value is an Object without a [[DateValue]] internal slot
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
---*/
var getFullYear = Date.prototype.getFullYear;
var args = (function() { return arguments; }());
assert.sameValue(typeof getFullYear, 'function');
assert.throws(TypeError, function() {
getFullYear.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
getFullYear.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
getFullYear.call(args);
}, 'arguments exotic object');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getfullyear
es6id: 20.3.4.4
description: Behavior when "this" value is not an Object
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
features: [Symbol]
---*/
var getFullYear = Date.prototype.getFullYear;
var symbol = Symbol();
assert.sameValue(typeof getFullYear, 'function');
assert.throws(TypeError, function() {
getFullYear.call(0);
}, 'number');
assert.throws(TypeError, function() {
getFullYear.call(true);
}, 'boolean');
assert.throws(TypeError, function() {
getFullYear.call(null);
}, 'null');
assert.throws(TypeError, function() {
getFullYear.call(undefined);
}, 'undefined');
assert.throws(TypeError, function() {
getFullYear.call('');
}, 'string');
assert.throws(TypeError, function() {
getFullYear.call(symbol);
}, 'symbol');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getfullyear
es6id: 20.3.4.4
description: Return value for valid dates
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
3. Return YearFromTime(LocalTime(t)).
---*/
assert.sameValue(new Date(2016, 0).getFullYear(), 2016, 'first millisecond');
assert.sameValue(
new Date(2016, 0, 1, 0, 0, 0, -1).getFullYear(), 2015, 'previous millisecond'
);
assert.sameValue(
new Date(2016, 11, 31, 23, 59, 59, 999).getFullYear(),
2016,
'final millisecond'
);
assert.sameValue(
new Date(2016, 11, 31, 23, 59, 59, 1000).getFullYear(),
2017,
'subsequent millisecond'
);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.gethours
es6id: 20.3.4.5
description: Return value for invalid date
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
---*/
assert.sameValue(new Date(NaN).getHours(), NaN);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.gethours
es6id: 20.3.4.5
description: >
Behavior when "this" value is an Object without a [[DateValue]] internal slot
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
---*/
var getHours = Date.prototype.getHours;
var args = (function() { return arguments; }());
assert.sameValue(typeof getHours, 'function');
assert.throws(TypeError, function() {
getHours.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
getHours.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
getHours.call(args);
}, 'arguments exotic object');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.gethours
es6id: 20.3.4.5
description: Behavior when "this" value is not an Object
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
features: [Symbol]
---*/
var getHours = Date.prototype.getHours;
var symbol = Symbol();
assert.sameValue(typeof getHours, 'function');
assert.throws(TypeError, function() {
getHours.call(0);
}, 'number');
assert.throws(TypeError, function() {
getHours.call(true);
}, 'boolean');
assert.throws(TypeError, function() {
getHours.call(null);
}, 'null');
assert.throws(TypeError, function() {
getHours.call(undefined);
}, 'undefined');
assert.throws(TypeError, function() {
getHours.call('');
}, 'string');
assert.throws(TypeError, function() {
getHours.call(symbol);
}, 'symbol');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.gethours
es6id: 20.3.4.5
description: Return value for valid dates
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
3. Return HourFromTime(LocalTime(t)).
---*/
assert.sameValue(new Date(2016, 6, 6, 13).getHours(), 13, 'first millisecond');
assert.sameValue(
new Date(2016, 6, 6, 13, 0, 0, -1).getHours(), 12, 'previous millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 13, 59, 59, 999).getHours(),
13,
'final millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 13, 59, 59, 1000).getHours(),
14,
'subsequent millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 23).getHours(), 23, 'first millisecond (hour boundary)'
);
assert.sameValue(
new Date(2016, 6, 6, 23, 0, 0, -1).getHours(),
22,
'previous millisecond (hour boundary)'
);
assert.sameValue(
new Date(2016, 6, 6, 23, 59, 59, 999).getHours(),
23,
'final millisecond (hour boundary)'
);
assert.sameValue(
new Date(2016, 6, 6, 23, 59, 59, 1000).getHours(),
0,
'subsequent millisecond (hour boundary)'
);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getmilliseconds
es6id: 20.3.4.6
description: Return value for invalid date
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
---*/
assert.sameValue(new Date(NaN).getMilliseconds(), NaN);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getmilliseconds
es6id: 20.3.4.6
description: >
Behavior when "this" value is an Object without a [[DateValue]] internal slot
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
---*/
var getMilliseconds = Date.prototype.getMilliseconds;
var args = (function() { return arguments; }());
assert.sameValue(typeof getMilliseconds, 'function');
assert.throws(TypeError, function() {
getMilliseconds.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
getMilliseconds.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
getMilliseconds.call(args);
}, 'arguments exotic object');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getmilliseconds
es6id: 20.3.4.6
description: Behavior when "this" value is not an Object
info: |
1. Let t be ? thisTimeValue(this value).
The abstract operation thisTimeValue(value) performs the following steps:
1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
a. Return value.[[DateValue]].
2. Throw a TypeError exception.
features: [Symbol]
---*/
var getMilliseconds = Date.prototype.getMilliseconds;
var symbol = Symbol();
assert.sameValue(typeof getMilliseconds, 'function');
assert.throws(TypeError, function() {
getMilliseconds.call(0);
}, 'number');
assert.throws(TypeError, function() {
getMilliseconds.call(true);
}, 'boolean');
assert.throws(TypeError, function() {
getMilliseconds.call(null);
}, 'null');
assert.throws(TypeError, function() {
getMilliseconds.call(undefined);
}, 'undefined');
assert.throws(TypeError, function() {
getMilliseconds.call('');
}, 'string');
assert.throws(TypeError, function() {
getMilliseconds.call(symbol);
}, 'symbol');
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.getmilliseconds
es6id: 20.3.4.6
description: Return value for valid dates
info: |
1. Let t be ? thisTimeValue(this value).
2. If t is NaN, return NaN.
3. Return msFromTime(LocalTime(t)).
---*/
assert.sameValue(
new Date(2016, 6, 6).getMilliseconds(), 0, 'first millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 0, 0, 0, -1).getMilliseconds(),
999,
'previous millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 23, 59, 59, 999).getMilliseconds(),
999,
'final millisecond'
);
assert.sameValue(
new Date(2016, 6, 6, 23, 59, 59, 1000).getMilliseconds(),
0,
'subsequent millisecond'
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment