OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 'dart:io'; | 5 import 'dart:io' as io; |
6 | 6 |
7 import '../lib/shared_messages.dart'; | 7 import '../lib/shared_messages.dart'; |
8 | 8 |
9 void testJsonIsUpdated() { | 9 void testJsonIsUpdated() { |
10 var packageRoot = Platform.packageRoot; | 10 var packageRoot = io.Platform.packageRoot; |
11 if (packageRoot == null || packageRoot == "") { | 11 if (packageRoot == null || packageRoot == "") { |
12 throw new UnsupportedError("This test requires a package root."); | 12 throw new UnsupportedError("This test requires a package root."); |
13 } | 13 } |
14 var jsonUri = Uri.parse(packageRoot).resolve( | 14 var jsonUri = Uri.parse(packageRoot).resolve( |
15 'dart_messages/generated/shared_messages.json'); | 15 'dart_messages/generated/shared_messages.json'); |
16 var jsonPath = jsonUri.toFilePath(); | 16 var jsonPath = jsonUri.toFilePath(); |
17 var content = new File(jsonPath).readAsStringSync(); | 17 var content = new io.File(jsonPath).readAsStringSync(); |
18 if (messagesAsJson != content) { | 18 if (messagesAsJson != content) { |
19 print("The content of the Dart messages and the corresponding JSON file"); | 19 print("The content of the Dart messages and the corresponding JSON file"); |
20 print("is not the same."); | 20 print("is not the same."); |
21 print("Please run bin/publish.dart to update the JSON file."); | 21 print("Please run bin/publish.dart to update the JSON file."); |
22 throw "Content is not the same"; | 22 throw "Content is not the same"; |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 void testIdsAreUnique() { | 26 void testIdsAreUnique() { |
27 var usedIds = new Set(); | 27 var usedIds = new Set(); |
28 for (var entry in MESSAGES.values) { | 28 for (var entry in MESSAGES.values) { |
29 var id = entry.id; | 29 var id = "${entry.id}-${entry.subId}"; |
30 if (!usedIds.add(id)) { | 30 if (!usedIds.add(id)) { |
31 throw "Id appears twice: $id"; | 31 throw "Id appears twice: $id"; |
32 } | 32 } |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 void main() { | 36 void main() { |
37 testJsonIsUpdated(); | 37 testJsonIsUpdated(); |
38 testIdsAreUnique(); | 38 testIdsAreUnique(); |
39 } | 39 } |
OLD | NEW |