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

Unified Diff: test/line_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 | « pubspec.yaml ('k') | test/string_scanner_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/line_scanner_test.dart
diff --git a/test/line_scanner_test.dart b/test/line_scanner_test.dart
index 9874cb309461304aa0f250797b28016df1059e13..ed04b371c1e4b713e967c3c3a51c0f99a5b06095 100644
--- a/test/line_scanner_test.dart
+++ b/test/line_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';
@@ -80,6 +81,39 @@ void main() {
});
});
+ 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", () {
+ scanner.expect('foo');
+ expect(scanner.line, equals(0));
+ expect(scanner.column, equals(3));
+
+ scanner.scanChar($lf);
+ expect(scanner.line, equals(1));
+ expect(scanner.column, equals(0));
+ });
+
+ test("consuming halfway through a CR LF doesn't count as a line", () {
+ scanner.expect('foo\nbar');
+ expect(scanner.line, equals(1));
+ expect(scanner.column, equals(3));
+
+ scanner.scanChar($cr);
+ expect(scanner.line, equals(1));
+ expect(scanner.column, equals(4));
+
+ scanner.scanChar($lf);
+ expect(scanner.line, equals(2));
+ expect(scanner.column, equals(0));
+ });
+ });
+
group("position=", () {
test("forward through newlines sets the line and column", () {
scanner.position = 10; // "foo\nbar\r\nb"
« no previous file with comments | « pubspec.yaml ('k') | test/string_scanner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698