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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « test/line_scanner_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:charcode/charcode.dart';
5 import 'package:string_scanner/string_scanner.dart'; 6 import 'package:string_scanner/string_scanner.dart';
6 import 'package:test/test.dart'; 7 import 'package:test/test.dart';
7 8
8 void main() { 9 void main() {
9 group('with an empty string', () { 10 group('with an empty string', () {
10 var scanner; 11 var scanner;
11 setUp(() { 12 setUp(() {
12 scanner = new StringScanner(''); 13 scanner = new StringScanner('');
13 }); 14 });
14 15
(...skipping 19 matching lines...) Expand all
34 expect(scanner.lastMatch, isNull); 35 expect(scanner.lastMatch, isNull);
35 expect(scanner.position, equals(0)); 36 expect(scanner.position, equals(0));
36 }); 37 });
37 38
38 test("peekChar returns null and doesn't change the state", () { 39 test("peekChar returns null and doesn't change the state", () {
39 expect(scanner.peekChar(), isNull); 40 expect(scanner.peekChar(), isNull);
40 expect(scanner.lastMatch, isNull); 41 expect(scanner.lastMatch, isNull);
41 expect(scanner.position, equals(0)); 42 expect(scanner.position, equals(0));
42 }); 43 });
43 44
45 test("scanChar returns false and doesn't change the state", () {
46 expect(scanner.scanChar($f), isFalse);
47 expect(scanner.lastMatch, isNull);
48 expect(scanner.position, equals(0));
49 });
50
51 test("expectChar fails and doesn't change the state", () {
52 expect(() => scanner.expectChar($f), throwsFormatException);
53 expect(scanner.lastMatch, isNull);
54 expect(scanner.position, equals(0));
55 });
56
44 test("scan returns false and doesn't change the state", () { 57 test("scan returns false and doesn't change the state", () {
45 expect(scanner.scan(new RegExp('.')), isFalse); 58 expect(scanner.scan(new RegExp('.')), isFalse);
46 expect(scanner.lastMatch, isNull); 59 expect(scanner.lastMatch, isNull);
47 expect(scanner.position, equals(0)); 60 expect(scanner.position, equals(0));
48 }); 61 });
49 62
50 test("expect throws a FormatException and doesn't change the state", () { 63 test("expect throws a FormatException and doesn't change the state", () {
51 expect(() => scanner.expect(new RegExp('.')), throwsFormatException); 64 expect(() => scanner.expect(new RegExp('.')), throwsFormatException);
52 expect(scanner.lastMatch, isNull); 65 expect(scanner.lastMatch, isNull);
53 expect(scanner.position, equals(0)); 66 expect(scanner.position, equals(0));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 expect(scanner.lastMatch, isNull); 123 expect(scanner.lastMatch, isNull);
111 expect(scanner.position, equals(0)); 124 expect(scanner.position, equals(0));
112 }); 125 });
113 126
114 test('peekChar with an argument returns the nth character', () { 127 test('peekChar with an argument returns the nth character', () {
115 expect(scanner.peekChar(4), equals(0x62)); 128 expect(scanner.peekChar(4), equals(0x62));
116 expect(scanner.lastMatch, isNull); 129 expect(scanner.lastMatch, isNull);
117 expect(scanner.position, equals(0)); 130 expect(scanner.position, equals(0));
118 }); 131 });
119 132
133 test("a matching scanChar returns true moves forward", () {
134 expect(scanner.scanChar($f), isTrue);
135 expect(scanner.lastMatch, isNull);
136 expect(scanner.position, equals(1));
137 });
138
139 test("a non-matching scanChar returns false and does nothing", () {
140 expect(scanner.scanChar($x), isFalse);
141 expect(scanner.lastMatch, isNull);
142 expect(scanner.position, equals(0));
143 });
144
145 test("a matching expectChar moves forward", () {
146 scanner.expectChar($f);
147 expect(scanner.lastMatch, isNull);
148 expect(scanner.position, equals(1));
149 });
150
151 test("a non-matching expectChar fails", () {
152 expect(() => scanner.expectChar($x), throwsFormatException);
153 expect(scanner.lastMatch, isNull);
154 expect(scanner.position, equals(0));
155 });
156
120 test("a matching scan returns true and changes the state", () { 157 test("a matching scan returns true and changes the state", () {
121 expect(scanner.scan(new RegExp('f(..)')), isTrue); 158 expect(scanner.scan(new RegExp('f(..)')), isTrue);
122 expect(scanner.lastMatch[1], equals('oo')); 159 expect(scanner.lastMatch[1], equals('oo'));
123 expect(scanner.position, equals(3)); 160 expect(scanner.position, equals(3));
124 expect(scanner.rest, equals(' bar')); 161 expect(scanner.rest, equals(' bar'));
125 }); 162 });
126 163
127 test("a non-matching scan returns false and sets lastMatch to null", () { 164 test("a non-matching scan returns false and sets lastMatch to null", () {
128 expect(scanner.matches(new RegExp('f(..)')), isTrue); 165 expect(scanner.matches(new RegExp('f(..)')), isTrue);
129 expect(scanner.lastMatch, isNotNull); 166 expect(scanner.lastMatch, isNotNull);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 expect(scanner.lastMatch, isNotNull); 286 expect(scanner.lastMatch, isNotNull);
250 expect(scanner.position, equals(7)); 287 expect(scanner.position, equals(7));
251 }); 288 });
252 289
253 test("peekChar returns null and doesn't change the state", () { 290 test("peekChar returns null and doesn't change the state", () {
254 expect(scanner.peekChar(), isNull); 291 expect(scanner.peekChar(), isNull);
255 expect(scanner.lastMatch, isNotNull); 292 expect(scanner.lastMatch, isNotNull);
256 expect(scanner.position, equals(7)); 293 expect(scanner.position, equals(7));
257 }); 294 });
258 295
296 test("scanChar returns false and doesn't change the state", () {
297 expect(scanner.scanChar($f), isFalse);
298 expect(scanner.lastMatch, isNotNull);
299 expect(scanner.position, equals(7));
300 });
301
302 test("expectChar fails and doesn't change the state", () {
303 expect(() => scanner.expectChar($f), throwsFormatException);
304 expect(scanner.lastMatch, isNotNull);
305 expect(scanner.position, equals(7));
306 });
307
259 test("scan returns false and sets lastMatch to null", () { 308 test("scan returns false and sets lastMatch to null", () {
260 expect(scanner.scan(new RegExp('.')), isFalse); 309 expect(scanner.scan(new RegExp('.')), isFalse);
261 expect(scanner.lastMatch, isNull); 310 expect(scanner.lastMatch, isNull);
262 expect(scanner.position, equals(7)); 311 expect(scanner.position, equals(7));
263 }); 312 });
264 313
265 test("expect throws a FormatException and sets lastMatch to null", () { 314 test("expect throws a FormatException and sets lastMatch to null", () {
266 expect(() => scanner.expect(new RegExp('.')), throwsFormatException); 315 expect(() => scanner.expect(new RegExp('.')), throwsFormatException);
267 expect(scanner.lastMatch, isNull); 316 expect(scanner.lastMatch, isNull);
268 expect(scanner.position, equals(7)); 317 expect(scanner.position, equals(7));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 expect(() => new StringScanner('foo bar', position: -1), 375 expect(() => new StringScanner('foo bar', position: -1),
327 throwsArgumentError); 376 throwsArgumentError);
328 }); 377 });
329 378
330 test('throws an ArgumentError if the position is beyond the string', () { 379 test('throws an ArgumentError if the position is beyond the string', () {
331 expect( 380 expect(
332 () => new StringScanner('foo bar', position: 8), throwsArgumentError); 381 () => new StringScanner('foo bar', position: 8), throwsArgumentError);
333 }); 382 });
334 }); 383 });
335 } 384 }
OLDNEW
« 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