OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'package:unittest/unittest.dart'; | 5 import 'package:matcher/mirror_matchers.dart'; |
6 import 'package:unittest/mirror_matchers.dart'; | 6 import 'package:unittest/unittest.dart' as ut; |
7 | 7 |
8 import 'test_utils.dart'; | 8 import 'test_utils.dart'; |
9 | 9 |
10 class C { | 10 class C { |
11 var instanceField = 1; | 11 var instanceField = 1; |
12 get instanceGetter => 2; | 12 get instanceGetter => 2; |
13 static var staticField = 3; | 13 static var staticField = 3; |
14 static get staticGetter => 4; | 14 static get staticGetter => 4; |
15 } | 15 } |
16 | 16 |
17 void main() { | 17 void main() { |
18 | 18 |
19 initUtils(); | 19 initUtils(); |
20 | 20 |
21 test('hasProperty', () { | 21 ut.test('hasProperty', () { |
22 var foo = [3]; | 22 var foo = [3]; |
23 shouldPass(foo, hasProperty('length', 1)); | 23 shouldPass(foo, hasProperty('length', 1)); |
24 shouldFail(foo, hasProperty('foo'), 'Expected: has property "foo" ' | 24 shouldFail(foo, hasProperty('foo'), 'Expected: has property "foo" ' |
25 'Actual: [3] ' | 25 'Actual: [3] ' |
26 'Which: has no property named "foo"'); | 26 'Which: has no property named "foo"'); |
27 shouldFail(foo, hasProperty('length', 2), | 27 shouldFail(foo, hasProperty('length', 2), |
28 'Expected: has property "length" which matches <2> ' | 28 'Expected: has property "length" which matches <2> ' |
29 'Actual: [3] ' | 29 'Actual: [3] ' |
30 'Which: has property "length" with value <1>'); | 30 'Which: has property "length" with value <1>'); |
31 var c = new C(); | 31 var c = new C(); |
32 shouldPass(c, hasProperty('instanceField', 1)); | 32 shouldPass(c, hasProperty('instanceField', 1)); |
33 shouldPass(c, hasProperty('instanceGetter', 2)); | 33 shouldPass(c, hasProperty('instanceGetter', 2)); |
34 shouldFail(c, hasProperty('staticField'), | 34 shouldFail(c, hasProperty('staticField'), |
35 'Expected: has property "staticField" ' | 35 'Expected: has property "staticField" ' |
36 'Actual: <Instance of \'C\'> ' | 36 'Actual: <Instance of \'C\'> ' |
37 'Which: has a member named "staticField",' | 37 'Which: has a member named "staticField",' |
38 ' but it is not an instance property'); | 38 ' but it is not an instance property'); |
39 shouldFail(c, hasProperty('staticGetter'), | 39 shouldFail(c, hasProperty('staticGetter'), |
40 'Expected: has property "staticGetter" ' | 40 'Expected: has property "staticGetter" ' |
41 'Actual: <Instance of \'C\'> ' | 41 'Actual: <Instance of \'C\'> ' |
42 'Which: has a member named "staticGetter",' | 42 'Which: has a member named "staticGetter",' |
43 ' but it is not an instance property'); | 43 ' but it is not an instance property'); |
44 }); | 44 }); |
45 } | 45 } |
OLD | NEW |