| OLD | NEW |
| 1 library TestUtils; | 1 library TestUtils; |
| 2 | 2 |
| 3 import 'dart:async'; | 3 import 'dart:async'; |
| 4 import 'dart:html'; | 4 import 'dart:html'; |
| 5 import 'dart:typeddata'; |
| 5 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
| 6 | 7 |
| 7 /** | 8 /** |
| 8 * Verifies that [actual] has the same graph structure as [expected]. | 9 * Verifies that [actual] has the same graph structure as [expected]. |
| 9 * Detects cycles and DAG structure in Maps and Lists. | 10 * Detects cycles and DAG structure in Maps and Lists. |
| 10 */ | 11 */ |
| 11 verifyGraph(expected, actual) { | 12 verifyGraph(expected, actual) { |
| 12 var eItems = []; | 13 var eItems = []; |
| 13 var aItems = []; | 14 var aItems = []; |
| 14 | 15 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 33 for (int i = 0; i < aItems.length; i++) { | 34 for (int i = 0; i < aItems.length; i++) { |
| 34 if (identical(actual, aItems[i])) { | 35 if (identical(actual, aItems[i])) { |
| 35 expect(expected, same(eItems[i]), | 36 expect(expected, same(eItems[i]), |
| 36 reason: message(path, 'extra back or side edge')); | 37 reason: message(path, 'extra back or side edge')); |
| 37 return; | 38 return; |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 eItems.add(expected); | 41 eItems.add(expected); |
| 41 aItems.add(actual); | 42 aItems.add(actual); |
| 42 | 43 |
| 43 if (expected is ArrayBuffer) { | 44 if (expected is ByteBuffer) { |
| 44 expect(actual is ArrayBuffer, isTrue, | 45 expect(actual is ByteBuffer, isTrue, |
| 45 reason: '$actual is ArrayBuffer'); | 46 reason: '$actual is ByteBuffer'); |
| 46 expect(expected.byteLength, equals(actual.byteLength), | 47 expect(expected.lengthInBytes, equals(actual.lengthInBytes), |
| 47 reason: message(path, '.byteLength')); | 48 reason: message(path, '.lengthInBytes')); |
| 48 // TODO(antonm): one can create a view on top of those | 49 // TODO(antonm): one can create a view on top of those |
| 49 // and check if contents identical. Let's do it later. | 50 // and check if contents identical. Let's do it later. |
| 50 return; | 51 return; |
| 51 } | 52 } |
| 52 | 53 |
| 53 if (expected is ArrayBufferView) { | 54 if (expected is TypedData) { |
| 54 expect(actual is ArrayBufferView, isTrue, | 55 expect(actual is TypedData, isTrue, |
| 55 reason: '$actual is ArrayBufferView'); | 56 reason: '$actual is TypedData'); |
| 56 walk('$path/.buffer', expected.buffer, actual.buffer); | 57 walk('$path/.buffer', expected.buffer, actual.buffer); |
| 57 expect(expected.byteOffset, equals(actual.byteOffset), | 58 expect(expected.offsetInBytes, equals(actual.offsetInBytes), |
| 58 reason: message(path, '.byteOffset')); | 59 reason: message(path, '.offsetInBytes')); |
| 59 expect(expected.byteLength, equals(actual.byteLength), | 60 expect(expected.lengthInBytes, equals(actual.lengthInBytes), |
| 60 reason: message(path, '.byteLength')); | 61 reason: message(path, '.lengthInBytes')); |
| 61 // And also fallback to elements check below. | 62 // And also fallback to elements check below. |
| 62 } | 63 } |
| 63 | 64 |
| 64 if (expected is List) { | 65 if (expected is List) { |
| 65 expect(actual, isList, reason: message(path, '$actual is List')); | 66 expect(actual, isList, reason: message(path, '$actual is List')); |
| 66 expect(actual.length, expected.length, | 67 expect(actual.length, expected.length, |
| 67 reason: message(path, 'different list lengths')); | 68 reason: message(path, 'different list lengths')); |
| 68 for (var i = 0; i < expected.length; i++) { | 69 for (var i = 0; i < expected.length; i++) { |
| 69 walk('$path[$i]', expected[i], actual[i]); | 70 walk('$path[$i]', expected[i], actual[i]); |
| 70 } | 71 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 return; | 88 return; |
| 88 } | 89 } |
| 89 | 90 |
| 90 expect(false, isTrue, reason: 'Unhandled type: $expected'); | 91 expect(false, isTrue, reason: 'Unhandled type: $expected'); |
| 91 } | 92 } |
| 92 | 93 |
| 93 walk('', expected, actual); | 94 walk('', expected, actual); |
| 94 } | 95 } |
| OLD | NEW |