| 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 location; | 9 var location; |
| 10 setUp(() { | 10 setUp(() { |
| 11 location = new SourceLocation(15, | 11 location = |
| 12 line: 2, column: 6, sourceUrl: "foo.dart"); | 12 new SourceLocation(15, line: 2, column: 6, sourceUrl: "foo.dart"); |
| 13 }); | 13 }); |
| 14 | 14 |
| 15 group('errors', () { | 15 group('errors', () { |
| 16 group('for new SourceLocation()', () { | 16 group('for new SourceLocation()', () { |
| 17 test('offset may not be negative', () { | 17 test('offset may not be negative', () { |
| 18 expect(() => new SourceLocation(-1), throwsRangeError); | 18 expect(() => new SourceLocation(-1), throwsRangeError); |
| 19 }); | 19 }); |
| 20 | 20 |
| 21 test('line may not be negative', () { | 21 test('line may not be negative', () { |
| 22 expect(() => new SourceLocation(0, line: -1), throwsRangeError); | 22 expect(() => new SourceLocation(0, line: -1), throwsRangeError); |
| 23 }); | 23 }); |
| 24 | 24 |
| 25 test('column may not be negative', () { | 25 test('column may not be negative', () { |
| 26 expect(() => new SourceLocation(0, column: -1), throwsRangeError); | 26 expect(() => new SourceLocation(0, column: -1), throwsRangeError); |
| 27 }); | 27 }); |
| 28 }); | 28 }); |
| 29 | 29 |
| 30 test('for distance() source URLs must match', () { | 30 test('for distance() source URLs must match', () { |
| 31 expect(() => location.distance(new SourceLocation(0)), | 31 expect( |
| 32 throwsArgumentError); | 32 () => location.distance(new SourceLocation(0)), throwsArgumentError); |
| 33 }); | 33 }); |
| 34 | 34 |
| 35 test('for compareTo() source URLs must match', () { | 35 test('for compareTo() source URLs must match', () { |
| 36 expect(() => location.compareTo(new SourceLocation(0)), | 36 expect( |
| 37 throwsArgumentError); | 37 () => location.compareTo(new SourceLocation(0)), throwsArgumentError); |
| 38 }); | 38 }); |
| 39 }); | 39 }); |
| 40 | 40 |
| 41 test('fields work correctly', () { | 41 test('fields work correctly', () { |
| 42 expect(location.sourceUrl, equals(Uri.parse("foo.dart"))); | 42 expect(location.sourceUrl, equals(Uri.parse("foo.dart"))); |
| 43 expect(location.offset, equals(15)); | 43 expect(location.offset, equals(15)); |
| 44 expect(location.line, equals(2)); | 44 expect(location.line, equals(2)); |
| 45 expect(location.column, equals(6)); | 45 expect(location.column, equals(6)); |
| 46 }); | 46 }); |
| 47 | 47 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 74 var other = new SourceLocation(20, sourceUrl: "foo.dart"); | 74 var other = new SourceLocation(20, sourceUrl: "foo.dart"); |
| 75 expect(location.compareTo(other), lessThan(0)); | 75 expect(location.compareTo(other), lessThan(0)); |
| 76 expect(other.compareTo(location), greaterThan(0)); | 76 expect(other.compareTo(location), greaterThan(0)); |
| 77 }); | 77 }); |
| 78 | 78 |
| 79 test("considers equal locations equal", () { | 79 test("considers equal locations equal", () { |
| 80 expect(location.compareTo(location), equals(0)); | 80 expect(location.compareTo(location), equals(0)); |
| 81 }); | 81 }); |
| 82 }); | 82 }); |
| 83 | 83 |
| 84 | |
| 85 group("equality", () { | 84 group("equality", () { |
| 86 test("two locations with the same offset and source are equal", () { | 85 test("two locations with the same offset and source are equal", () { |
| 87 var other = new SourceLocation(15, sourceUrl: "foo.dart"); | 86 var other = new SourceLocation(15, sourceUrl: "foo.dart"); |
| 88 expect(location, equals(other)); | 87 expect(location, equals(other)); |
| 89 }); | 88 }); |
| 90 | 89 |
| 91 test("a different offset isn't equal", () { | 90 test("a different offset isn't equal", () { |
| 92 var other = new SourceLocation(10, sourceUrl: "foo.dart"); | 91 var other = new SourceLocation(10, sourceUrl: "foo.dart"); |
| 93 expect(location, isNot(equals(other))); | 92 expect(location, isNot(equals(other))); |
| 94 }); | 93 }); |
| 95 | 94 |
| 96 test("a different source isn't equal", () { | 95 test("a different source isn't equal", () { |
| 97 var other = new SourceLocation(15, sourceUrl: "bar.dart"); | 96 var other = new SourceLocation(15, sourceUrl: "bar.dart"); |
| 98 expect(location, isNot(equals(other))); | 97 expect(location, isNot(equals(other))); |
| 99 }); | 98 }); |
| 100 }); | 99 }); |
| 101 } | 100 } |
| OLD | NEW |