| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
| 6 import 'package:source_span/source_span.dart'; | 6 import 'package:source_span/source_span.dart'; |
| 7 | 7 |
| 8 main() { | 8 main() { |
| 9 var file; | 9 var file; |
| 10 setUp(() { | 10 setUp(() { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 expect(() => file.getOffset(1, -1), throwsRangeError); | 80 expect(() => file.getOffset(1, -1), throwsRangeError); |
| 81 }); | 81 }); |
| 82 | 82 |
| 83 test("line may not be outside the file", () { | 83 test("line may not be outside the file", () { |
| 84 expect(() => file.getOffset(100), throwsRangeError); | 84 expect(() => file.getOffset(100), throwsRangeError); |
| 85 }); | 85 }); |
| 86 | 86 |
| 87 test("column may not be outside the file", () { | 87 test("column may not be outside the file", () { |
| 88 expect(() => file.getOffset(2, 100), throwsRangeError); | 88 expect(() => file.getOffset(2, 100), throwsRangeError); |
| 89 }); | 89 }); |
| 90 | 90 |
| 91 test("column may not be outside the line", () { | 91 test("column may not be outside the line", () { |
| 92 expect(() => file.getOffset(1, 20), throwsRangeError); | 92 expect(() => file.getOffset(1, 20), throwsRangeError); |
| 93 }); | 93 }); |
| 94 }); | 94 }); |
| 95 | 95 |
| 96 group("for getText()", () { | 96 group("for getText()", () { |
| 97 test("end must come after start", () { | 97 test("end must come after start", () { |
| 98 expect(() => file.getText(10, 5), throwsArgumentError); | 98 expect(() => file.getText(10, 5), throwsArgumentError); |
| 99 }); | 99 }); |
| 100 | 100 |
| 101 test("start may not be negative", () { | 101 test("start may not be negative", () { |
| 102 expect(() => file.getText(-1, 5), throwsRangeError); | 102 expect(() => file.getText(-1, 5), throwsRangeError); |
| 103 }); | 103 }); |
| 104 | 104 |
| 105 test("end may not be outside the file", () { | 105 test("end may not be outside the file", () { |
| 106 expect(() => file.getText(10, 100), throwsRangeError); | 106 expect(() => file.getText(10, 100), throwsRangeError); |
| 107 }); | 107 }); |
| 108 }); | 108 }); |
| 109 | 109 |
| 110 group("for span().union()", () { | 110 group("for span().union()", () { |
| 111 test("source URLs must match", () { | 111 test("source URLs must match", () { |
| 112 var other = new SourceSpan( | 112 var other = |
| 113 new SourceLocation(10), new SourceLocation(11), "_"); | 113 new SourceSpan(new SourceLocation(10), new SourceLocation(11), "_"); |
| 114 | 114 |
| 115 expect(() => file.span(9, 10).union(other), throwsArgumentError); | 115 expect(() => file.span(9, 10).union(other), throwsArgumentError); |
| 116 }); | 116 }); |
| 117 | 117 |
| 118 test("spans may not be disjoint", () { | 118 test("spans may not be disjoint", () { |
| 119 expect(() => file.span(9, 10).union(file.span(11, 12)), | 119 expect(() => file.span(9, 10).union(file.span(11, 12)), |
| 120 throwsArgumentError); | 120 throwsArgumentError); |
| 121 }); | 121 }); |
| 122 }); | 122 }); |
| 123 | 123 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 test("works with an external overlapping span", () { | 299 test("works with an external overlapping span", () { |
| 300 var other = file.span(0, 16); | 300 var other = file.span(0, 16); |
| 301 expect(span.union(other), equals(other)); | 301 expect(span.union(other), equals(other)); |
| 302 }); | 302 }); |
| 303 | 303 |
| 304 test("returns a FileSpan for a FileSpan input", () { | 304 test("returns a FileSpan for a FileSpan input", () { |
| 305 expect(span.union(file.span(0, 5)), new isInstanceOf<FileSpan>()); | 305 expect(span.union(file.span(0, 5)), new isInstanceOf<FileSpan>()); |
| 306 }); | 306 }); |
| 307 | 307 |
| 308 test("returns a base SourceSpan for a SourceSpan input", () { | 308 test("returns a base SourceSpan for a SourceSpan input", () { |
| 309 var other = new SourceSpan( | 309 var other = new SourceSpan(new SourceLocation(0, sourceUrl: "foo.dart"), |
| 310 new SourceLocation(0, sourceUrl: "foo.dart"), | 310 new SourceLocation(5, sourceUrl: "foo.dart"), "hey, "); |
| 311 new SourceLocation(5, sourceUrl: "foo.dart"), | |
| 312 "hey, "); | |
| 313 var result = span.union(other); | 311 var result = span.union(other); |
| 314 expect(result, isNot(new isInstanceOf<FileSpan>())); | 312 expect(result, isNot(new isInstanceOf<FileSpan>())); |
| 315 expect(result.start, equals(other.start)); | 313 expect(result.start, equals(other.start)); |
| 316 expect(result.end, equals(span.end)); | 314 expect(result.end, equals(span.end)); |
| 317 expect(result.text, equals("hey, ar baz\n")); | 315 expect(result.text, equals("hey, ar baz\n")); |
| 318 }); | 316 }); |
| 319 }); | 317 }); |
| 320 | 318 |
| 321 group("expand()", () { | 319 group("expand()", () { |
| 322 var span; | 320 var span; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 var other = file.span(7, 10); | 358 var other = file.span(7, 10); |
| 361 expect(span.expand(other), equals(span)); | 359 expect(span.expand(other), equals(span)); |
| 362 }); | 360 }); |
| 363 | 361 |
| 364 test("works with an external overlapping span", () { | 362 test("works with an external overlapping span", () { |
| 365 var other = file.span(0, 16); | 363 var other = file.span(0, 16); |
| 366 expect(span.expand(other), equals(other)); | 364 expect(span.expand(other), equals(other)); |
| 367 }); | 365 }); |
| 368 }); | 366 }); |
| 369 }); | 367 }); |
| 370 } | 368 } |
| OLD | NEW |