| 1 |
// Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
description: > |
| 5 |
Only passes when the provided date is exactly the specified number of |
| 6 |
milliseconds from the Unix epoch |
| 7 |
includes: [assertRelativeDateMs.js] |
| 8 |
---*/ |
| 9 |
|
| 10 |
var thrown; |
| 11 |
|
| 12 |
assertRelativeDateMs(new Date(1970, 0), 0); |
| 13 |
assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, 0, 0), 0); |
| 14 |
assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, 0, 1), 1); |
| 15 |
assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, 0, -1), -1); |
| 16 |
assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, 1, 0), 1000); |
| 17 |
assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, -1, 0), -1000); |
| 18 |
assertRelativeDateMs(new Date(1970, 0, 1, 0, 2, 0, 0), 120000); |
| 19 |
assertRelativeDateMs(new Date(1970, 0, 1, 0, -2, 0, 0), -120000); |
| 20 |
assertRelativeDateMs(new Date(2016, 3, 12, 13, 21, 23, 24), 1460467283024); |
| 21 |
|
| 22 |
thrown = null; |
| 23 |
try { |
| 24 |
assertRelativeDateMs(new Date(1), 0); |
| 25 |
} catch (err) { |
| 26 |
thrown = err; |
| 27 |
} |
| 28 |
if (!thrown) { |
| 29 |
throw new Error('Expected error, but no error was thrown.'); |
| 30 |
} else if (thrown.constructor !== Test262Error) { |
| 31 |
throw new Error('Expected error of type Test262Error.'); |
| 32 |
} |
| 33 |
|
| 34 |
thrown = null; |
| 35 |
try { |
| 36 |
assertRelativeDateMs(new Date(-1), 0); |
| 37 |
} catch (err) { |
| 38 |
thrown = err; |
| 39 |
} |
| 40 |
if (!thrown) { |
| 41 |
throw new Error('Expected error, but no error was thrown.'); |
| 42 |
} else if (thrown.constructor !== Test262Error) { |
| 43 |
throw new Error('Expected error of type Test262Error.'); |
| 44 |
} |
| 45 |
|
| 46 |
thrown = null; |
| 47 |
try { |
| 48 |
assertRelativeDateMs(new Date(1970, 0), 1); |
| 49 |
} catch (err) { |
| 50 |
thrown = err; |
| 51 |
} |
| 52 |
if (!thrown) { |
| 53 |
throw new Error('Expected error, but no error was thrown.'); |
| 54 |
} else if (thrown.constructor !== Test262Error) { |
| 55 |
throw new Error('Expected error of type Test262Error.'); |
| 56 |
} |
| 57 |
|
| 58 |
thrown = null; |
| 59 |
try { |
| 60 |
assertRelativeDateMs(new Date(1970, 0), -1); |
| 61 |
} catch (err) { |
| 62 |
thrown = err; |
| 63 |
} |
| 64 |
if (!thrown) { |
| 65 |
throw new Error('Expected error, but no error was thrown.'); |
| 66 |
} else if (thrown.constructor !== Test262Error) { |
| 67 |
throw new Error('Expected error of type Test262Error.'); |
| 68 |
} |
| 69 |
|
| 70 |
thrown = null; |
| 71 |
try { |
| 72 |
assertRelativeDateMs(new Date('invalid'), NaN); |
| 73 |
} catch (err) { |
| 74 |
thrown = err; |
| 75 |
} |
| 76 |
if (!thrown) { |
| 77 |
throw new Error('Expected error, but no error was thrown.'); |
| 78 |
} else if (thrown.constructor !== Test262Error) { |
| 79 |
throw new Error('Expected error of type Test262Error.'); |
| 80 |
} |
| 81 |
|
| 82 |
reportCompare(0, 0); |