OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library path.test.utils; | |
6 | |
7 import "package:test/test.dart"; | 5 import "package:test/test.dart"; |
8 import "package:path/path.dart" as path; | 6 import "package:path/path.dart" as p; |
9 | 7 |
10 /// A matcher for a closure that throws a [path.PathException]. | 8 /// A matcher for a closure that throws a [path.PathException]. |
11 final throwsPathException = throwsA(new isInstanceOf<path.PathException>()); | 9 final throwsPathException = throwsA(new isInstanceOf<p.PathException>()); |
| 10 |
| 11 void expectEquals(p.Context context, String path1, String path2) { |
| 12 expect(context.equals(path1, path2), isTrue, |
| 13 reason: 'Expected "$path1" to equal "$path2".'); |
| 14 expect(context.equals(path2, path1), isTrue, |
| 15 reason: 'Expected "$path2" to equal "$path1".'); |
| 16 expect(context.hash(path1), equals(context.hash(path2)), |
| 17 reason: 'Expected "$path1" to hash the same as "$path2".'); |
| 18 } |
| 19 |
| 20 void expectNotEquals(p.Context context, String path1, String path2, |
| 21 {bool allowSameHash: false}) { |
| 22 expect(context.equals(path1, path2), isFalse, |
| 23 reason: 'Expected "$path1" not to equal "$path2".'); |
| 24 expect(context.equals(path2, path1), isFalse, |
| 25 reason: 'Expected "$path2" not to equal "$path1".'); |
| 26 |
| 27 // Hash collisions are allowed, but the test author should be explicitly aware |
| 28 // when they occur. |
| 29 if (allowSameHash) return; |
| 30 expect(context.hash(path1), isNot(equals(context.hash(path2))), |
| 31 reason: 'Expected "$path1" not to hash the same as "$path2".'); |
| 32 } |
OLD | NEW |