From eaf5817b8d5a2a8bbc13d6d31224a05ed31018b7 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 5 Dec 2019 14:32:41 -0800 Subject: [PATCH] Fix latest pedantic lints, remove deprecated author field in pubspec (#17) --- analysis_options.yaml | 2 -- example/example.dart | 8 +++--- lib/src/eager_span_scanner.dart | 17 +++++++++--- lib/src/exception.dart | 1 + lib/src/line_scanner.dart | 10 ++++--- lib/src/relative_span_scanner.dart | 17 ++++++++++-- lib/src/span_scanner.dart | 13 +++++++-- lib/src/string_scanner.dart | 12 ++++----- lib/src/utils.dart | 12 ++++----- pubspec.yaml | 1 - test/error_test.dart | 30 ++++++++++----------- test/line_scanner_test.dart | 38 +++++++++++++-------------- test/span_scanner_test.dart | 42 +++++++++++++++--------------- test/string_scanner_test.dart | 40 ++++++++++++++-------------- 14 files changed, 139 insertions(+), 104 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 6e8826ba96f15..c9899f2e2541a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -5,7 +5,6 @@ analyzer: linter: rules: - always_declare_return_types - #- annotate_overrides - avoid_bool_literals_in_conditional_expressions - avoid_classes_with_only_static_members - avoid_empty_else @@ -68,7 +67,6 @@ linter: - prefer_is_empty - prefer_is_not_empty - prefer_null_aware_operators - #- prefer_single_quotes - prefer_typing_uninitialized_variables - recursive_getters - slash_for_doc_comments diff --git a/example/example.dart b/example/example.dart index ddd9d3ead4b4a..0358967e42140 100644 --- a/example/example.dart +++ b/example/example.dart @@ -16,18 +16,18 @@ num parseNumber(String source) { // [Scanner.scan] tries to consume a [Pattern] and returns whether or not it // succeeded. It will move the scan pointer past the end of the pattern. - var negative = scanner.scan("-"); + var negative = scanner.scan('-'); // [Scanner.expect] consumes a [Pattern] and throws a [FormatError] if it // fails. Like [Scanner.scan], it will move the scan pointer forward. - scanner.expect(RegExp(r"\d+")); + scanner.expect(RegExp(r'\d+')); // [Scanner.lastMatch] holds the [MatchData] for the most recent call to // [Scanner.scan], [Scanner.expect], or [Scanner.matches]. var number = num.parse(scanner.lastMatch[0]); - if (scanner.scan(".")) { - scanner.expect(RegExp(r"\d+")); + if (scanner.scan('.')) { + scanner.expect(RegExp(r'\d+')); var decimal = scanner.lastMatch[0]; number += int.parse(decimal) / math.pow(10, decimal.length); } diff --git a/lib/src/eager_span_scanner.dart b/lib/src/eager_span_scanner.dart index a2df0f8806053..d34e4f7c39018 100644 --- a/lib/src/eager_span_scanner.dart +++ b/lib/src/eager_span_scanner.dart @@ -11,26 +11,30 @@ import 'span_scanner.dart'; // sdk#23770 is fully complete, we should move the shared code into a mixin. /// A regular expression matching newlines across platforms. -final _newlineRegExp = RegExp(r"\r\n?|\n"); +final _newlineRegExp = RegExp(r'\r\n?|\n'); /// A [SpanScanner] that tracks the line and column eagerly, like [LineScanner]. class EagerSpanScanner extends SpanScanner { + @override int get line => _line; int _line = 0; + @override int get column => _column; int _column = 0; + @override LineScannerState get state => _EagerSpanScannerState(this, position, line, column); bool get _betweenCRLF => peekChar(-1) == $cr && peekChar() == $lf; + @override set state(LineScannerState state) { if (state is! _EagerSpanScannerState || !identical((state as _EagerSpanScannerState)._scanner, this)) { - throw ArgumentError("The given LineScannerState was not returned by " - "this LineScanner."); + throw ArgumentError('The given LineScannerState was not returned by ' + 'this LineScanner.'); } super.position = state.position; @@ -38,6 +42,7 @@ class EagerSpanScanner extends SpanScanner { _column = state.column; } + @override set position(int newPosition) { var oldPosition = position; super.position = newPosition; @@ -67,12 +72,14 @@ class EagerSpanScanner extends SpanScanner { EagerSpanScanner(String string, {sourceUrl, int position}) : super(string, sourceUrl: sourceUrl, position: position); + @override bool scanChar(int character) { if (!super.scanChar(character)) return false; _adjustLineAndColumn(character); return true; } + @override int readChar() { var character = super.readChar(); _adjustLineAndColumn(character); @@ -89,6 +96,7 @@ class EagerSpanScanner extends SpanScanner { } } + @override bool scan(Pattern pattern) { if (!super.scan(pattern)) return false; @@ -115,8 +123,11 @@ class EagerSpanScanner extends SpanScanner { /// A class representing the state of an [EagerSpanScanner]. class _EagerSpanScannerState implements LineScannerState { final EagerSpanScanner _scanner; + @override final int position; + @override final int line; + @override final int column; _EagerSpanScannerState(this._scanner, this.position, this.line, this.column); diff --git a/lib/src/exception.dart b/lib/src/exception.dart index bad08f6e212d6..8c994b5aefe81 100644 --- a/lib/src/exception.dart +++ b/lib/src/exception.dart @@ -8,6 +8,7 @@ import 'string_scanner.dart'; /// An exception thrown by a [StringScanner] that failed to parse a string. class StringScannerException extends SourceSpanFormatException { + @override String get source => super.source as String; /// The URL of the source file being parsed. diff --git a/lib/src/line_scanner.dart b/lib/src/line_scanner.dart index e16302a062f85..180d9239bda8b 100644 --- a/lib/src/line_scanner.dart +++ b/lib/src/line_scanner.dart @@ -9,7 +9,7 @@ import 'string_scanner.dart'; // Note that much of this code is duplicated in eager_span_scanner.dart. /// A regular expression matching newlines across platforms. -final _newlineRegExp = RegExp(r"\r\n?|\n"); +final _newlineRegExp = RegExp(r'\r\n?|\n'); /// A subclass of [StringScanner] that tracks line and column information. class LineScanner extends StringScanner { @@ -37,8 +37,8 @@ class LineScanner extends StringScanner { set state(LineScannerState state) { if (!identical(state._scanner, this)) { - throw ArgumentError("The given LineScannerState was not returned by " - "this LineScanner."); + throw ArgumentError('The given LineScannerState was not returned by ' + 'this LineScanner.'); } super.position = state.position; @@ -46,6 +46,7 @@ class LineScanner extends StringScanner { _column = state.column; } + @override set position(int newPosition) { var oldPosition = position; super.position = newPosition; @@ -75,12 +76,14 @@ class LineScanner extends StringScanner { LineScanner(String string, {sourceUrl, int position}) : super(string, sourceUrl: sourceUrl, position: position); + @override bool scanChar(int character) { if (!super.scanChar(character)) return false; _adjustLineAndColumn(character); return true; } + @override int readChar() { var character = super.readChar(); _adjustLineAndColumn(character); @@ -97,6 +100,7 @@ class LineScanner extends StringScanner { } } + @override bool scan(Pattern pattern) { if (!super.scan(pattern)) return false; diff --git a/lib/src/relative_span_scanner.dart b/lib/src/relative_span_scanner.dart index 1a992e41b4ed9..096bee3ad4f6b 100644 --- a/lib/src/relative_span_scanner.dart +++ b/lib/src/relative_span_scanner.dart @@ -27,10 +27,12 @@ class RelativeSpanScanner extends StringScanner implements SpanScanner { /// This is used to convert between span-relative and file-relative fields. final FileLocation _startLocation; + @override int get line => _sourceFile.getLine(_startLocation.offset + position) - _startLocation.line; + @override int get column { var line = _sourceFile.getLine(_startLocation.offset + position); var column = @@ -40,24 +42,29 @@ class RelativeSpanScanner extends StringScanner implements SpanScanner { : column; } + @override LineScannerState get state => _SpanScannerState(this, position); + @override set state(LineScannerState state) { if (state is! _SpanScannerState || !identical((state as _SpanScannerState)._scanner, this)) { - throw ArgumentError("The given LineScannerState was not returned by " - "this LineScanner."); + throw ArgumentError('The given LineScannerState was not returned by ' + 'this LineScanner.'); } position = state.position; } + @override FileSpan get lastSpan => _lastSpan; FileSpan _lastSpan; + @override FileLocation get location => _sourceFile.location(_startLocation.offset + position); + @override FileSpan get emptySpan => location.pointSpan(); RelativeSpanScanner(FileSpan span) @@ -65,12 +72,14 @@ class RelativeSpanScanner extends StringScanner implements SpanScanner { _startLocation = span.start, super(span.text, sourceUrl: span.sourceUrl); + @override FileSpan spanFrom(LineScannerState startState, [LineScannerState endState]) { var endPosition = endState == null ? position : endState.position; return _sourceFile.span(_startLocation.offset + startState.position, _startLocation.offset + endPosition); } + @override bool matches(Pattern pattern) { if (!super.matches(pattern)) { _lastSpan = null; @@ -82,6 +91,7 @@ class RelativeSpanScanner extends StringScanner implements SpanScanner { return true; } + @override void error(String message, {Match match, int position, int length}) { validateErrorArgs(string, match, position, length); @@ -100,8 +110,11 @@ class _SpanScannerState implements LineScannerState { /// The [SpanScanner] that created this. final RelativeSpanScanner _scanner; + @override final int position; + @override int get line => _scanner._sourceFile.getLine(position); + @override int get column => _scanner._sourceFile.getColumn(position); _SpanScannerState(this._scanner, this.position); diff --git a/lib/src/span_scanner.dart b/lib/src/span_scanner.dart index d332216267a5c..732a76f18fbf9 100644 --- a/lib/src/span_scanner.dart +++ b/lib/src/span_scanner.dart @@ -19,16 +19,20 @@ class SpanScanner extends StringScanner implements LineScanner { /// This caches line break information and is used to generate [FileSpan]s. final SourceFile _sourceFile; + @override int get line => _sourceFile.getLine(position); + @override int get column => _sourceFile.getColumn(position); + @override LineScannerState get state => _SpanScannerState(this, position); + @override set state(LineScannerState state) { if (state is! _SpanScannerState || !identical((state as _SpanScannerState)._scanner, this)) { - throw ArgumentError("The given LineScannerState was not returned by " - "this LineScanner."); + throw ArgumentError('The given LineScannerState was not returned by ' + 'this LineScanner.'); } position = state.position; @@ -89,6 +93,7 @@ class SpanScanner extends StringScanner implements LineScanner { return _sourceFile.span(startState.position, endPosition); } + @override bool matches(Pattern pattern) { if (!super.matches(pattern)) { _lastSpan = null; @@ -99,6 +104,7 @@ class SpanScanner extends StringScanner implements LineScanner { return true; } + @override void error(String message, {Match match, int position, int length}) { validateErrorArgs(string, match, position, length); @@ -116,8 +122,11 @@ class _SpanScannerState implements LineScannerState { /// The [SpanScanner] that created this. final SpanScanner _scanner; + @override final int position; + @override int get line => _scanner._sourceFile.getLine(position); + @override int get column => _scanner._sourceFile.getColumn(position); _SpanScannerState(this._scanner, this.position); diff --git a/lib/src/string_scanner.dart b/lib/src/string_scanner.dart index 4a1d10c0cccc7..1739a7cd4fcca 100644 --- a/lib/src/string_scanner.dart +++ b/lib/src/string_scanner.dart @@ -24,7 +24,7 @@ class StringScanner { int get position => _position; set position(int position) { if (position < 0 || position > string.length) { - throw ArgumentError("Invalid position $position"); + throw ArgumentError('Invalid position $position'); } _position = position; @@ -68,7 +68,7 @@ class StringScanner { /// This throws a [FormatException] if the string has been fully consumed. It /// doesn't affect [lastMatch]. int readChar() { - if (isDone) _fail("more input"); + if (isDone) _fail('more input'); return string.codeUnitAt(_position++); } @@ -144,10 +144,10 @@ class StringScanner { if (name == null) { if (pattern is RegExp) { var source = pattern.pattern; - name = "/$source/"; + name = '/$source/'; } else { name = - pattern.toString().replaceAll("\\", "\\\\").replaceAll('"', '\\"'); + pattern.toString().replaceAll('\\', '\\\\').replaceAll('"', '\\"'); name = '"$name"'; } } @@ -158,7 +158,7 @@ class StringScanner { /// [FormatException]. void expectDone() { if (isDone) return; - _fail("no more input"); + _fail('no more input'); } /// Returns whether or not [pattern] matches at the current position of the @@ -210,6 +210,6 @@ class StringScanner { /// Throws a [FormatException] describing that [name] is expected at the /// current position in the string. void _fail(String name) { - error("expected $name.", position: position, length: 0); + error('expected $name.', position: position, length: 0); } } diff --git a/lib/src/utils.dart b/lib/src/utils.dart index df29ba21b742a..7fe3d52416abf 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -12,19 +12,19 @@ void validateErrorArgs(String string, Match match, int position, int length) { if (position != null) { if (position < 0) { - throw RangeError("position must be greater than or equal to 0."); + throw RangeError('position must be greater than or equal to 0.'); } else if (position > string.length) { - throw RangeError("position must be less than or equal to the " - "string length."); + throw RangeError('position must be less than or equal to the ' + 'string length.'); } } if (length != null && length < 0) { - throw RangeError("length must be greater than or equal to 0."); + throw RangeError('length must be greater than or equal to 0.'); } if (position != null && length != null && position + length > string.length) { - throw RangeError("position plus length must not go beyond the end of " - "the string."); + throw RangeError('position plus length must not go beyond the end of ' + 'the string.'); } } diff --git a/pubspec.yaml b/pubspec.yaml index 6cba21e76230e..d5cefceda7d60 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,6 @@ name: string_scanner version: 1.0.5 description: A class for parsing strings using a sequence of patterns. -author: Dart Team homepage: https://github.com/dart-lang/string_scanner environment: diff --git a/test/error_test.dart b/test/error_test.dart index b966b1bca550a..dfa71755c5627 100644 --- a/test/error_test.dart +++ b/test/error_test.dart @@ -15,7 +15,7 @@ void main() { expect(() => scanner.error('oh no!'), throwsStringScannerException('bar')); }); - group("with match", () { + group('with match', () { test('supports an earlier match', () { var scanner = StringScanner('foo bar baz'); scanner.expect('foo '); @@ -56,7 +56,7 @@ void main() { }); }); - group("with position and/or length", () { + group('with position and/or length', () { test('defaults to length 0', () { var scanner = StringScanner('foo bar baz'); scanner.expect('foo '); @@ -105,39 +105,39 @@ void main() { }); }); - group("argument errors", () { + group('argument errors', () { StringScanner scanner; setUp(() { scanner = StringScanner('foo bar baz'); scanner.scan('foo'); }); - test("if match is passed with position", () { + test('if match is passed with position', () { expect( - () => scanner.error("oh no!", match: scanner.lastMatch, position: 1), + () => scanner.error('oh no!', match: scanner.lastMatch, position: 1), throwsArgumentError); }); - test("if match is passed with length", () { - expect(() => scanner.error("oh no!", match: scanner.lastMatch, length: 1), + test('if match is passed with length', () { + expect(() => scanner.error('oh no!', match: scanner.lastMatch, length: 1), throwsArgumentError); }); - test("if position is negative", () { - expect(() => scanner.error("oh no!", position: -1), throwsArgumentError); + test('if position is negative', () { + expect(() => scanner.error('oh no!', position: -1), throwsArgumentError); }); - test("if position is outside the string", () { - expect(() => scanner.error("oh no!", position: 100), throwsArgumentError); + test('if position is outside the string', () { + expect(() => scanner.error('oh no!', position: 100), throwsArgumentError); }); - test("if position + length is outside the string", () { - expect(() => scanner.error("oh no!", position: 7, length: 7), + test('if position + length is outside the string', () { + expect(() => scanner.error('oh no!', position: 7, length: 7), throwsArgumentError); }); - test("if length is negative", () { - expect(() => scanner.error("oh no!", length: -1), throwsArgumentError); + test('if length is negative', () { + expect(() => scanner.error('oh no!', length: -1), throwsArgumentError); }); }); } diff --git a/test/line_scanner_test.dart b/test/line_scanner_test.dart index 8767142712549..dc9b8cfd1983a 100644 --- a/test/line_scanner_test.dart +++ b/test/line_scanner_test.dart @@ -17,20 +17,20 @@ void main() { expect(scanner.column, equals(0)); }); - group("scan()", () { - test("consuming no newlines increases the column but not the line", () { + group('scan()', () { + test('consuming no newlines increases the column but not the line', () { scanner.scan('foo'); expect(scanner.line, equals(0)); expect(scanner.column, equals(3)); }); - test("consuming a newline resets the column and increases the line", () { + test('consuming a newline resets the column and increases the line', () { scanner.expect('foo\nba'); expect(scanner.line, equals(1)); expect(scanner.column, equals(2)); }); - test("consuming multiple newlines resets the column and increases the line", + test('consuming multiple newlines resets the column and increases the line', () { scanner.expect('foo\nbar\r\nb'); expect(scanner.line, equals(2)); @@ -48,15 +48,15 @@ void main() { }); }); - group("readChar()", () { - test("on a non-newline character increases the column but not the line", + group('readChar()', () { + test('on a non-newline character increases the column but not the line', () { scanner.readChar(); expect(scanner.line, equals(0)); expect(scanner.column, equals(1)); }); - test("consuming a newline resets the column and increases the line", () { + test('consuming a newline resets the column and increases the line', () { scanner.expect('foo'); expect(scanner.line, equals(0)); expect(scanner.column, equals(3)); @@ -81,15 +81,15 @@ void main() { }); }); - group("scanChar()", () { - test("on a non-newline character increases the column but not the line", + group('scanChar()', () { + test('on a non-newline character increases the column but not the line', () { scanner.scanChar($f); expect(scanner.line, equals(0)); expect(scanner.column, equals(1)); }); - test("consuming a newline resets the column and increases the line", () { + test('consuming a newline resets the column and increases the line', () { scanner.expect('foo'); expect(scanner.line, equals(0)); expect(scanner.column, equals(3)); @@ -114,28 +114,28 @@ void main() { }); }); - group("position=", () { - test("forward through newlines sets the line and column", () { + group('position=', () { + test('forward through newlines sets the line and column', () { scanner.position = 10; // "foo\nbar\r\nb" expect(scanner.line, equals(2)); expect(scanner.column, equals(1)); }); - test("forward through no newlines sets the column", () { + test('forward through no newlines sets the column', () { scanner.position = 2; // "fo" expect(scanner.line, equals(0)); expect(scanner.column, equals(2)); }); - test("backward through newlines sets the line and column", () { - scanner.scan("foo\nbar\r\nbaz"); + test('backward through newlines sets the line and column', () { + scanner.scan('foo\nbar\r\nbaz'); scanner.position = 2; // "fo" expect(scanner.line, equals(0)); expect(scanner.column, equals(2)); }); - test("backward through no newlines sets the column", () { - scanner.scan("foo\nbar\r\nbaz"); + test('backward through no newlines sets the column', () { + scanner.scan('foo\nbar\r\nbaz'); scanner.position = 10; // "foo\nbar\r\nb" expect(scanner.line, equals(2)); expect(scanner.column, equals(1)); @@ -148,7 +148,7 @@ void main() { }); }); - test("state= restores the line, column, and position", () { + test('state= restores the line, column, and position', () { scanner.scan('foo\nb'); var state = scanner.state; @@ -159,7 +159,7 @@ void main() { expect(scanner.column, equals(1)); }); - test("state= rejects a foreign state", () { + test('state= rejects a foreign state', () { scanner.scan('foo\nb'); expect(() => LineScanner(scanner.string).state = scanner.state, diff --git a/test/span_scanner_test.dart b/test/span_scanner_test.dart index 65694eaacd903..e2570aeff8638 100644 --- a/test/span_scanner_test.dart +++ b/test/span_scanner_test.dart @@ -9,15 +9,15 @@ import 'package:test/test.dart'; import 'utils.dart'; void main() { - testForImplementation("lazy", ([String string]) { + testForImplementation('lazy', ([String string]) { return SpanScanner(string ?? 'foo\nbar\nbaz', sourceUrl: 'source'); }); - testForImplementation("eager", ([String string]) { + testForImplementation('eager', ([String string]) { return SpanScanner.eager(string ?? 'foo\nbar\nbaz', sourceUrl: 'source'); }); - group("within", () { + group('within', () { var text = 'first\nbefore: foo\nbar\nbaz :after\nlast'; var startOffset = text.indexOf('foo'); @@ -28,24 +28,24 @@ void main() { SpanScanner.within(file.span(startOffset, text.indexOf(' :after'))); }); - test("string only includes the span text", () { - expect(scanner.string, equals("foo\nbar\nbaz")); + test('string only includes the span text', () { + expect(scanner.string, equals('foo\nbar\nbaz')); }); - test("line and column are span-relative", () { + test('line and column are span-relative', () { expect(scanner.line, equals(0)); expect(scanner.column, equals(0)); - scanner.scan("foo"); + scanner.scan('foo'); expect(scanner.line, equals(0)); expect(scanner.column, equals(3)); - scanner.scan("\n"); + scanner.scan('\n'); expect(scanner.line, equals(1)); expect(scanner.column, equals(0)); }); - test("tracks the span for the last match", () { + test('tracks the span for the last match', () { scanner.scan('fo'); scanner.scan('o\nba'); @@ -63,7 +63,7 @@ void main() { expect(span.text, equals('o\nba')); }); - test(".spanFrom() returns a span from a previous state", () { + test('.spanFrom() returns a span from a previous state', () { scanner.scan('fo'); var state = scanner.state; scanner.scan('o\nba'); @@ -73,7 +73,7 @@ void main() { expect(span.text, equals('o\nbar\nba')); }); - test(".emptySpan returns an empty span at the current location", () { + test('.emptySpan returns an empty span at the current location', () { scanner.scan('foo\nba'); var span = scanner.emptySpan; @@ -90,14 +90,14 @@ void main() { expect(span.text, equals('')); }); - test(".error() uses an absolute span", () { - scanner.expect("foo"); + test('.error() uses an absolute span', () { + scanner.expect('foo'); expect( - () => scanner.error('oh no!'), throwsStringScannerException("foo")); + () => scanner.error('oh no!'), throwsStringScannerException('foo')); }); - test(".isDone returns true at the end of the span", () { - scanner.expect("foo\nbar\nbaz"); + test('.isDone returns true at the end of the span', () { + scanner.expect('foo\nbar\nbaz'); expect(scanner.isDone, isTrue); }); }); @@ -105,11 +105,11 @@ void main() { void testForImplementation( String name, SpanScanner Function([String string]) create) { - group("for a $name scanner", () { + group('for a $name scanner', () { SpanScanner scanner; setUp(() => scanner = create()); - test("tracks the span for the last match", () { + test('tracks the span for the last match', () { scanner.scan('fo'); scanner.scan('o\nba'); @@ -127,7 +127,7 @@ void testForImplementation( expect(span.text, equals('o\nba')); }); - test(".spanFrom() returns a span from a previous state", () { + test('.spanFrom() returns a span from a previous state', () { scanner.scan('fo'); var state = scanner.state; scanner.scan('o\nba'); @@ -137,7 +137,7 @@ void testForImplementation( expect(span.text, equals('o\nbar\nba')); }); - test(".spanFrom() handles surrogate pairs correctly", () { + test('.spanFrom() handles surrogate pairs correctly', () { scanner = create('fo\u{12345}o'); scanner.scan('fo'); var state = scanner.state; @@ -146,7 +146,7 @@ void testForImplementation( expect(span.text, equals('\u{12345}o')); }); - test(".emptySpan returns an empty span at the current location", () { + test('.emptySpan returns an empty span at the current location', () { scanner.scan('foo\nba'); var span = scanner.emptySpan; diff --git a/test/string_scanner_test.dart b/test/string_scanner_test.dart index 9d6d6b8609c6b..e1e5b4eb829df 100644 --- a/test/string_scanner_test.dart +++ b/test/string_scanner_test.dart @@ -72,7 +72,7 @@ void main() { expect(scanner.position, equals(0)); }); - test("substring returns the empty string", () { + test('substring returns the empty string', () { expect(scanner.substring(0), isEmpty); }); @@ -130,38 +130,38 @@ void main() { expect(scanner.position, equals(0)); }); - test("a matching scanChar returns true moves forward", () { + test('a matching scanChar returns true moves forward', () { expect(scanner.scanChar($f), isTrue); expect(scanner.lastMatch, isNull); expect(scanner.position, equals(1)); }); - test("a non-matching scanChar returns false and does nothing", () { + test('a non-matching scanChar returns false and does nothing', () { expect(scanner.scanChar($x), isFalse); expect(scanner.lastMatch, isNull); expect(scanner.position, equals(0)); }); - test("a matching expectChar moves forward", () { + test('a matching expectChar moves forward', () { scanner.expectChar($f); expect(scanner.lastMatch, isNull); expect(scanner.position, equals(1)); }); - test("a non-matching expectChar fails", () { + test('a non-matching expectChar fails', () { expect(() => scanner.expectChar($x), throwsFormatException); expect(scanner.lastMatch, isNull); expect(scanner.position, equals(0)); }); - test("a matching scan returns true and changes the state", () { + test('a matching scan returns true and changes the state', () { expect(scanner.scan(RegExp('f(..)')), isTrue); expect(scanner.lastMatch[1], equals('oo')); expect(scanner.position, equals(3)); expect(scanner.rest, equals(' bar')); }); - test("a non-matching scan returns false and sets lastMatch to null", () { + test('a non-matching scan returns false and sets lastMatch to null', () { expect(scanner.matches(RegExp('f(..)')), isTrue); expect(scanner.lastMatch, isNotNull); @@ -171,7 +171,7 @@ void main() { expect(scanner.rest, equals('foo bar')); }); - test("a matching expect changes the state", () { + test('a matching expect changes the state', () { scanner.expect(RegExp('f(..)')); expect(scanner.lastMatch[1], equals('oo')); expect(scanner.position, equals(3)); @@ -179,8 +179,8 @@ void main() { }); test( - "a non-matching expect throws a FormatException and sets lastMatch to " - "null", () { + 'a non-matching expect throws a FormatException and sets lastMatch to ' + 'null', () { expect(scanner.matches(RegExp('f(..)')), isTrue); expect(scanner.lastMatch, isNotNull); @@ -190,7 +190,7 @@ void main() { expect(scanner.rest, equals('foo bar')); }); - test("a matching matches returns true and only changes lastMatch", () { + test('a matching matches returns true and only changes lastMatch', () { expect(scanner.matches(RegExp('f(..)')), isTrue); expect(scanner.lastMatch[1], equals('oo')); expect(scanner.position, equals(0)); @@ -205,15 +205,15 @@ void main() { expect(scanner.rest, equals('foo bar')); }); - test("substring from the beginning returns the empty string", () { + test('substring from the beginning returns the empty string', () { expect(scanner.substring(0), isEmpty); }); - test("substring with a custom end returns the substring", () { + test('substring with a custom end returns the substring', () { expect(scanner.substring(0, 3), equals('foo')); }); - test("substring with the string length returns the whole string", () { + test('substring with the string length returns the whole string', () { expect(scanner.substring(0, 7), equals('foo bar')); }); @@ -332,33 +332,33 @@ void main() { expect(scanner.position, equals(7)); }); - test("scan returns false and sets lastMatch to null", () { + test('scan returns false and sets lastMatch to null', () { expect(scanner.scan(RegExp('.')), isFalse); expect(scanner.lastMatch, isNull); expect(scanner.position, equals(7)); }); - test("expect throws a FormatException and sets lastMatch to null", () { + test('expect throws a FormatException and sets lastMatch to null', () { expect(() => scanner.expect(RegExp('.')), throwsFormatException); expect(scanner.lastMatch, isNull); expect(scanner.position, equals(7)); }); - test("matches returns false sets lastMatch to null", () { + test('matches returns false sets lastMatch to null', () { expect(scanner.matches(RegExp('.')), isFalse); expect(scanner.lastMatch, isNull); expect(scanner.position, equals(7)); }); - test("substring from the beginning returns the whole string", () { + test('substring from the beginning returns the whole string', () { expect(scanner.substring(0), equals('foo bar')); }); - test("substring with a custom start returns a substring from there", () { + test('substring with a custom start returns a substring from there', () { expect(scanner.substring(4), equals('bar')); }); - test("substring with a custom start and end returns that substring", () { + test('substring with a custom start and end returns that substring', () { expect(scanner.substring(3, 5), equals(' b')); });