| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:compiler/src/common.dart'; | 8 import 'package:compiler/src/common.dart'; |
| 9 import 'package:compiler/src/common_elements.dart'; | 9 import 'package:compiler/src/common_elements.dart'; |
| 10 import 'package:compiler/src/compiler.dart'; | 10 import 'package:compiler/src/compiler.dart'; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 annotations | 123 annotations |
| 124 .putIfAbsent(data.sourceSpan.begin, () => []) | 124 .putIfAbsent(data.sourceSpan.begin, () => []) |
| 125 .add('${data.value}'); | 125 .add('${data.value}'); |
| 126 }); | 126 }); |
| 127 return withAnnotations(annotations); | 127 return withAnnotations(annotations); |
| 128 } | 128 } |
| 129 | 129 |
| 130 String get diffCode { | 130 String get diffCode { |
| 131 Map<int, List<String>> annotations = <int, List<String>>{}; | 131 Map<int, List<String>> annotations = <int, List<String>>{}; |
| 132 actualMap.forEach((Id id, ActualData data) { | 132 actualMap.forEach((Id id, ActualData data) { |
| 133 String expected = expectedMap[id]?.value ?? ''; | 133 IdValue value = expectedMap[id]; |
| 134 if (data.value != expected) { | 134 if (data.value != value || value == null && data.value.value != '') { |
| 135 String expected = value?.toString() ?? ''; |
| 135 annotations | 136 annotations |
| 136 .putIfAbsent(data.sourceSpan.begin, () => []) | 137 .putIfAbsent(data.sourceSpan.begin, () => []) |
| 137 .add('${expected} | ${data.value}'); | 138 .add('${expected} | ${data.value}'); |
| 138 } | 139 } |
| 139 }); | 140 }); |
| 140 expectedMap.forEach((Id id, IdValue expected) { | 141 expectedMap.forEach((Id id, IdValue expected) { |
| 141 if (!actualMap.containsKey(id)) { | 142 if (!actualMap.containsKey(id)) { |
| 142 int offset = compiler.reporter | 143 int offset = compiler.reporter |
| 143 .spanFromSpannable( | 144 .spanFromSpannable( |
| 144 computeSpannable(elementEnvironment, mainUri, id)) | 145 computeSpannable(elementEnvironment, mainUri, id)) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 Set<Id> missingIds = new Set<Id>(); | 250 Set<Id> missingIds = new Set<Id>(); |
| 250 data.expectedMap.forEach((Id id, IdValue expected) { | 251 data.expectedMap.forEach((Id id, IdValue expected) { |
| 251 if (!data.actualMap.containsKey(id)) { | 252 if (!data.actualMap.containsKey(id)) { |
| 252 missingIds.add(id); | 253 missingIds.add(id); |
| 253 reportHere( | 254 reportHere( |
| 254 data.compiler.reporter, | 255 data.compiler.reporter, |
| 255 computeSpannable(data.elementEnvironment, data.mainUri, id), | 256 computeSpannable(data.elementEnvironment, data.mainUri, id), |
| 256 'Expected $expected for id $id missing in ${data.actualMap.keys}'); | 257 'Expected $expected for id $id missing in ${data.actualMap.keys}'); |
| 257 } | 258 } |
| 258 }); | 259 }); |
| 260 if (missingIds.isNotEmpty) { |
| 261 print('--annotations diff--------------------------------------------'); |
| 262 print(data.diffCode); |
| 263 print('--------------------------------------------------------------'); |
| 264 } |
| 259 Expect.isTrue(missingIds.isEmpty, "Ids not found: ${missingIds}."); | 265 Expect.isTrue(missingIds.isEmpty, "Ids not found: ${missingIds}."); |
| 260 } | 266 } |
| 261 | 267 |
| 262 /// Compute a [Spannable] from an [id] in the library [mainUri]. | 268 /// Compute a [Spannable] from an [id] in the library [mainUri]. |
| 263 Spannable computeSpannable( | 269 Spannable computeSpannable( |
| 264 ElementEnvironment elementEnvironment, Uri mainUri, Id id) { | 270 ElementEnvironment elementEnvironment, Uri mainUri, Id id) { |
| 265 if (id is NodeId) { | 271 if (id is NodeId) { |
| 266 return new SourceSpan(mainUri, id.value, id.value + 1); | 272 return new SourceSpan(mainUri, id.value, id.value + 1); |
| 267 } else if (id is ElementId) { | 273 } else if (id is ElementId) { |
| 268 LibraryEntity library = elementEnvironment.lookupLibrary(mainUri); | 274 LibraryEntity library = elementEnvironment.lookupLibrary(mainUri); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 279 | 285 |
| 280 /// Compute the expectancy map from [code]. | 286 /// Compute the expectancy map from [code]. |
| 281 Map<Id, IdValue> computeExpectedMap(AnnotatedCode code) { | 287 Map<Id, IdValue> computeExpectedMap(AnnotatedCode code) { |
| 282 Map<Id, IdValue> map = <Id, IdValue>{}; | 288 Map<Id, IdValue> map = <Id, IdValue>{}; |
| 283 for (Annotation annotation in code.annotations) { | 289 for (Annotation annotation in code.annotations) { |
| 284 IdValue idValue = IdValue.decode(annotation.offset, annotation.text); | 290 IdValue idValue = IdValue.decode(annotation.offset, annotation.text); |
| 285 map[idValue.id] = idValue; | 291 map[idValue.id] = idValue; |
| 286 } | 292 } |
| 287 return map; | 293 return map; |
| 288 } | 294 } |
| OLD | NEW |