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

Side by Side Diff: pkg/source_span/test/file_message_test.dart

Issue 381363002: Extract out a source_span package from source_maps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
(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 import 'package:unittest/unittest.dart';
6 import 'package:source_span/source_span.dart';
7 import 'package:source_span/src/colors.dart' as colors;
8
9 main() {
10 var file;
11 setUp(() {
12 file = new SourceFile("""
13 foo bar baz
14 whiz bang boom
15 zip zap zop
16 """, url: "foo.dart");
17 });
18
19 test("points to the span in the source", () {
20 expect(file.span(4, 7).message("oh no"), equals("""
21 line 1, column 5 of foo.dart: oh no
22 foo bar baz
23 ^^^"""));
24 });
25
26 test("gracefully handles a missing source URL", () {
27 var span = new SourceFile("foo bar baz").span(4, 7);
28 expect(span.message("oh no"), equals("""
29 line 1, column 5: oh no
30 foo bar baz
31 ^^^"""));
32 });
33
34 test("highlights the first line of a multiline span", () {
35 expect(file.span(4, 20).message("oh no"), equals("""
36 line 1, column 5 of foo.dart: oh no
37 foo bar baz
38 ^^^^^^^^"""));
39 });
40
41 test("works for a point span", () {
42 expect(file.location(4).pointSpan().message("oh no"), equals("""
43 line 1, column 5 of foo.dart: oh no
44 foo bar baz
45 ^"""));
46 });
47
48 test("works for a point span at the end of a line", () {
49 expect(file.location(11).pointSpan().message("oh no"), equals("""
50 line 1, column 12 of foo.dart: oh no
51 foo bar baz
52 ^"""));
53 });
54
55 test("works for a point span at the end of the file", () {
56 expect(file.location(38).pointSpan().message("oh no"), equals("""
57 line 3, column 12 of foo.dart: oh no
58 zip zap zop
59 ^"""));
60 });
61
62 test("works for a point span in an empty file", () {
63 expect(new SourceFile("").location(0).pointSpan().message("oh no"),
64 equals("""
65 line 1, column 1: oh no
66
67 ^"""));
68 });
69
70 group("colors", () {
71 test("doesn't colorize if color is false", () {
72 expect(file.span(4, 7).message("oh no", color: false), equals("""
73 line 1, column 5 of foo.dart: oh no
74 foo bar baz
75 ^^^"""));
76 });
77
78 test("colorizes if color is true", () {
79 expect(file.span(4, 7).message("oh no", color: true), equals("""
80 line 1, column 5 of foo.dart: oh no
81 foo ${colors.RED}bar${colors.NONE} baz
82 ${colors.RED}^^^${colors.NONE}"""));
83 });
84
85 test("uses the given color if it's passed", () {
86 expect(file.span(4, 7).message("oh no", color: colors.YELLOW), equals("""
87 line 1, column 5 of foo.dart: oh no
88 foo ${colors.YELLOW}bar${colors.NONE} baz
89 ${colors.YELLOW}^^^${colors.NONE}"""));
90 });
91 });
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698