mirror of https://github.com/tc39/test262.git
Add tests for Date.prototype.setYear
This commit is contained in:
parent
018ad2110d
commit
1a66e812c8
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Check type of various properties
|
||||
es5id: B.2.5
|
||||
description: Checking properties of the Date object (setYear)
|
||||
---*/
|
||||
|
||||
if (typeof Date.prototype.setYear !== "function") $ERROR('#1: typeof Date.prototype.setYear === "function". Actual: ' + (typeof Date.prototype.setYear ));
|
||||
if (typeof Date.prototype['setYear'] !== "function") $ERROR('#2: typeof Date.prototype["setYear"] === "function". Actual: ' + (typeof Date.prototype["setYear"] ));
|
|
@ -0,0 +1,26 @@
|
|||
// 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.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: Behavior when "this" value has no [[DateValue]] internal slot
|
||||
info: |
|
||||
1. Let t be ? thisTimeValue(this value).
|
||||
---*/
|
||||
|
||||
var setYear = Date.prototype.setYear;
|
||||
|
||||
assert.sameValue(typeof setYear, 'function');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
setYear.call({}, 1);
|
||||
}, 'object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
setYear.call(undefined, 1);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
setYear.call(null, 1);
|
||||
}, 'null');
|
|
@ -0,0 +1,18 @@
|
|||
// 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.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when the [[DateValue]] internal slot of "this" value is NaN
|
||||
info: |
|
||||
1. Let t be ? thisTimeValue(this value).
|
||||
2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t).
|
||||
---*/
|
||||
|
||||
var date = new Date({});
|
||||
var expected = new Date(1971, 0).valueOf();
|
||||
|
||||
assert.sameValue(date.setYear(71), expected, 'method return value');
|
||||
assert.sameValue(date.valueOf(), expected, '[[DateValue]] internal slot');
|
|
@ -0,0 +1,19 @@
|
|||
// 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.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when the [[DateValue]] internal slot of "this" value is an integer
|
||||
value
|
||||
info: |
|
||||
1. Let t be ? thisTimeValue(this value).
|
||||
2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t).
|
||||
---*/
|
||||
|
||||
var date = new Date(1970, 1, 2, 3, 4, 5);
|
||||
var expected = new Date(1971, 1, 2, 3, 4, 5).valueOf();
|
||||
|
||||
assert.sameValue(date.setYear(71), expected, 'method return value');
|
||||
assert.sameValue(date.valueOf(), expected, '[[DateValue]] internal slot');
|
|
@ -0,0 +1,34 @@
|
|||
// 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.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: Clipping of new time value
|
||||
info: |
|
||||
[...]
|
||||
9. Set the [[DateValue]] internal slot of this Date object to
|
||||
TimeClip(date).
|
||||
10. Return the value of the [[DateValue]] internal slot of this Date
|
||||
object.
|
||||
---*/
|
||||
|
||||
var date;
|
||||
|
||||
date = new Date(1970, 8, 12, 20, 0, 0, 0);
|
||||
|
||||
assert.notSameValue(
|
||||
date.setYear(275760), NaN, 'method return value (valid date)'
|
||||
);
|
||||
assert.notSameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (valid date)'
|
||||
);
|
||||
|
||||
date = new Date(1970, 8, 12, 20, 0, 0, 1);
|
||||
|
||||
assert.sameValue(
|
||||
date.setYear(275760), NaN, 'method return value (invalid date)'
|
||||
);
|
||||
assert.sameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (invalid date)'
|
||||
);
|
|
@ -0,0 +1,36 @@
|
|||
// 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.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: Behavior when year value coerces to NaN
|
||||
info: |
|
||||
[...]
|
||||
3. Let y be ? ToNumber(year).
|
||||
4. If y is NaN, set the [[DateValue]] internal slot of this Date object to
|
||||
NaN and return NaN.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var date;
|
||||
|
||||
date = new Date();
|
||||
assert.sameValue(date.setYear(), NaN, 'return value (no argument)');
|
||||
assert.sameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (no argument)'
|
||||
);
|
||||
|
||||
date = new Date();
|
||||
assert.sameValue(date.setYear(NaN), NaN, 'return value (literal NaN)');
|
||||
assert.sameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (literal NaN)'
|
||||
);
|
||||
|
||||
date = new Date();
|
||||
assert.sameValue(
|
||||
date.setYear('not a number'), NaN, 'return value (NaN from ToNumber)'
|
||||
);
|
||||
assert.sameValue(
|
||||
date.valueOf(), NaN, '[[DateValue]] internal slot (NaN from ToNumber)'
|
||||
);
|
|
@ -0,0 +1,42 @@
|
|||
// 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.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when the integer representation of the specified `year` is not
|
||||
relative to 1900
|
||||
info: |
|
||||
[...]
|
||||
5. If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, let yyyy be ToInteger(y) +
|
||||
1900.
|
||||
6. Else, let yyyy be y.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
var date;
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(-1);
|
||||
assert.sameValue(date.getFullYear(), -1);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(100);
|
||||
assert.sameValue(date.getFullYear(), 100);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(1899);
|
||||
assert.sameValue(date.getFullYear(), 1899);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(1900);
|
||||
assert.sameValue(date.getFullYear(), 1900);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(1999);
|
||||
assert.sameValue(date.getFullYear(), 1999);
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(2000);
|
||||
assert.sameValue(date.getFullYear(), 2000);
|
|
@ -0,0 +1,45 @@
|
|||
// 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.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when the integer representation of the specified `year` is
|
||||
relative to 1900
|
||||
info: |
|
||||
[...]
|
||||
5. If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, let yyyy be ToInteger(y) +
|
||||
1900.
|
||||
[...]
|
||||
---*/
|
||||
|
||||
var date;
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(-0.9999999);
|
||||
assert.sameValue(date.getFullYear(), 1900, 'y = -0.999999');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(-0);
|
||||
assert.sameValue(date.getFullYear(), 1900, 'y = -0');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(0);
|
||||
assert.sameValue(date.getFullYear(), 1900, 'y = 0');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(50);
|
||||
assert.sameValue(date.getFullYear(), 1950, 'y = 50');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(50.999999);
|
||||
assert.sameValue(date.getFullYear(), 1950, 'y = 50.999999');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(99);
|
||||
assert.sameValue(date.getFullYear(), 1999, 'y = 99');
|
||||
|
||||
date = new Date(1970, 0);
|
||||
date.setYear(99.999999);
|
||||
assert.sameValue(date.getFullYear(), 1999, 'y = 99.999999');
|
|
@ -0,0 +1,29 @@
|
|||
// 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.setyear
|
||||
es6id: B.2.4.2
|
||||
es5id: B.2.5
|
||||
description: >
|
||||
Behavior when calling ToNumber on year value returns an abrupt completion
|
||||
info: |
|
||||
[...]
|
||||
3. Let y be ? ToNumber(year).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var date = new Date();
|
||||
var symbol = Symbol('');
|
||||
var year = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
date.setYear(year);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
date.setYear(symbol);
|
||||
});
|
Loading…
Reference in New Issue