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

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: code review 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
« no previous file with comments | « pkg/source_span/pubspec.yaml ('k') | pkg/source_span/test/file_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 test("works for a single-line file without a newline", () {
71 expect(new SourceFile("foo bar").span(0, 7).message("oh no"),
72 equals("""
73 line 1, column 1: oh no
74 foo bar
75 ^^^^^^^"""));
76 });
77
78 group("colors", () {
79 test("doesn't colorize if color is false", () {
80 expect(file.span(4, 7).message("oh no", color: false), equals("""
81 line 1, column 5 of foo.dart: oh no
82 foo bar baz
83 ^^^"""));
84 });
85
86 test("colorizes if color is true", () {
87 expect(file.span(4, 7).message("oh no", color: true), equals("""
88 line 1, column 5 of foo.dart: oh no
89 foo ${colors.RED}bar${colors.NONE} baz
90 ${colors.RED}^^^${colors.NONE}"""));
91 });
92
93 test("uses the given color if it's passed", () {
94 expect(file.span(4, 7).message("oh no", color: colors.YELLOW), equals("""
95 line 1, column 5 of foo.dart: oh no
96 foo ${colors.YELLOW}bar${colors.NONE} baz
97 ${colors.YELLOW}^^^${colors.NONE}"""));
98 });
99 });
100 }
OLDNEW
« no previous file with comments | « pkg/source_span/pubspec.yaml ('k') | pkg/source_span/test/file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698