| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 if (name_opt) { | 44 if (name_opt) { |
| 45 // Fix this when we ditch the old test runner. | 45 // Fix this when we ditch the old test runner. |
| 46 start = "Fail" + "ure (" + name_opt + "): "; | 46 start = "Fail" + "ure (" + name_opt + "): "; |
| 47 } else { | 47 } else { |
| 48 start = "Fail" + "ure:"; | 48 start = "Fail" + "ure:"; |
| 49 } | 49 } |
| 50 throw new MjsUnitAssertionError(start + " expected <" + expected + "> found <"
+ found + ">"); | 50 throw new MjsUnitAssertionError(start + " expected <" + expected + "> found <"
+ found + ">"); |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 function deepEquals(a, b) { |
| 55 if (a == b) return true; |
| 56 if ((typeof a) !== 'object' || (typeof b) !== 'object' || |
| 57 (a === null) || (b === null)) |
| 58 return false; |
| 59 if (a.constructor === Array) { |
| 60 if (b.constructor !== Array) |
| 61 return false; |
| 62 if (a.length != b.length) |
| 63 return false; |
| 64 for (var i = 0; i < a.length; i++) { |
| 65 if (i in a) { |
| 66 if (!(i in b) || !(deepEquals(a[i], b[i]))) |
| 67 return false; |
| 68 } else if (i in b) { |
| 69 return false; |
| 70 } |
| 71 } |
| 72 return true; |
| 73 } |
| 74 return false; |
| 75 } |
| 76 |
| 77 |
| 54 function assertEquals(expected, found, name_opt) { | 78 function assertEquals(expected, found, name_opt) { |
| 55 if (expected != found) { | 79 if (!deepEquals(found, expected)) { |
| 56 fail(expected, found, name_opt); | 80 fail(expected, found, name_opt); |
| 57 } | 81 } |
| 58 } | 82 } |
| 59 | 83 |
| 60 | 84 |
| 61 function assertArrayEquals(expected, found, name_opt) { | 85 function assertArrayEquals(expected, found, name_opt) { |
| 62 var start = ""; | 86 var start = ""; |
| 63 if (name_opt) { | 87 if (name_opt) { |
| 64 start = name_opt + " - "; | 88 start = name_opt + " - "; |
| 65 } | 89 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 142 |
| 119 | 143 |
| 120 function assertUnreachable(name_opt) { | 144 function assertUnreachable(name_opt) { |
| 121 // Fix this when we ditch the old test runner. | 145 // Fix this when we ditch the old test runner. |
| 122 var message = "Fail" + "ure: unreachable" | 146 var message = "Fail" + "ure: unreachable" |
| 123 if (name_opt) { | 147 if (name_opt) { |
| 124 message += " - " + name_opt; | 148 message += " - " + name_opt; |
| 125 } | 149 } |
| 126 throw new MjsUnitAssertionError(message); | 150 throw new MjsUnitAssertionError(message); |
| 127 } | 151 } |
| OLD | NEW |