Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: tests/compiler/dart2js/message_span_test.dart

Issue 2788373002: Add Source.getTextLine and use it to display source snippets in error messages. (Closed)
Patch Set: dartfmt Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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:convert' show JSON, UTF8;
5 import 'package:async_helper/async_helper.dart'; 6 import 'package:async_helper/async_helper.dart';
6 import 'package:compiler/src/commandline_options.dart'; 7 import 'package:compiler/src/commandline_options.dart';
7 import 'package:compiler/src/diagnostics/messages.dart'; 8 import 'package:compiler/src/diagnostics/messages.dart';
8 import 'package:compiler/src/io/source_file.dart'; 9 import 'package:compiler/src/io/source_file.dart';
9 import 'package:expect/expect.dart'; 10 import 'package:expect/expect.dart';
10 import 'memory_compiler.dart'; 11 import 'memory_compiler.dart';
11 import 'memory_source_file_helper.dart'; 12 import 'memory_source_file_helper.dart';
12 13
13 const List<Test> TESTS = const <Test>[ 14 const List<Test> TESTS = const <Test>[
14 const Test( 15 const Test(
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 new Map<MessageKind, String>.from(test.kindToSpan); 169 new Map<MessageKind, String>.from(test.kindToSpan);
169 for (CollectedMessage message in collector.messages) { 170 for (CollectedMessage message in collector.messages) {
170 String expectedSpanText = kindToSpan[message.messageKind]; 171 String expectedSpanText = kindToSpan[message.messageKind];
171 if (expectedSpanText != null) { 172 if (expectedSpanText != null) {
172 SourceFile sourceFile = provider.getSourceFile(message.uri); 173 SourceFile sourceFile = provider.getSourceFile(message.uri);
173 String locationMessage = 174 String locationMessage =
174 sourceFile.getLocationMessage(MARKER, message.begin, message.end); 175 sourceFile.getLocationMessage(MARKER, message.begin, message.end);
175 // Remove `filename:line:column:` and message. 176 // Remove `filename:line:column:` and message.
176 String strippedLocationMessage = locationMessage 177 String strippedLocationMessage = locationMessage
177 .substring(locationMessage.indexOf(MARKER) + MARKER.length + 1); 178 .substring(locationMessage.indexOf(MARKER) + MARKER.length + 1);
179 // Using JSON.encode to add string quotes and backslashes.
180 String expected = JSON.encode(
181 UTF8.decode(expectedSpanText.codeUnits, allowMalformed: true));
182 String actual = JSON.encode(UTF8
183 .decode(strippedLocationMessage.codeUnits, allowMalformed: true));
178 Expect.equals( 184 Expect.equals(
179 expectedSpanText, 185 expectedSpanText,
180 strippedLocationMessage, 186 strippedLocationMessage,
181 "Unexpected span for ${message.messageKind} in\n${test.code}" 187 "Unexpected span for ${message.messageKind} in\n${test.code}"
182 "\nExpected:${expectedSpanText.codeUnits}" 188 "\nExpected: $expected"
183 "\nActual :${strippedLocationMessage.codeUnits}"); 189 "\nActual : $actual");
184 kindToSpan.remove(message.messageKind); 190 kindToSpan.remove(message.messageKind);
185 } 191 }
186 } 192 }
187 kindToSpan.forEach((MessageKind kind, _) { 193 kindToSpan.forEach((MessageKind kind, _) {
188 Expect.fail("Missing message kin $kind in\n${test.code}"); 194 Expect.fail("Missing message kin $kind in\n${test.code}");
189 }); 195 });
190 } 196 }
191 }); 197 });
192 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698