Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(686)

Unified Diff: test/string_scanner_test.dart

Issue 2041813002: Add StringScanner.scanChar() and .expectChar(). (Closed) Base URL: git@github.com:dart-lang/string_scanner@master
Patch Set: Code review changes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/line_scanner_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/string_scanner_test.dart
diff --git a/test/string_scanner_test.dart b/test/string_scanner_test.dart
index 10e622a82a3cc2268eaf913e7aec260799e10f8f..0b4d4824f0bf2bf64cb85f4799d4cdceb004fc07 100644
--- a/test/string_scanner_test.dart
+++ b/test/string_scanner_test.dart
@@ -2,6 +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.
+import 'package:charcode/charcode.dart';
import 'package:string_scanner/string_scanner.dart';
import 'package:test/test.dart';
@@ -41,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);
@@ -117,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'));
@@ -256,6 +293,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);
« no previous file with comments | « test/line_scanner_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698