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

Side by Side Diff: pkg/string_scanner/test/string_scanner_test.dart

Issue 213833013: Add a string_scanner package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « pkg/string_scanner/test/error_format_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 library shelf.string_scanner_test; 5 library string_scanner.string_scanner_test;
6 6
7 import 'package:shelf/src/string_scanner.dart'; 7 import 'package:string_scanner/string_scanner.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 void main() { 10 void main() {
11 group('with an empty string', () { 11 group('with an empty string', () {
12 var scanner; 12 var scanner;
13 setUp(() { 13 setUp(() {
14 scanner = new StringScanner(''); 14 scanner = new StringScanner('');
15 }); 15 });
16 16
17 test('is done', () { 17 test('is done', () {
18 expect(scanner.isDone, isTrue); 18 expect(scanner.isDone, isTrue);
19 expect(scanner.expectDone, isNot(throwsFormatException));
19 }); 20 });
20 21
21 test('rest is empty', () { 22 test('rest is empty', () {
22 expect(scanner.rest, isEmpty); 23 expect(scanner.rest, isEmpty);
23 }); 24 });
24 25
25 test('lastMatch is null', () { 26 test('lastMatch is null', () {
26 expect(scanner.lastMatch, isNull); 27 expect(scanner.lastMatch, isNull);
27 }); 28 });
28 29
29 test('position is zero', () { 30 test('position is zero', () {
30 expect(scanner.position, equals(0)); 31 expect(scanner.position, equals(0));
31 }); 32 });
32 33
33 test("scan returns false and doesn't change the state", () { 34 test("scan returns false and doesn't change the state", () {
34 expect(scanner.scan(new RegExp('.')), isFalse); 35 expect(scanner.scan(new RegExp('.')), isFalse);
35 expect(scanner.lastMatch, isNull); 36 expect(scanner.lastMatch, isNull);
36 expect(scanner.position, equals(0)); 37 expect(scanner.position, equals(0));
37 }); 38 });
38 39
39 test("expect throws a FormatException and doesn't change the state", () { 40 test("expect throws a FormatException and doesn't change the state", () {
40 expect(() => scanner.expect(new RegExp('.'), 'error'), 41 expect(() => scanner.expect(new RegExp('.')), throwsFormatException);
41 throwsFormatException);
42 expect(scanner.lastMatch, isNull); 42 expect(scanner.lastMatch, isNull);
43 expect(scanner.position, equals(0)); 43 expect(scanner.position, equals(0));
44 }); 44 });
45 45
46 test("matches returns false and doesn't change the state", () { 46 test("matches returns false and doesn't change the state", () {
47 expect(scanner.matches(new RegExp('.')), isFalse); 47 expect(scanner.matches(new RegExp('.')), isFalse);
48 expect(scanner.lastMatch, isNull); 48 expect(scanner.lastMatch, isNull);
49 expect(scanner.position, equals(0)); 49 expect(scanner.position, equals(0));
50 }); 50 });
51 51
(...skipping 11 matching lines...) Expand all
63 }); 63 });
64 64
65 group('at the beginning of a string', () { 65 group('at the beginning of a string', () {
66 var scanner; 66 var scanner;
67 setUp(() { 67 setUp(() {
68 scanner = new StringScanner('foo bar'); 68 scanner = new StringScanner('foo bar');
69 }); 69 });
70 70
71 test('is not done', () { 71 test('is not done', () {
72 expect(scanner.isDone, isFalse); 72 expect(scanner.isDone, isFalse);
73 expect(scanner.expectDone, throwsFormatException);
73 }); 74 });
74 75
75 test('rest is the whole string', () { 76 test('rest is the whole string', () {
76 expect(scanner.rest, equals('foo bar')); 77 expect(scanner.rest, equals('foo bar'));
77 }); 78 });
78 79
79 test('lastMatch is null', () { 80 test('lastMatch is null', () {
80 expect(scanner.lastMatch, isNull); 81 expect(scanner.lastMatch, isNull);
81 }); 82 });
82 83
(...skipping 12 matching lines...) Expand all
95 expect(scanner.matches(new RegExp('f(..)')), isTrue); 96 expect(scanner.matches(new RegExp('f(..)')), isTrue);
96 expect(scanner.lastMatch, isNotNull); 97 expect(scanner.lastMatch, isNotNull);
97 98
98 expect(scanner.scan(new RegExp('b(..)')), isFalse); 99 expect(scanner.scan(new RegExp('b(..)')), isFalse);
99 expect(scanner.lastMatch, isNull); 100 expect(scanner.lastMatch, isNull);
100 expect(scanner.position, equals(0)); 101 expect(scanner.position, equals(0));
101 expect(scanner.rest, equals('foo bar')); 102 expect(scanner.rest, equals('foo bar'));
102 }); 103 });
103 104
104 test("a matching expect changes the state", () { 105 test("a matching expect changes the state", () {
105 scanner.expect(new RegExp('f(..)'), 'error'); 106 scanner.expect(new RegExp('f(..)'));
106 expect(scanner.lastMatch[1], equals('oo')); 107 expect(scanner.lastMatch[1], equals('oo'));
107 expect(scanner.position, equals(3)); 108 expect(scanner.position, equals(3));
108 expect(scanner.rest, equals(' bar')); 109 expect(scanner.rest, equals(' bar'));
109 }); 110 });
110 111
111 test("a non-matching expect throws a FormatException and sets lastMatch to " 112 test("a non-matching expect throws a FormatException and sets lastMatch to "
112 "null", () { 113 "null", () {
113 expect(scanner.matches(new RegExp('f(..)')), isTrue); 114 expect(scanner.matches(new RegExp('f(..)')), isTrue);
114 expect(scanner.lastMatch, isNotNull); 115 expect(scanner.lastMatch, isNotNull);
115 116
116 expect(() => scanner.expect(new RegExp('b(..)'), 'error'), 117 expect(() => scanner.expect(new RegExp('b(..)')), throwsFormatException);
117 throwsFormatException);
118 expect(scanner.lastMatch, isNull); 118 expect(scanner.lastMatch, isNull);
119 expect(scanner.position, equals(0)); 119 expect(scanner.position, equals(0));
120 expect(scanner.rest, equals('foo bar')); 120 expect(scanner.rest, equals('foo bar'));
121 }); 121 });
122 122
123 test("a matching matches returns true and only changes lastMatch", () { 123 test("a matching matches returns true and only changes lastMatch", () {
124 expect(scanner.matches(new RegExp('f(..)')), isTrue); 124 expect(scanner.matches(new RegExp('f(..)')), isTrue);
125 expect(scanner.lastMatch[1], equals('oo')); 125 expect(scanner.lastMatch[1], equals('oo'));
126 expect(scanner.position, equals(0)); 126 expect(scanner.position, equals(0));
127 expect(scanner.rest, equals('foo bar')); 127 expect(scanner.rest, equals('foo bar'));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 expect(scanner.scan(new RegExp('f(..)')), isTrue); 169 expect(scanner.scan(new RegExp('f(..)')), isTrue);
170 expect(scanner.lastMatch[1], equals('oo')); 170 expect(scanner.lastMatch[1], equals('oo'));
171 expect(scanner.position, equals(3)); 171 expect(scanner.position, equals(3));
172 expect(scanner.rest, equals(' bar')); 172 expect(scanner.rest, equals(' bar'));
173 173
174 expect(scanner.scan(new RegExp(' b(..)')), isTrue); 174 expect(scanner.scan(new RegExp(' b(..)')), isTrue);
175 expect(scanner.lastMatch[1], equals('ar')); 175 expect(scanner.lastMatch[1], equals('ar'));
176 expect(scanner.position, equals(7)); 176 expect(scanner.position, equals(7));
177 expect(scanner.rest, equals('')); 177 expect(scanner.rest, equals(''));
178 expect(scanner.isDone, isTrue); 178 expect(scanner.isDone, isTrue);
179 expect(scanner.expectDone, isNot(throwsFormatException));
179 }); 180 });
180 }); 181 });
181 182
182 group('at the end of a string', () { 183 group('at the end of a string', () {
183 var scanner; 184 var scanner;
184 setUp(() { 185 setUp(() {
185 scanner = new StringScanner('foo bar'); 186 scanner = new StringScanner('foo bar');
186 expect(scanner.scan('foo bar'), isTrue); 187 expect(scanner.scan('foo bar'), isTrue);
187 }); 188 });
188 189
189 test('is done', () { 190 test('is done', () {
190 expect(scanner.isDone, isTrue); 191 expect(scanner.isDone, isTrue);
192 expect(scanner.expectDone, isNot(throwsFormatException));
191 }); 193 });
192 194
193 test('rest is empty', () { 195 test('rest is empty', () {
194 expect(scanner.rest, isEmpty); 196 expect(scanner.rest, isEmpty);
195 }); 197 });
196 198
197 test('position is zero', () { 199 test('position is zero', () {
198 expect(scanner.position, equals(7)); 200 expect(scanner.position, equals(7));
199 }); 201 });
200 202
201 test("scan returns false and sets lastMatch to null", () { 203 test("scan returns false and sets lastMatch to null", () {
202 expect(scanner.scan(new RegExp('.')), isFalse); 204 expect(scanner.scan(new RegExp('.')), isFalse);
203 expect(scanner.lastMatch, isNull); 205 expect(scanner.lastMatch, isNull);
204 expect(scanner.position, equals(7)); 206 expect(scanner.position, equals(7));
205 }); 207 });
206 208
207 test("expect throws a FormatException and sets lastMatch to null", () { 209 test("expect throws a FormatException and sets lastMatch to null", () {
208 expect(() => scanner.expect(new RegExp('.'), 'error'), 210 expect(() => scanner.expect(new RegExp('.')), throwsFormatException);
209 throwsFormatException);
210 expect(scanner.lastMatch, isNull); 211 expect(scanner.lastMatch, isNull);
211 expect(scanner.position, equals(7)); 212 expect(scanner.position, equals(7));
212 }); 213 });
213 214
214 test("matches returns false sets lastMatch to null", () { 215 test("matches returns false sets lastMatch to null", () {
215 expect(scanner.matches(new RegExp('.')), isFalse); 216 expect(scanner.matches(new RegExp('.')), isFalse);
216 expect(scanner.lastMatch, isNull); 217 expect(scanner.lastMatch, isNull);
217 expect(scanner.position, equals(7)); 218 expect(scanner.position, equals(7));
218 }); 219 });
219 220
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 expect(() => new StringScanner('foo bar', position: -1), 258 expect(() => new StringScanner('foo bar', position: -1),
258 throwsArgumentError); 259 throwsArgumentError);
259 }); 260 });
260 261
261 test('throws an ArgumentError if the position is beyond the string', () { 262 test('throws an ArgumentError if the position is beyond the string', () {
262 expect(() => new StringScanner('foo bar', position: 8), 263 expect(() => new StringScanner('foo bar', position: 8),
263 throwsArgumentError); 264 throwsArgumentError);
264 }); 265 });
265 }); 266 });
266 } 267 }
OLDNEW
« no previous file with comments | « pkg/string_scanner/test/error_format_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698