OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Asserts that a given argument's value is undefined. | 6 * Asserts that a given argument's value is undefined. |
7 * @param {object} a The argument to check. | 7 * @param {object} a The argument to check. |
8 */ | 8 */ |
9 function assertUndefined(a) { | 9 function assertUndefined(a) { |
10 if (a !== undefined) { | 10 if (a !== undefined) { |
11 throw new Error('Assertion failed: expected undefined'); | 11 throw new Error('Assertion failed: expected undefined'); |
12 } | 12 } |
13 } | 13 } |
14 | 14 |
15 /** | 15 /** |
16 * Asserts that the argument is neither null nor undefined. | 16 * Asserts that the argument is neither null nor undefined. |
17 * @param {object} obj The argument to check. | 17 * @param {object} obj The argument to check. |
18 * @param {string=} opt_message Error message if the condition is not met. | 18 * @param {string=} opt_message Error message if the condition is not met. |
19 */ | 19 */ |
20 function assertNotNullNorUndefined(obj, opt_message) { | 20 function assertNotNullNorUndefined(obj, opt_message) { |
21 if (obj === undefined || obj === null) { | 21 if (obj === undefined || obj === null) { |
22 throw new Error('Can\'t be null or undefined: ' + (opt_message || '') + | 22 throw new Error('Can\'t be null or undefined: ' + (opt_message || '') + |
23 '\n' + 'Actual: ' + a); | 23 '\n' + 'Actual: ' + obj); |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 /** | 27 /** |
28 * Asserts that a given function call throws an exception. | 28 * Asserts that a given function call throws an exception. |
29 * @param {string} msg Message to print if exception not thrown. | 29 * @param {string} msg Message to print if exception not thrown. |
30 * @param {Function} fn The function to call. | 30 * @param {Function} fn The function to call. |
31 * @param {string} error The name of the exception we expect {@code fn} to | 31 * @param {string} error The name of the exception we expect {@code fn} to |
32 * throw. | 32 * throw. |
33 */ | 33 */ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 function assertEqualsJSON(expected, actual, opt_message) { | 75 function assertEqualsJSON(expected, actual, opt_message) { |
76 if (JSON.stringify(actual) !== JSON.stringify(expected)) { | 76 if (JSON.stringify(actual) !== JSON.stringify(expected)) { |
77 throw new Error((opt_message ? opt_message + '\n' : '') + | 77 throw new Error((opt_message ? opt_message + '\n' : '') + |
78 'Expected ' + JSON.stringify(expected) + '\n' + | 78 'Expected ' + JSON.stringify(expected) + '\n' + |
79 'Got ' + JSON.stringify(actual)); | 79 'Got ' + JSON.stringify(actual)); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 assertSame = assertEquals; | 83 assertSame = assertEquals; |
84 assertNotSame = assertNotEquals; | 84 assertNotSame = assertNotEquals; |
OLD | NEW |