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