SourceFile.span() should include last char when end offset omitted (#28)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 489f01a..44c3ca5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+# 1.5.2
+
+* `SourceFile.span()` now goes to the end of the file by default, rather than
+ ending one character before the end of the file. This matches the documented
+ behavior.
+
# 1.5.1
* Produce better source span highlights for multi-line spans that cover the
diff --git a/lib/src/file.dart b/lib/src/file.dart
index 18c46e6..3941042 100644
--- a/lib/src/file.dart
+++ b/lib/src/file.dart
@@ -88,7 +88,7 @@
///
/// If [end] isn't passed, it defaults to the end of the file.
FileSpan span(int start, [int end]) {
- if (end == null) end = length - 1;
+ if (end == null) end = length;
return new _FileSpan(this, start, end);
}
diff --git a/pubspec.yaml b/pubspec.yaml
index fc5ba2b..ffd9df3 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: source_span
-version: 1.5.1
+version: 1.5.2-dev
description: A library for identifying source spans and locations.
author: Dart Team <misc@dartlang.org>
diff --git a/test/file_test.dart b/test/file_test.dart
index 071f3f9..3f32a3c 100644
--- a/test/file_test.dart
+++ b/test/file_test.dart
@@ -157,7 +157,7 @@
test("end defaults to the end of the file", () {
var span = file.span(5);
expect(span.start, equals(file.location(5)));
- expect(span.end, equals(file.location(file.length - 1)));
+ expect(span.end, equals(file.location(file.length)));
});
});
@@ -253,6 +253,10 @@
expect(file.span(8, 15).text, equals("baz\nwhi"));
});
+ test("text includes the last char when end is defaulted to EOF", () {
+ expect(file.span(29).text, equals("p zap zop"));
+ });
+
test("context contains the span's text", () {
var span = file.span(8, 15);
expect(span.context.contains(span.text), isTrue);