Run dartfmt --fix (#42)
Drops unnecessary `new`.
diff --git a/lib/src/file.dart b/lib/src/file.dart
index 27dae5d..5a193d3 100644
--- a/lib/src/file.dart
+++ b/lib/src/file.dart
@@ -72,7 +72,7 @@
/// or equal to `0xFFFF`.
SourceFile.decoded(Iterable<int> decodedChars, {url})
: url = url is String ? Uri.parse(url) : url,
- _decodedChars = new Uint32List.fromList(decodedChars.toList()) {
+ _decodedChars = Uint32List.fromList(decodedChars.toList()) {
for (var i = 0; i < _decodedChars.length; i++) {
var c = _decodedChars[i];
if (c == _CR) {
@@ -89,18 +89,18 @@
/// If [end] isn't passed, it defaults to the end of the file.
FileSpan span(int start, [int end]) {
if (end == null) end = length;
- return new _FileSpan(this, start, end);
+ return _FileSpan(this, start, end);
}
/// Returns a location in [this] at [offset].
- FileLocation location(int offset) => new FileLocation._(this, offset);
+ FileLocation location(int offset) => FileLocation._(this, offset);
/// Gets the 0-based line corresponding to [offset].
int getLine(int offset) {
if (offset < 0) {
- throw new RangeError("Offset may not be negative, was $offset.");
+ throw RangeError("Offset may not be negative, was $offset.");
} else if (offset > length) {
- throw new RangeError("Offset $offset must not be greater than the number "
+ throw RangeError("Offset $offset must not be greater than the number "
"of characters in the file, $length.");
}
@@ -163,24 +163,24 @@
/// is used to more efficiently compute the column.
int getColumn(int offset, {int line}) {
if (offset < 0) {
- throw new RangeError("Offset may not be negative, was $offset.");
+ throw RangeError("Offset may not be negative, was $offset.");
} else if (offset > length) {
- throw new RangeError("Offset $offset must be not be greater than the "
+ throw RangeError("Offset $offset must be not be greater than the "
"number of characters in the file, $length.");
}
if (line == null) {
line = getLine(offset);
} else if (line < 0) {
- throw new RangeError("Line may not be negative, was $line.");
+ throw RangeError("Line may not be negative, was $line.");
} else if (line >= lines) {
- throw new RangeError("Line $line must be less than the number of "
+ throw RangeError("Line $line must be less than the number of "
"lines in the file, $lines.");
}
var lineStart = _lineStarts[line];
if (lineStart > offset) {
- throw new RangeError("Line $line comes after offset $offset.");
+ throw RangeError("Line $line comes after offset $offset.");
}
return offset - lineStart;
@@ -193,18 +193,18 @@
if (column == null) column = 0;
if (line < 0) {
- throw new RangeError("Line may not be negative, was $line.");
+ throw RangeError("Line may not be negative, was $line.");
} else if (line >= lines) {
- throw new RangeError("Line $line must be less than the number of "
+ throw RangeError("Line $line must be less than the number of "
"lines in the file, $lines.");
} else if (column < 0) {
- throw new RangeError("Column may not be negative, was $column.");
+ throw RangeError("Column may not be negative, was $column.");
}
var result = _lineStarts[line] + column;
if (result > length ||
(line + 1 < lines && result >= _lineStarts[line + 1])) {
- throw new RangeError("Line $line doesn't have $column columns.");
+ throw RangeError("Line $line doesn't have $column columns.");
}
return result;
@@ -214,7 +214,7 @@
///
/// If [end] isn't passed, it defaults to the end of the file.
String getText(int start, [int end]) =>
- new String.fromCharCodes(_decodedChars.sublist(start, end));
+ String.fromCharCodes(_decodedChars.sublist(start, end));
}
/// A [SourceLocation] within a [SourceFile].
@@ -234,14 +234,14 @@
FileLocation._(this.file, this.offset) {
if (offset < 0) {
- throw new RangeError("Offset may not be negative, was $offset.");
+ throw RangeError("Offset may not be negative, was $offset.");
} else if (offset > file.length) {
- throw new RangeError("Offset $offset must not be greater than the number "
+ throw RangeError("Offset $offset must not be greater than the number "
"of characters in the file, ${file.length}.");
}
}
- FileSpan pointSpan() => new _FileSpan(file, offset, offset);
+ FileSpan pointSpan() => _FileSpan(file, offset, offset);
}
/// A [SourceSpan] within a [SourceFile].
@@ -288,8 +288,8 @@
Uri get sourceUrl => file.url;
int get length => _end - _start;
- FileLocation get start => new FileLocation._(file, _start);
- FileLocation get end => new FileLocation._(file, _end);
+ FileLocation get start => FileLocation._(file, _start);
+ FileLocation get end => FileLocation._(file, _end);
String get text => file.getText(_start, _end);
String get context {
@@ -327,12 +327,12 @@
_FileSpan(this.file, this._start, this._end) {
if (_end < _start) {
- throw new ArgumentError('End $_end must come after start $_start.');
+ throw ArgumentError('End $_end must come after start $_start.');
} else if (_end > file.length) {
- throw new RangeError("End $_end must not be greater than the number "
+ throw RangeError("End $_end must not be greater than the number "
"of characters in the file, ${file.length}.");
} else if (_start < 0) {
- throw new RangeError("Start may not be negative, was $_start.");
+ throw RangeError("Start may not be negative, was $_start.");
}
}
@@ -351,11 +351,11 @@
if (other is _FileSpan) {
if (this._start > other._end || other._start > this._end) {
- throw new ArgumentError("Spans $this and $other are disjoint.");
+ throw ArgumentError("Spans $this and $other are disjoint.");
}
} else {
if (this._start > other.end.offset || other.start.offset > this._end) {
- throw new ArgumentError("Spans $this and $other are disjoint.");
+ throw ArgumentError("Spans $this and $other are disjoint.");
}
}
@@ -382,18 +382,18 @@
/// between the two will be covered by the returned span.
FileSpan expand(FileSpan other) {
if (sourceUrl != other.sourceUrl) {
- throw new ArgumentError("Source URLs \"${sourceUrl}\" and "
+ throw ArgumentError("Source URLs \"${sourceUrl}\" and "
" \"${other.sourceUrl}\" don't match.");
}
if (other is _FileSpan) {
var start = math.min(this._start, other._start);
var end = math.max(this._end, other._end);
- return new _FileSpan(file, start, end);
+ return _FileSpan(file, start, end);
} else {
var start = math.min(this._start, other.start.offset);
var end = math.max(this._end, other.end.offset);
- return new _FileSpan(file, start, end);
+ return _FileSpan(file, start, end);
}
}
}
diff --git a/lib/src/highlighter.dart b/lib/src/highlighter.dart
index 0714acd..f68e52a 100644
--- a/lib/src/highlighter.dart
+++ b/lib/src/highlighter.dart
@@ -36,7 +36,7 @@
_multiline ? 3 : 1;
/// The buffer to which to write the result.
- final _buffer = new StringBuffer();
+ final _buffer = StringBuffer();
/// The number of spaces to render for hard tabs that appear in `_span.text`.
///
@@ -63,7 +63,7 @@
newSpan = _normalizeTrailingNewline(newSpan);
newSpan = _normalizeEndOfLine(newSpan);
- return new Highlighter._(newSpan, color);
+ return Highlighter._(newSpan, color);
}
/// Normalizes [span] to ensure that it's a [SourceSpanWithContext] whose
@@ -76,10 +76,10 @@
span is SourceSpanWithContext &&
findLineStart(span.context, span.text, span.start.column) != null
? span
- : new SourceSpanWithContext(
- new SourceLocation(span.start.offset,
+ : SourceSpanWithContext(
+ SourceLocation(span.start.offset,
sourceUrl: span.sourceUrl, line: 0, column: 0),
- new SourceLocation(span.end.offset,
+ SourceLocation(span.end.offset,
sourceUrl: span.sourceUrl,
line: countCodeUnits(span.text, $lf),
column: _lastLineLength(span.text)),
@@ -99,9 +99,9 @@
}
}
- return new SourceSpanWithContext(
+ return SourceSpanWithContext(
span.start,
- new SourceLocation(endOffset,
+ SourceLocation(endOffset,
sourceUrl: span.sourceUrl,
line: span.end.line,
column: span.end.column),
@@ -127,13 +127,13 @@
var end = span.end;
if (span.text.endsWith("\n") && _isTextAtEndOfContext(span)) {
text = span.text.substring(0, span.text.length - 1);
- end = new SourceLocation(span.end.offset - 1,
+ end = SourceLocation(span.end.offset - 1,
sourceUrl: span.sourceUrl,
line: span.end.line - 1,
column: _lastLineLength(text));
start = span.start.offset == span.end.offset ? end : span.start;
}
- return new SourceSpanWithContext(start, end, text, context);
+ return SourceSpanWithContext(start, end, text, context);
}
/// Normalizes [span] so that the end location is at the end of a line rather
@@ -144,9 +144,9 @@
var text = span.text.substring(0, span.text.length - 1);
- return new SourceSpanWithContext(
+ return SourceSpanWithContext(
span.start,
- new SourceLocation(span.end.offset - 1,
+ SourceLocation(span.end.offset - 1,
sourceUrl: span.sourceUrl,
line: span.end.line - 1,
column: _lastLineLength(text)),
diff --git a/lib/src/location.dart b/lib/src/location.dart
index cf99319..a271880 100644
--- a/lib/src/location.dart
+++ b/lib/src/location.dart
@@ -48,11 +48,11 @@
line = line == null ? 0 : line,
column = column == null ? offset : column {
if (offset < 0) {
- throw new RangeError("Offset may not be negative, was $offset.");
+ throw RangeError("Offset may not be negative, was $offset.");
} else if (line != null && line < 0) {
- throw new RangeError("Line may not be negative, was $line.");
+ throw RangeError("Line may not be negative, was $line.");
} else if (column != null && column < 0) {
- throw new RangeError("Column may not be negative, was $column.");
+ throw RangeError("Column may not be negative, was $column.");
}
}
@@ -61,21 +61,21 @@
/// This always returns a non-negative value.
int distance(SourceLocation other) {
if (sourceUrl != other.sourceUrl) {
- throw new ArgumentError("Source URLs \"${sourceUrl}\" and "
+ throw ArgumentError("Source URLs \"${sourceUrl}\" and "
"\"${other.sourceUrl}\" don't match.");
}
return (offset - other.offset).abs();
}
/// Returns a span that covers only a single point: this location.
- SourceSpan pointSpan() => new SourceSpan(this, this, "");
+ SourceSpan pointSpan() => SourceSpan(this, this, "");
/// Compares two locations.
///
/// [other] must have the same source URL as [this].
int compareTo(SourceLocation other) {
if (sourceUrl != other.sourceUrl) {
- throw new ArgumentError("Source URLs \"${sourceUrl}\" and "
+ throw ArgumentError("Source URLs \"${sourceUrl}\" and "
"\"${other.sourceUrl}\" don't match.");
}
return offset - other.offset;
diff --git a/lib/src/location_mixin.dart b/lib/src/location_mixin.dart
index 1e5fc66..7d34311 100644
--- a/lib/src/location_mixin.dart
+++ b/lib/src/location_mixin.dart
@@ -21,17 +21,17 @@
int distance(SourceLocation other) {
if (sourceUrl != other.sourceUrl) {
- throw new ArgumentError("Source URLs \"${sourceUrl}\" and "
+ throw ArgumentError("Source URLs \"${sourceUrl}\" and "
"\"${other.sourceUrl}\" don't match.");
}
return (offset - other.offset).abs();
}
- SourceSpan pointSpan() => new SourceSpan(this, this, "");
+ SourceSpan pointSpan() => SourceSpan(this, this, "");
int compareTo(SourceLocation other) {
if (sourceUrl != other.sourceUrl) {
- throw new ArgumentError("Source URLs \"${sourceUrl}\" and "
+ throw ArgumentError("Source URLs \"${sourceUrl}\" and "
"\"${other.sourceUrl}\" don't match.");
}
return offset - other.offset;
diff --git a/lib/src/span.dart b/lib/src/span.dart
index 57ffe79..b32e1ff 100644
--- a/lib/src/span.dart
+++ b/lib/src/span.dart
@@ -33,7 +33,7 @@
/// before [end]. [text] must have a number of characters equal to the
/// distance between [start] and [end].
factory SourceSpan(SourceLocation start, SourceLocation end, String text) =>
- new SourceSpanBase(start, end, text);
+ SourceSpanBase(start, end, text);
/// Creates a new span that's the union of [this] and [other].
///
@@ -91,12 +91,12 @@
SourceSpanBase(this.start, this.end, this.text) {
if (end.sourceUrl != start.sourceUrl) {
- throw new ArgumentError("Source URLs \"${start.sourceUrl}\" and "
+ throw ArgumentError("Source URLs \"${start.sourceUrl}\" and "
" \"${end.sourceUrl}\" don't match.");
} else if (end.offset < start.offset) {
- throw new ArgumentError('End $end must come after start $start.');
+ throw ArgumentError('End $end must come after start $start.');
} else if (text.length != start.distance(end)) {
- throw new ArgumentError('Text "$text" must be ${start.distance(end)} '
+ throw ArgumentError('Text "$text" must be ${start.distance(end)} '
'characters long.');
}
}
diff --git a/lib/src/span_mixin.dart b/lib/src/span_mixin.dart
index d8ac8f2..9bf0937 100644
--- a/lib/src/span_mixin.dart
+++ b/lib/src/span_mixin.dart
@@ -26,7 +26,7 @@
SourceSpan union(SourceSpan other) {
if (sourceUrl != other.sourceUrl) {
- throw new ArgumentError("Source URLs \"${sourceUrl}\" and "
+ throw ArgumentError("Source URLs \"${sourceUrl}\" and "
" \"${other.sourceUrl}\" don't match.");
}
@@ -36,16 +36,16 @@
var endSpan = end == this.end ? this : other;
if (beginSpan.end.compareTo(endSpan.start) < 0) {
- throw new ArgumentError("Spans $this and $other are disjoint.");
+ throw ArgumentError("Spans $this and $other are disjoint.");
}
var text = beginSpan.text +
endSpan.text.substring(beginSpan.end.distance(endSpan.start));
- return new SourceSpan(start, end, text);
+ return SourceSpan(start, end, text);
}
String message(String message, {color}) {
- var buffer = new StringBuffer();
+ var buffer = StringBuffer();
buffer.write('line ${start.line + 1}, column ${start.column + 1}');
if (sourceUrl != null) buffer.write(' of ${p.prettyUri(sourceUrl)}');
buffer.write(': $message');
@@ -61,7 +61,7 @@
String highlight({color}) {
if (this is! SourceSpanWithContext && this.length == 0) return "";
- return new Highlighter(this, color: color).highlight();
+ return Highlighter(this, color: color).highlight();
}
bool operator ==(other) =>
diff --git a/lib/src/span_with_context.dart b/lib/src/span_with_context.dart
index 41697a0..da09cc0 100644
--- a/lib/src/span_with_context.dart
+++ b/lib/src/span_with_context.dart
@@ -25,12 +25,11 @@
SourceLocation start, SourceLocation end, String text, this._context)
: super(start, end, text) {
if (!context.contains(text)) {
- throw new ArgumentError(
- 'The context line "$context" must contain "$text".');
+ throw ArgumentError('The context line "$context" must contain "$text".');
}
if (findLineStart(context, text, start.column) == null) {
- throw new ArgumentError('The span text "$text" must start at '
+ throw ArgumentError('The span text "$text" must start at '
'column ${start.column + 1} in a line within "$context".');
}
}
diff --git a/test/file_test.dart b/test/file_test.dart
index 9a103c4..6759ca2 100644
--- a/test/file_test.dart
+++ b/test/file_test.dart
@@ -8,7 +8,7 @@
main() {
var file;
setUp(() {
- file = new SourceFile.fromString("""
+ file = SourceFile.fromString("""
foo bar baz
whiz bang boom
zip zap zop""", url: "foo.dart");
@@ -109,8 +109,7 @@
group("for span().union()", () {
test("source URLs must match", () {
- var other =
- new SourceSpan(new SourceLocation(10), new SourceLocation(11), "_");
+ var other = SourceSpan(SourceLocation(10), SourceLocation(11), "_");
expect(() => file.span(9, 10).union(other), throwsArgumentError);
});
@@ -122,7 +121,7 @@
});
test("for span().expand() source URLs must match", () {
- var other = new SourceFile.fromString("""
+ var other = SourceFile.fromString("""
foo bar baz
whiz bang boom
zip zap zop""", url: "bar.dart").span(10, 11);
@@ -139,11 +138,11 @@
group("new SourceFile()", () {
test("handles CRLF correctly", () {
- expect(new SourceFile.fromString("foo\r\nbar").getLine(6), equals(1));
+ expect(SourceFile.fromString("foo\r\nbar").getLine(6), equals(1));
});
test("handles a lone CR correctly", () {
- expect(new SourceFile.fromString("foo\rbar").getLine(5), equals(1));
+ expect(SourceFile.fromString("foo\rbar").getLine(5), equals(1));
});
});
@@ -283,7 +282,7 @@
});
test("with a newline, contains an empty line", () {
- file = new SourceFile.fromString("""
+ file = SourceFile.fromString("""
foo bar baz
whiz bang boom
zip zap zop
@@ -348,8 +347,8 @@
});
test("returns a base SourceSpan for a SourceSpan input", () {
- var other = new SourceSpan(new SourceLocation(0, sourceUrl: "foo.dart"),
- new SourceLocation(5, sourceUrl: "foo.dart"), "hey, ");
+ var other = SourceSpan(SourceLocation(0, sourceUrl: "foo.dart"),
+ SourceLocation(5, sourceUrl: "foo.dart"), "hey, ");
var result = span.union(other);
expect(result, isNot(isA<FileSpan>()));
expect(result.start, equals(other.start));
diff --git a/test/highlight_test.dart b/test/highlight_test.dart
index 521f748..c215680 100644
--- a/test/highlight_test.dart
+++ b/test/highlight_test.dart
@@ -21,7 +21,7 @@
var file;
setUp(() {
- file = new SourceFile.fromString("""
+ file = SourceFile.fromString("""
foo bar baz
whiz bang boom
zip zap zop
@@ -37,7 +37,7 @@
});
test("gracefully handles a missing source URL", () {
- var span = new SourceFile.fromString("foo bar baz").span(4, 7);
+ var span = SourceFile.fromString("foo bar baz").span(4, 7);
expect(span.highlight(), equals("""
,
1 | foo bar baz
@@ -95,7 +95,7 @@
});
test("at the end of the file with no trailing newline", () {
- file = new SourceFile.fromString("zip zap zop");
+ file = SourceFile.fromString("zip zap zop");
expect(file.location(10).pointSpan().highlight(), equals("""
,
1 | zip zap zop
@@ -104,7 +104,7 @@
});
test("after the end of the file with no trailing newline", () {
- file = new SourceFile.fromString("zip zap zop");
+ file = SourceFile.fromString("zip zap zop");
expect(file.location(11).pointSpan().highlight(), equals("""
,
1 | zip zap zop
@@ -113,7 +113,7 @@
});
test("in an empty file", () {
- expect(new SourceFile.fromString("").location(0).pointSpan().highlight(),
+ expect(SourceFile.fromString("").location(0).pointSpan().highlight(),
equals("""
,
1 |
@@ -122,7 +122,7 @@
});
test("on an empty line", () {
- var file = new SourceFile.fromString("foo\n\nbar");
+ var file = SourceFile.fromString("foo\n\nbar");
expect(file.location(4).pointSpan().highlight(), equals("""
,
2 |
@@ -132,8 +132,7 @@
});
test("highlights a single-line file without a newline", () {
- expect(
- new SourceFile.fromString("foo bar").span(0, 7).highlight(), equals("""
+ expect(SourceFile.fromString("foo bar").span(0, 7).highlight(), equals("""
,
1 | foo bar
| ^^^^^^^
@@ -141,8 +140,8 @@
});
test("highlights a single empty line", () {
- expect(new SourceFile.fromString("foo\n\nbar").span(4, 5).highlight(),
- equals("""
+ expect(
+ SourceFile.fromString("foo\n\nbar").span(4, 5).highlight(), equals("""
,
2 |
| ^
@@ -194,7 +193,7 @@
});
test("highlights the full first line even if it's indented", () {
- var file = new SourceFile.fromString("""
+ var file = SourceFile.fromString("""
foo bar baz
whiz bang boom
zip zap zop
@@ -210,7 +209,7 @@
});
test("highlights the full first line if it's empty", () {
- var file = new SourceFile.fromString("""
+ var file = SourceFile.fromString("""
foo
bar
@@ -242,7 +241,7 @@
});
test("highlights the full last line with a trailing Windows newline", () {
- var file = new SourceFile.fromString("""
+ var file = SourceFile.fromString("""
foo bar baz\r
whiz bang boom\r
zip zap zop\r
@@ -269,7 +268,7 @@
test(
"highlights the full last line at the end of the file with no trailing "
"newline", () {
- var file = new SourceFile.fromString("""
+ var file = SourceFile.fromString("""
foo bar baz
whiz bang boom
zip zap zop""");
@@ -284,7 +283,7 @@
});
test("highlights the full last line if it's empty", () {
- var file = new SourceFile.fromString("""
+ var file = SourceFile.fromString("""
foo
bar
@@ -298,7 +297,7 @@
});
test("highlights multiple empty lines", () {
- var file = new SourceFile.fromString("foo\n\n\n\nbar");
+ var file = SourceFile.fromString("foo\n\n\n\nbar");
expect(file.span(4, 7).highlight(), equals("""
,
2 | /
@@ -309,7 +308,7 @@
// Regression test for #32
test("highlights the end of a line and an empty line", () {
- var file = new SourceFile.fromString("foo\n\n");
+ var file = SourceFile.fromString("foo\n\n");
expect(file.span(3, 5).highlight(), equals("""
,
1 | foo
@@ -322,7 +321,7 @@
group("prints tabs as spaces", () {
group("in a single-line span", () {
test("before the highlighted section", () {
- var span = new SourceFile.fromString("foo\tbar baz").span(4, 7);
+ var span = SourceFile.fromString("foo\tbar baz").span(4, 7);
expect(span.highlight(), equals("""
,
@@ -332,7 +331,7 @@
});
test("within the highlighted section", () {
- var span = new SourceFile.fromString("foo bar\tbaz bang").span(4, 11);
+ var span = SourceFile.fromString("foo bar\tbaz bang").span(4, 11);
expect(span.highlight(), equals("""
,
@@ -342,7 +341,7 @@
});
test("after the highlighted section", () {
- var span = new SourceFile.fromString("foo bar\tbaz").span(4, 7);
+ var span = SourceFile.fromString("foo bar\tbaz").span(4, 7);
expect(span.highlight(), equals("""
,
@@ -354,7 +353,7 @@
group("in a multi-line span", () {
test("before the highlighted section", () {
- var span = new SourceFile.fromString("""
+ var span = SourceFile.fromString("""
foo\tbar baz
whiz bang boom
""").span(4, 21);
@@ -369,7 +368,7 @@
});
test("within the first highlighted line", () {
- var span = new SourceFile.fromString("""
+ var span = SourceFile.fromString("""
foo bar\tbaz
whiz bang boom
""").span(4, 21);
@@ -384,7 +383,7 @@
});
test("within a middle highlighted line", () {
- var span = new SourceFile.fromString("""
+ var span = SourceFile.fromString("""
foo bar baz
whiz\tbang boom
zip zap zop
@@ -401,7 +400,7 @@
});
test("within the last highlighted line", () {
- var span = new SourceFile.fromString("""
+ var span = SourceFile.fromString("""
foo bar baz
whiz\tbang boom
""").span(4, 21);
@@ -416,7 +415,7 @@
});
test("after the highlighted section", () {
- var span = new SourceFile.fromString("""
+ var span = SourceFile.fromString("""
foo bar baz
whiz bang\tboom
""").span(4, 21);
@@ -434,9 +433,9 @@
group("supports lines of preceding and following context for a span", () {
test("within a single line", () {
- var span = new SourceSpanWithContext(
- new SourceLocation(20, line: 2, column: 5, sourceUrl: "foo.dart"),
- new SourceLocation(27, line: 2, column: 12, sourceUrl: "foo.dart"),
+ var span = SourceSpanWithContext(
+ SourceLocation(20, line: 2, column: 5, sourceUrl: "foo.dart"),
+ SourceLocation(27, line: 2, column: 12, sourceUrl: "foo.dart"),
"foo bar",
"previous\nlines\n-----foo bar-----\nfollowing line\n");
@@ -451,9 +450,9 @@
});
test("covering a full line", () {
- var span = new SourceSpanWithContext(
- new SourceLocation(15, line: 2, column: 0, sourceUrl: "foo.dart"),
- new SourceLocation(33, line: 3, column: 0, sourceUrl: "foo.dart"),
+ var span = SourceSpanWithContext(
+ SourceLocation(15, line: 2, column: 0, sourceUrl: "foo.dart"),
+ SourceLocation(33, line: 3, column: 0, sourceUrl: "foo.dart"),
"-----foo bar-----\n",
"previous\nlines\n-----foo bar-----\nfollowing line\n");
@@ -468,9 +467,9 @@
});
test("covering multiple full lines", () {
- var span = new SourceSpanWithContext(
- new SourceLocation(15, line: 2, column: 0, sourceUrl: "foo.dart"),
- new SourceLocation(23, line: 4, column: 0, sourceUrl: "foo.dart"),
+ var span = SourceSpanWithContext(
+ SourceLocation(15, line: 2, column: 0, sourceUrl: "foo.dart"),
+ SourceLocation(23, line: 4, column: 0, sourceUrl: "foo.dart"),
"foo\nbar\n",
"previous\nlines\nfoo\nbar\nfollowing line\n");
diff --git a/test/location_test.dart b/test/location_test.dart
index 3a32a92..9032936 100644
--- a/test/location_test.dart
+++ b/test/location_test.dart
@@ -8,33 +8,30 @@
main() {
var location;
setUp(() {
- location =
- new SourceLocation(15, line: 2, column: 6, sourceUrl: "foo.dart");
+ location = SourceLocation(15, line: 2, column: 6, sourceUrl: "foo.dart");
});
group('errors', () {
group('for new SourceLocation()', () {
test('offset may not be negative', () {
- expect(() => new SourceLocation(-1), throwsRangeError);
+ expect(() => SourceLocation(-1), throwsRangeError);
});
test('line may not be negative', () {
- expect(() => new SourceLocation(0, line: -1), throwsRangeError);
+ expect(() => SourceLocation(0, line: -1), throwsRangeError);
});
test('column may not be negative', () {
- expect(() => new SourceLocation(0, column: -1), throwsRangeError);
+ expect(() => SourceLocation(0, column: -1), throwsRangeError);
});
});
test('for distance() source URLs must match', () {
- expect(
- () => location.distance(new SourceLocation(0)), throwsArgumentError);
+ expect(() => location.distance(SourceLocation(0)), throwsArgumentError);
});
test('for compareTo() source URLs must match', () {
- expect(
- () => location.compareTo(new SourceLocation(0)), throwsArgumentError);
+ expect(() => location.compareTo(SourceLocation(0)), throwsArgumentError);
});
});
@@ -51,13 +48,13 @@
});
test('gracefully handles a missing source URL', () {
- var location = new SourceLocation(15, line: 2, column: 6);
+ var location = SourceLocation(15, line: 2, column: 6);
expect(location.toolString, equals('unknown source:3:7'));
});
});
test("distance returns the absolute distance between locations", () {
- var other = new SourceLocation(10, sourceUrl: "foo.dart");
+ var other = SourceLocation(10, sourceUrl: "foo.dart");
expect(location.distance(other), equals(5));
expect(other.distance(location), equals(5));
});
@@ -71,7 +68,7 @@
group("compareTo()", () {
test("sorts by offset", () {
- var other = new SourceLocation(20, sourceUrl: "foo.dart");
+ var other = SourceLocation(20, sourceUrl: "foo.dart");
expect(location.compareTo(other), lessThan(0));
expect(other.compareTo(location), greaterThan(0));
});
@@ -83,17 +80,17 @@
group("equality", () {
test("two locations with the same offset and source are equal", () {
- var other = new SourceLocation(15, sourceUrl: "foo.dart");
+ var other = SourceLocation(15, sourceUrl: "foo.dart");
expect(location, equals(other));
});
test("a different offset isn't equal", () {
- var other = new SourceLocation(10, sourceUrl: "foo.dart");
+ var other = SourceLocation(10, sourceUrl: "foo.dart");
expect(location, isNot(equals(other)));
});
test("a different source isn't equal", () {
- var other = new SourceLocation(15, sourceUrl: "bar.dart");
+ var other = SourceLocation(15, sourceUrl: "bar.dart");
expect(location, isNot(equals(other)));
});
});
diff --git a/test/span_test.dart b/test/span_test.dart
index 9989516..6a18b42 100644
--- a/test/span_test.dart
+++ b/test/span_test.dart
@@ -21,122 +21,114 @@
var span;
setUp(() {
- span = new SourceSpan(new SourceLocation(5, sourceUrl: "foo.dart"),
- new SourceLocation(12, sourceUrl: "foo.dart"), "foo bar");
+ span = SourceSpan(SourceLocation(5, sourceUrl: "foo.dart"),
+ SourceLocation(12, sourceUrl: "foo.dart"), "foo bar");
});
group('errors', () {
group('for new SourceSpan()', () {
test('source URLs must match', () {
- var start = new SourceLocation(0, sourceUrl: "foo.dart");
- var end = new SourceLocation(1, sourceUrl: "bar.dart");
- expect(() => new SourceSpan(start, end, "_"), throwsArgumentError);
+ var start = SourceLocation(0, sourceUrl: "foo.dart");
+ var end = SourceLocation(1, sourceUrl: "bar.dart");
+ expect(() => SourceSpan(start, end, "_"), throwsArgumentError);
});
test('end must come after start', () {
- var start = new SourceLocation(1);
- var end = new SourceLocation(0);
- expect(() => new SourceSpan(start, end, "_"), throwsArgumentError);
+ var start = SourceLocation(1);
+ var end = SourceLocation(0);
+ expect(() => SourceSpan(start, end, "_"), throwsArgumentError);
});
test('text must be the right length', () {
- var start = new SourceLocation(0);
- var end = new SourceLocation(1);
- expect(() => new SourceSpan(start, end, "abc"), throwsArgumentError);
+ var start = SourceLocation(0);
+ var end = SourceLocation(1);
+ expect(() => SourceSpan(start, end, "abc"), throwsArgumentError);
});
});
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--"),
+ var start = SourceLocation(2);
+ var end = SourceLocation(5);
+ expect(() => 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--"),
+ var start = SourceLocation(3);
+ var end = SourceLocation(5);
+ expect(() => SourceSpanWithContext(start, end, "abc", "--abc--"),
throwsArgumentError);
});
test('text starts at start.column of line in multi-line context', () {
- var start = new SourceLocation(4, line: 55, column: 3);
- var end = new SourceLocation(7, line: 55, column: 6);
- expect(() => new SourceSpanWithContext(start, end, "abc", "\n--abc--"),
+ var start = SourceLocation(4, line: 55, column: 3);
+ var end = SourceLocation(7, line: 55, column: 6);
+ expect(() => SourceSpanWithContext(start, end, "abc", "\n--abc--"),
throwsArgumentError);
- expect(
- () => new SourceSpanWithContext(start, end, "abc", "\n----abc--"),
+ expect(() => SourceSpanWithContext(start, end, "abc", "\n----abc--"),
throwsArgumentError);
- expect(
- () => new SourceSpanWithContext(start, end, "abc", "\n\n--abc--"),
+ expect(() => SourceSpanWithContext(start, end, "abc", "\n\n--abc--"),
throwsArgumentError);
// However, these are valid:
- new SourceSpanWithContext(start, end, "abc", "\n---abc--");
- new SourceSpanWithContext(start, end, "abc", "\n\n---abc--");
+ SourceSpanWithContext(start, end, "abc", "\n---abc--");
+ SourceSpanWithContext(start, end, "abc", "\n\n---abc--");
});
test('text can occur multiple times in context', () {
- var start1 = new SourceLocation(4, line: 55, column: 2);
- var end1 = new SourceLocation(7, line: 55, column: 5);
- var start2 = new SourceLocation(4, line: 55, column: 8);
- var end2 = new SourceLocation(7, line: 55, column: 11);
- new SourceSpanWithContext(start1, end1, "abc", "--abc---abc--\n");
- new SourceSpanWithContext(start1, end1, "abc", "--abc--abc--\n");
- new SourceSpanWithContext(start2, end2, "abc", "--abc---abc--\n");
- new SourceSpanWithContext(start2, end2, "abc", "---abc--abc--\n");
+ var start1 = SourceLocation(4, line: 55, column: 2);
+ var end1 = SourceLocation(7, line: 55, column: 5);
+ var start2 = SourceLocation(4, line: 55, column: 8);
+ var end2 = SourceLocation(7, line: 55, column: 11);
+ SourceSpanWithContext(start1, end1, "abc", "--abc---abc--\n");
+ SourceSpanWithContext(start1, end1, "abc", "--abc--abc--\n");
+ SourceSpanWithContext(start2, end2, "abc", "--abc---abc--\n");
+ SourceSpanWithContext(start2, end2, "abc", "---abc--abc--\n");
expect(
- () => new SourceSpanWithContext(
- start1, end1, "abc", "---abc--abc--\n"),
+ () => SourceSpanWithContext(start1, end1, "abc", "---abc--abc--\n"),
throwsArgumentError);
expect(
- () => new SourceSpanWithContext(
- start2, end2, "abc", "--abc--abc--\n"),
+ () => SourceSpanWithContext(start2, end2, "abc", "--abc--abc--\n"),
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"),
- "_");
+ var other = SourceSpan(SourceLocation(12, sourceUrl: "bar.dart"),
+ SourceLocation(13, sourceUrl: "bar.dart"), "_");
expect(() => span.union(other), throwsArgumentError);
});
test('spans may not be disjoint', () {
- var other = new SourceSpan(
- new SourceLocation(13, sourceUrl: 'foo.dart'),
- new SourceLocation(14, sourceUrl: 'foo.dart'),
- "_");
+ var other = SourceSpan(SourceLocation(13, sourceUrl: 'foo.dart'),
+ 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 = SourceSpan(SourceLocation(12, sourceUrl: "bar.dart"),
+ SourceLocation(13, sourceUrl: "bar.dart"), "_");
expect(() => span.compareTo(other), throwsArgumentError);
});
});
test('fields work correctly', () {
- expect(span.start, equals(new SourceLocation(5, sourceUrl: "foo.dart")));
- expect(span.end, equals(new SourceLocation(12, sourceUrl: "foo.dart")));
+ expect(span.start, equals(SourceLocation(5, sourceUrl: "foo.dart")));
+ expect(span.end, equals(SourceLocation(12, sourceUrl: "foo.dart")));
expect(span.sourceUrl, equals(Uri.parse("foo.dart")));
expect(span.length, equals(7));
});
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 = SourceSpan(SourceLocation(0, sourceUrl: "foo.dart"),
+ SourceLocation(5, sourceUrl: "foo.dart"), "hey, ");
var result = span.union(other);
expect(result.start, equals(other.start));
@@ -145,8 +137,8 @@
});
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 = SourceSpan(SourceLocation(0, sourceUrl: "foo.dart"),
+ SourceLocation(8, sourceUrl: "foo.dart"), "hey, foo");
var result = span.union(other);
expect(result.start, equals(other.start));
@@ -155,8 +147,8 @@
});
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 = SourceSpan(SourceLocation(12, sourceUrl: "foo.dart"),
+ SourceLocation(16, sourceUrl: "foo.dart"), " baz");
var result = span.union(other);
expect(result.start, equals(span.start));
@@ -165,8 +157,8 @@
});
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 = SourceSpan(SourceLocation(9, sourceUrl: "foo.dart"),
+ SourceLocation(16, sourceUrl: "foo.dart"), "bar baz");
var result = span.union(other);
expect(result.start, equals(span.start));
@@ -175,15 +167,15 @@
});
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 = SourceSpan(SourceLocation(7, sourceUrl: "foo.dart"),
+ 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 = SourceSpan(SourceLocation(0, sourceUrl: "foo.dart"),
+ SourceLocation(16, sourceUrl: "foo.dart"), "hey, foo bar baz");
expect(span.union(other), equals(other));
});
@@ -200,8 +192,7 @@
});
test("gracefully handles a missing source URL", () {
- var span = new SourceSpan(
- new SourceLocation(5), new SourceLocation(12), "foo bar");
+ var span = SourceSpan(SourceLocation(5), SourceLocation(12), "foo bar");
expect(span.message("oh no"), equalsIgnoringWhitespace("""
line 1, column 6: oh no
@@ -212,8 +203,7 @@
});
test("gracefully handles empty text", () {
- var span =
- new SourceSpan(new SourceLocation(5), new SourceLocation(5), "");
+ var span = SourceSpan(SourceLocation(5), SourceLocation(5), "");
expect(span.message("oh no"), equals("line 1, column 6: oh no"));
});
@@ -246,9 +236,9 @@
});
test("with context, underlines the right column", () {
- var spanWithContext = new SourceSpanWithContext(
- new SourceLocation(5, sourceUrl: "foo.dart"),
- new SourceLocation(12, sourceUrl: "foo.dart"),
+ var spanWithContext = SourceSpanWithContext(
+ SourceLocation(5, sourceUrl: "foo.dart"),
+ SourceLocation(12, sourceUrl: "foo.dart"),
"foo bar",
"-----foo bar-----");
@@ -263,16 +253,16 @@
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 = SourceSpan(SourceLocation(6, sourceUrl: "foo.dart"),
+ 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 = SourceSpan(SourceLocation(5, sourceUrl: "foo.dart"),
+ SourceLocation(14, sourceUrl: "foo.dart"), "foo bar b");
expect(span.compareTo(other), lessThan(0));
expect(other.compareTo(span), greaterThan(0));
@@ -285,29 +275,29 @@
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 = SourceSpan(SourceLocation(5, sourceUrl: "foo.dart"),
+ 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 = SourceSpan(SourceLocation(0, sourceUrl: "foo.dart"),
+ 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 = SourceSpan(SourceLocation(5, sourceUrl: "foo.dart"),
+ 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 = SourceSpan(SourceLocation(5, sourceUrl: "bar.dart"),
+ SourceLocation(12, sourceUrl: "bar.dart"), "foo bar");
expect(span, isNot(equals(other)));
});