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

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
Index: test/span_test.dart
diff --git a/test/span_test.dart b/test/span_test.dart
index c62753b1a59d66b54c5901deb9cd5155559b068e..0240f87826dc97fdd6afb089f860c0c1ba425619 100644
--- a/test/span_test.dart
+++ b/test/span_test.dart
@@ -9,10 +9,8 @@ import 'package:source_span/src/colors.dart' as colors;
main() {
var span;
setUp(() {
- span = new SourceSpan(
- new SourceLocation(5, sourceUrl: "foo.dart"),
- new SourceLocation(12, sourceUrl: "foo.dart"),
- "foo bar");
+ span = new SourceSpan(new SourceLocation(5, sourceUrl: "foo.dart"),
+ new SourceLocation(12, sourceUrl: "foo.dart"), "foo bar");
});
group('errors', () {
@@ -36,12 +34,27 @@ 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);
+ });
+ });
+
group('for union()', () {
test('source URLs must match', () {
var other = new SourceSpan(
new SourceLocation(12, sourceUrl: "bar.dart"),
- new SourceLocation(13, sourceUrl: "bar.dart"),
- "_");
+ new SourceLocation(13, sourceUrl: "bar.dart"), "_");
expect(() => span.union(other), throwsArgumentError);
});
@@ -49,18 +62,15 @@ main() {
test('spans may not be disjoint', () {
var other = new SourceSpan(
new SourceLocation(13, sourceUrl: 'foo.dart'),
- new SourceLocation(14, sourceUrl: 'foo.dart'),
- "_");
+ new SourceLocation(14, sourceUrl: 'foo.dart'), "_");
expect(() => span.union(other), throwsArgumentError);
});
});
test('for compareTo() source URLs must match', () {
- var other = new SourceSpan(
- new SourceLocation(12, sourceUrl: "bar.dart"),
- new SourceLocation(13, sourceUrl: "bar.dart"),
- "_");
+ var other = new SourceSpan(new SourceLocation(12, sourceUrl: "bar.dart"),
+ new SourceLocation(13, sourceUrl: "bar.dart"), "_");
expect(() => span.compareTo(other), throwsArgumentError);
});
@@ -75,10 +85,8 @@ main() {
group("union()", () {
test("works with a preceding adjacent span", () {
- var other = new SourceSpan(
- new SourceLocation(0, sourceUrl: "foo.dart"),
- new SourceLocation(5, sourceUrl: "foo.dart"),
- "hey, ");
+ var other = new SourceSpan(new SourceLocation(0, sourceUrl: "foo.dart"),
+ new SourceLocation(5, sourceUrl: "foo.dart"), "hey, ");
var result = span.union(other);
expect(result.start, equals(other.start));
@@ -87,10 +95,8 @@ main() {
});
test("works with a preceding overlapping span", () {
- var other = new SourceSpan(
- new SourceLocation(0, sourceUrl: "foo.dart"),
- new SourceLocation(8, sourceUrl: "foo.dart"),
- "hey, foo");
+ var other = new SourceSpan(new SourceLocation(0, sourceUrl: "foo.dart"),
+ new SourceLocation(8, sourceUrl: "foo.dart"), "hey, foo");
var result = span.union(other);
expect(result.start, equals(other.start));
@@ -99,10 +105,8 @@ main() {
});
test("works with a following adjacent span", () {
- var other = new SourceSpan(
- new SourceLocation(12, sourceUrl: "foo.dart"),
- new SourceLocation(16, sourceUrl: "foo.dart"),
- " baz");
+ var other = new SourceSpan(new SourceLocation(12, sourceUrl: "foo.dart"),
+ new SourceLocation(16, sourceUrl: "foo.dart"), " baz");
var result = span.union(other);
expect(result.start, equals(span.start));
@@ -111,10 +115,8 @@ main() {
});
test("works with a following overlapping span", () {
- var other = new SourceSpan(
- new SourceLocation(9, sourceUrl: "foo.dart"),
- new SourceLocation(16, sourceUrl: "foo.dart"),
- "bar baz");
+ var other = new SourceSpan(new SourceLocation(9, sourceUrl: "foo.dart"),
+ new SourceLocation(16, sourceUrl: "foo.dart"), "bar baz");
var result = span.union(other);
expect(result.start, equals(span.start));
@@ -123,19 +125,15 @@ main() {
});
test("works with an internal overlapping span", () {
- var other = new SourceSpan(
- new SourceLocation(7, sourceUrl: "foo.dart"),
- new SourceLocation(10, sourceUrl: "foo.dart"),
- "o b");
+ var other = new SourceSpan(new SourceLocation(7, sourceUrl: "foo.dart"),
+ new SourceLocation(10, sourceUrl: "foo.dart"), "o b");
expect(span.union(other), equals(span));
});
test("works with an external overlapping span", () {
- var other = new SourceSpan(
- new SourceLocation(0, sourceUrl: "foo.dart"),
- new SourceLocation(16, sourceUrl: "foo.dart"),
- "hey, foo bar baz");
+ var other = new SourceSpan(new SourceLocation(0, sourceUrl: "foo.dart"),
+ new SourceLocation(16, sourceUrl: "foo.dart"), "hey, foo bar baz");
expect(span.union(other), equals(other));
});
@@ -160,11 +158,10 @@ foo bar
});
test("gracefully handles empty text", () {
- var span = new SourceSpan(
- new SourceLocation(5), new SourceLocation(5), "");
+ var span =
+ new SourceSpan(new SourceLocation(5), new SourceLocation(5), "");
- expect(span.message("oh no"),
- equals("line 1, column 6: oh no"));
+ expect(span.message("oh no"), equals("line 1, column 6: oh no"));
});
test("doesn't colorize if color is false", () {
@@ -175,37 +172,49 @@ foo bar
});
test("colorizes if color is true", () {
- expect(span.message("oh no", color: true),
- equals("""
+ 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}"""));
});
});
group("compareTo()", () {
test("sorts by start location first", () {
- var other = new SourceSpan(
- new SourceLocation(6, sourceUrl: "foo.dart"),
- new SourceLocation(14, sourceUrl: "foo.dart"),
- "oo bar b");
+ var other = new SourceSpan(new SourceLocation(6, sourceUrl: "foo.dart"),
+ new SourceLocation(14, sourceUrl: "foo.dart"), "oo bar b");
expect(span.compareTo(other), lessThan(0));
expect(other.compareTo(span), greaterThan(0));
});
test("sorts by length second", () {
- var other = new SourceSpan(
- new SourceLocation(5, sourceUrl: "foo.dart"),
- new SourceLocation(14, sourceUrl: "foo.dart"),
- "foo bar b");
+ var other = new SourceSpan(new SourceLocation(5, sourceUrl: "foo.dart"),
+ new SourceLocation(14, sourceUrl: "foo.dart"), "foo bar b");
expect(span.compareTo(other), lessThan(0));
expect(other.compareTo(span), greaterThan(0));
@@ -218,37 +227,29 @@ ${colors.YELLOW}foo bar
group("equality", () {
test("two spans with the same locations are equal", () {
- var other = new SourceSpan(
- new SourceLocation(5, sourceUrl: "foo.dart"),
- new SourceLocation(12, sourceUrl: "foo.dart"),
- "foo bar");
+ var other = new SourceSpan(new SourceLocation(5, sourceUrl: "foo.dart"),
+ new SourceLocation(12, sourceUrl: "foo.dart"), "foo bar");
expect(span, equals(other));
});
test("a different start isn't equal", () {
- var other = new SourceSpan(
- new SourceLocation(0, sourceUrl: "foo.dart"),
- new SourceLocation(12, sourceUrl: "foo.dart"),
- "hey, foo bar");
+ var other = new SourceSpan(new SourceLocation(0, sourceUrl: "foo.dart"),
+ new SourceLocation(12, sourceUrl: "foo.dart"), "hey, foo bar");
expect(span, isNot(equals(other)));
});
test("a different end isn't equal", () {
- var other = new SourceSpan(
- new SourceLocation(5, sourceUrl: "foo.dart"),
- new SourceLocation(16, sourceUrl: "foo.dart"),
- "foo bar baz");
+ var other = new SourceSpan(new SourceLocation(5, sourceUrl: "foo.dart"),
+ new SourceLocation(16, sourceUrl: "foo.dart"), "foo bar baz");
expect(span, isNot(equals(other)));
});
test("a different source URL isn't equal", () {
- var other = new SourceSpan(
- new SourceLocation(5, sourceUrl: "bar.dart"),
- new SourceLocation(12, sourceUrl: "bar.dart"),
- "foo bar");
+ var other = new SourceSpan(new SourceLocation(5, sourceUrl: "bar.dart"),
+ new SourceLocation(12, sourceUrl: "bar.dart"), "foo bar");
expect(span, isNot(equals(other)));
});
« lib/src/span.dart ('K') | « test/location_test.dart ('k') | test/utils_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698