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

Unified Diff: test/span_test.dart

Issue 1028813002: Introduce span with line context (Closed) Base URL: git@github.com:dart-lang/source_span.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pubspec.yaml ('k') | test/utils_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/span_test.dart
diff --git a/test/span_test.dart b/test/span_test.dart
index c62753b1a59d66b54c5901deb9cd5155559b068e..39b0b9433ddc779998867a97ec8ebd60f77e7575 100644
--- a/test/span_test.dart
+++ b/test/span_test.dart
@@ -36,6 +36,37 @@ main() {
});
});
+ group('for new SourceSpanWithContext()', () {
+ test('context must contain text', () {
+ var start = new SourceLocation(2);
+ var end = new SourceLocation(5);
+ expect(() => new SourceSpanWithContext(
+ start, end, "abc", "--axc--"), throwsArgumentError);
+ });
+
+ test('text starts at start.column in context', () {
+ var start = new SourceLocation(3);
+ var end = new SourceLocation(5);
+ expect(() => new SourceSpanWithContext(
+ start, end, "abc", "--abc--"), throwsArgumentError);
+ });
+
+ test('text starts at start.column of line in multi-line context', () {
+ var start = new SourceLocation(4, line: 55, column: 3);
+ var end = new SourceLocation(7, line: 55, column: 6);
+ expect(() => new SourceSpanWithContext(
+ start, end, "abc", "\n--abc--"), throwsArgumentError);
+ expect(() => new SourceSpanWithContext(
+ start, end, "abc", "\n----abc--"), throwsArgumentError);
+ expect(() => new SourceSpanWithContext(
+ start, end, "abc", "\n\n--abc--"), throwsArgumentError);
+
+ // However, these are valid:
+ new SourceSpanWithContext(start, end, "abc", "\n---abc--");
+ new SourceSpanWithContext(start, end, "abc", "\n\n---abc--");
+ });
+ });
+
group('for union()', () {
test('source URLs must match', () {
var other = new SourceSpan(
@@ -178,15 +209,48 @@ foo bar
expect(span.message("oh no", color: true),
equals("""
line 1, column 6 of foo.dart: oh no
-${colors.RED}foo bar
-^^^^^^^${colors.NONE}"""));
+${colors.RED}foo bar${colors.NONE}
+${colors.RED}^^^^^^^${colors.NONE}"""));
});
test("uses the given color if it's passed", () {
expect(span.message("oh no", color: colors.YELLOW), equals("""
line 1, column 6 of foo.dart: oh no
-${colors.YELLOW}foo bar
-^^^^^^^${colors.NONE}"""));
+${colors.YELLOW}foo bar${colors.NONE}
+${colors.YELLOW}^^^^^^^${colors.NONE}"""));
+ });
+ });
+
+ group("message() with context", () {
+ var spanWithContext;
+ setUp(() {
+ spanWithContext = new SourceSpanWithContext(
+ new SourceLocation(5, sourceUrl: "foo.dart"),
+ new SourceLocation(12, sourceUrl: "foo.dart"),
+ "foo bar",
+ "-----foo bar-----");
+ });
+
+ test("underlines under the right column", () {
+ expect(spanWithContext.message("oh no", color: colors.YELLOW), equals("""
+line 1, column 6 of foo.dart: oh no
+-----${colors.YELLOW}foo bar${colors.NONE}-----
+ ${colors.YELLOW}^^^^^^^${colors.NONE}"""));
+ });
+
+ test("supports lines of preceeding context", () {
+ var span = new SourceSpanWithContext(
+ new SourceLocation(5, line: 3, column: 5, sourceUrl: "foo.dart"),
+ new SourceLocation(12, line: 3, column: 12, sourceUrl: "foo.dart"),
+ "foo bar",
+ "previous\nlines\n-----foo bar-----\nfollowing line\n");
+
+ expect(span.message("oh no", color: colors.YELLOW), equals("""
+line 4, column 6 of foo.dart: oh no
+previous
+lines
+-----${colors.YELLOW}foo bar${colors.NONE}-----
+ ${colors.YELLOW}^^^^^^^${colors.NONE}"""));
});
});
« no previous file with comments | « pubspec.yaml ('k') | test/utils_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698