| Index: packages/string_scanner/test/string_scanner_test.dart
|
| diff --git a/packages/string_scanner/test/string_scanner_test.dart b/packages/string_scanner/test/string_scanner_test.dart
|
| index c8e43a5aa963e36c2be147c5765f272430d56150..55ffa0a9f0c98792aa96294071fff8f0e7a20f4b 100644
|
| --- a/packages/string_scanner/test/string_scanner_test.dart
|
| +++ b/packages/string_scanner/test/string_scanner_test.dart
|
| @@ -2,8 +2,7 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -library string_scanner.string_scanner_test;
|
| -
|
| +import 'package:charcode/charcode.dart';
|
| import 'package:string_scanner/string_scanner.dart';
|
| import 'package:test/test.dart';
|
|
|
| @@ -43,6 +42,18 @@ void main() {
|
| expect(scanner.position, equals(0));
|
| });
|
|
|
| + test("scanChar returns false and doesn't change the state", () {
|
| + expect(scanner.scanChar($f), isFalse);
|
| + expect(scanner.lastMatch, isNull);
|
| + expect(scanner.position, equals(0));
|
| + });
|
| +
|
| + test("expectChar fails and doesn't change the state", () {
|
| + expect(() => scanner.expectChar($f), throwsFormatException);
|
| + expect(scanner.lastMatch, isNull);
|
| + expect(scanner.position, equals(0));
|
| + });
|
| +
|
| test("scan returns false and doesn't change the state", () {
|
| expect(scanner.scan(new RegExp('.')), isFalse);
|
| expect(scanner.lastMatch, isNull);
|
| @@ -119,6 +130,30 @@ void main() {
|
| expect(scanner.position, equals(0));
|
| });
|
|
|
| + 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", () {
|
| + expect(scanner.scanChar($x), isFalse);
|
| + expect(scanner.lastMatch, isNull);
|
| + expect(scanner.position, equals(0));
|
| + });
|
| +
|
| + test("a matching expectChar moves forward", () {
|
| + scanner.expectChar($f);
|
| + expect(scanner.lastMatch, isNull);
|
| + expect(scanner.position, equals(1));
|
| + });
|
| +
|
| + 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", () {
|
| expect(scanner.scan(new RegExp('f(..)')), isTrue);
|
| expect(scanner.lastMatch[1], equals('oo'));
|
| @@ -226,6 +261,32 @@ void main() {
|
| });
|
| });
|
|
|
| + group('after a scan', () {
|
| + var scanner;
|
| + setUp(() {
|
| + scanner = new StringScanner('foo bar');
|
| + expect(scanner.scan('foo'), isTrue);
|
| + });
|
| +
|
| + test('readChar returns the first character and unsets the last match', () {
|
| + expect(scanner.readChar(), equals($space));
|
| + expect(scanner.lastMatch, isNull);
|
| + expect(scanner.position, equals(4));
|
| + });
|
| +
|
| + test('a matching scanChar returns true and unsets the last match', () {
|
| + expect(scanner.scanChar($space), isTrue);
|
| + expect(scanner.lastMatch, isNull);
|
| + expect(scanner.position, equals(4));
|
| + });
|
| +
|
| + test('a matching expectChar returns true and unsets the last match', () {
|
| + scanner.expectChar($space);
|
| + expect(scanner.lastMatch, isNull);
|
| + expect(scanner.position, equals(4));
|
| + });
|
| + });
|
| +
|
| group('at the end of a string', () {
|
| var scanner;
|
| setUp(() {
|
| @@ -258,6 +319,18 @@ void main() {
|
| expect(scanner.position, equals(7));
|
| });
|
|
|
| + test("scanChar returns false and doesn't change the state", () {
|
| + expect(scanner.scanChar($f), isFalse);
|
| + expect(scanner.lastMatch, isNotNull);
|
| + expect(scanner.position, equals(7));
|
| + });
|
| +
|
| + test("expectChar fails and doesn't change the state", () {
|
| + expect(() => scanner.expectChar($f), throwsFormatException);
|
| + expect(scanner.lastMatch, isNotNull);
|
| + expect(scanner.position, equals(7));
|
| + });
|
| +
|
| test("scan returns false and sets lastMatch to null", () {
|
| expect(scanner.scan(new RegExp('.')), isFalse);
|
| expect(scanner.lastMatch, isNull);
|
| @@ -299,6 +372,13 @@ void main() {
|
| expect(scanner.rest, equals('bar'));
|
| });
|
|
|
| + test('setting and resetting position clears lastMatch', () {
|
| + var oldPosition = scanner.position;
|
| + scanner.position = 1;
|
| + scanner.position = oldPosition;
|
| + expect(scanner.lastMatch, isNull);
|
| + });
|
| +
|
| test('setting position beyond the string throws an ArgumentError', () {
|
| expect(() {
|
| scanner.position = 8;
|
|
|