Fix FileSpan.context to include FileSpan.text.
R=nweiz@google.com
Review URL: https://codereview.chromium.org//1039603004
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ab52c8..e749513 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# 1.1.1
+
+* Fixed `FileSpan`'s context to include the full span text, not just the first
+ line of it.
+
# 1.1.0
* Added `SourceSpanWithContext`: a span that also includes the full line of text
diff --git a/lib/src/file.dart b/lib/src/file.dart
index c7e5898..4b4e026 100644
--- a/lib/src/file.dart
+++ b/lib/src/file.dart
@@ -205,12 +205,8 @@
FileLocation get start => new FileLocation._(file, _start);
FileLocation get end => new FileLocation._(file, _end);
String get text => file.getText(_start, _end);
-
- String get context {
- var line = start.line;
- return file.getText(file.getOffset(line),
- line == file.lines - 1 ? null : file.getOffset(line + 1));
- }
+ String get context => file.getText(file.getOffset(start.line),
+ end.line == file.lines - 1 ? null : file.getOffset(end.line + 1));
FileSpan._(this.file, this._start, this._end) {
if (_end < _start) {
diff --git a/pubspec.yaml b/pubspec.yaml
index 887c040..73c2667 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: source_span
-version: 1.1.0
+version: 1.1.1
author: Dart Team <misc@dartlang.org>
description: A library for identifying source spans and locations.
homepage: http://github.com/dart-lang/source_span
diff --git a/test/file_test.dart b/test/file_test.dart
index 114a17e..c27c1f6 100644
--- a/test/file_test.dart
+++ b/test/file_test.dart
@@ -253,6 +253,12 @@
expect(file.span(8, 15).text, equals("baz\nwhi"));
});
+ test("context contains the span's text", () {
+ var span = file.span(8, 15);
+ expect(span.context.contains(span.text), isTrue);
+ expect(span.context, equals('foo bar baz\nwhiz bang boom\n'));
+ });
+
group("union()", () {
var span;
setUp(() {
@@ -367,4 +373,4 @@
});
});
});
-}
\ No newline at end of file
+}