OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Tests for some of the utility helper functions used by the compiler. | 5 /// Tests for some of the utility helper functions used by the compiler. |
| 6 @TestOn('vm') |
6 library polymer.test.build.messages_test; | 7 library polymer.test.build.messages_test; |
7 | 8 |
8 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
9 | 10 |
10 import 'package:unittest/unittest.dart'; | 11 import 'package:test/test.dart'; |
11 import 'package:code_transformers/messages/messages.dart' show Message; | 12 import 'package:code_transformers/messages/messages.dart' show Message; |
12 | 13 |
13 import 'package:code_transformers/src/messages.dart' as p1; | 14 import 'package:code_transformers/src/messages.dart' as p1; |
14 | 15 |
15 /// [p1] is accessed via mirrors, this comment prevents the analyzer from | 16 /// [p1] is accessed via mirrors, this comment prevents the analyzer from |
16 /// complaining about it. | 17 /// complaining about it. |
17 main() { | 18 main() { |
18 test('each message id is unique', () { | 19 test('each message id is unique', () { |
19 var seen = {}; | 20 var seen = {}; |
20 int total = 0; | 21 int total = 0; |
21 var mirrors = currentMirrorSystem(); | 22 var mirrors = currentMirrorSystem(); |
22 var lib = mirrors.findLibrary(#code_transformers.src.messages); | 23 var lib = mirrors.findLibrary(#code_transformers.src.messages); |
23 expect(lib, isNotNull); | 24 expect(lib, isNotNull); |
24 lib.declarations.forEach((symbol, decl) { | 25 lib.declarations.forEach((symbol, decl) { |
25 if (decl is! VariableMirror) return; | 26 if (decl is! VariableMirror) return; |
26 var field = lib.getField(symbol).reflectee; | 27 var field = lib.getField(symbol).reflectee; |
27 var name = MirrorSystem.getName(symbol); | 28 var name = MirrorSystem.getName(symbol); |
28 if (field is! Message) return; | 29 if (field is! Message) return; |
29 var id = field.id; | 30 var id = field.id; |
30 expect(seen.containsKey(id), isFalse, reason: 'Duplicate id `$id`. ' | 31 expect(seen.containsKey(id), isFalse, |
31 'Currently set for both `$name` and `${seen[id]}`.'); | 32 reason: 'Duplicate id `$id`. ' |
| 33 'Currently set for both `$name` and `${seen[id]}`.'); |
32 seen[id] = name; | 34 seen[id] = name; |
33 total++; | 35 total++; |
34 }); | 36 }); |
35 expect(seen.length, total); | 37 expect(seen.length, total); |
36 }); | 38 }); |
37 } | 39 } |
OLD | NEW |