OLD | NEW |
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 string_scanner.string_scanner_test; | 5 library string_scanner.string_scanner_test; |
6 | 6 |
7 import 'package:string_scanner/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() { |
(...skipping 13 matching lines...) Expand all Loading... |
24 }); | 24 }); |
25 | 25 |
26 test('lastMatch is null', () { | 26 test('lastMatch is null', () { |
27 expect(scanner.lastMatch, isNull); | 27 expect(scanner.lastMatch, isNull); |
28 }); | 28 }); |
29 | 29 |
30 test('position is zero', () { | 30 test('position is zero', () { |
31 expect(scanner.position, equals(0)); | 31 expect(scanner.position, equals(0)); |
32 }); | 32 }); |
33 | 33 |
| 34 test("readChar fails and doesn't change the state", () { |
| 35 expect(scanner.readChar, throwsFormatException); |
| 36 expect(scanner.lastMatch, isNull); |
| 37 expect(scanner.position, equals(0)); |
| 38 }); |
| 39 |
| 40 test("peekChar returns null and doesn't change the state", () { |
| 41 expect(scanner.peekChar(), isNull); |
| 42 expect(scanner.lastMatch, isNull); |
| 43 expect(scanner.position, equals(0)); |
| 44 }); |
| 45 |
34 test("scan returns false and doesn't change the state", () { | 46 test("scan returns false and doesn't change the state", () { |
35 expect(scanner.scan(new RegExp('.')), isFalse); | 47 expect(scanner.scan(new RegExp('.')), isFalse); |
36 expect(scanner.lastMatch, isNull); | 48 expect(scanner.lastMatch, isNull); |
37 expect(scanner.position, equals(0)); | 49 expect(scanner.position, equals(0)); |
38 }); | 50 }); |
39 | 51 |
40 test("expect throws a FormatException and doesn't change the state", () { | 52 test("expect throws a FormatException and doesn't change the state", () { |
41 expect(() => scanner.expect(new RegExp('.')), throwsFormatException); | 53 expect(() => scanner.expect(new RegExp('.')), throwsFormatException); |
42 expect(scanner.lastMatch, isNull); | 54 expect(scanner.lastMatch, isNull); |
43 expect(scanner.position, equals(0)); | 55 expect(scanner.position, equals(0)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 }); | 90 }); |
79 | 91 |
80 test('lastMatch is null', () { | 92 test('lastMatch is null', () { |
81 expect(scanner.lastMatch, isNull); | 93 expect(scanner.lastMatch, isNull); |
82 }); | 94 }); |
83 | 95 |
84 test('position is zero', () { | 96 test('position is zero', () { |
85 expect(scanner.position, equals(0)); | 97 expect(scanner.position, equals(0)); |
86 }); | 98 }); |
87 | 99 |
| 100 test('readChar returns the first character and moves forward', () { |
| 101 expect(scanner.readChar(), equals(0x66)); |
| 102 expect(scanner.lastMatch, isNull); |
| 103 expect(scanner.position, equals(1)); |
| 104 }); |
| 105 |
| 106 test('peekChar returns the first character', () { |
| 107 expect(scanner.peekChar(), equals(0x66)); |
| 108 expect(scanner.lastMatch, isNull); |
| 109 expect(scanner.position, equals(0)); |
| 110 }); |
| 111 |
| 112 test('peekChar with an argument returns the nth character', () { |
| 113 expect(scanner.peekChar(4), equals(0x62)); |
| 114 expect(scanner.lastMatch, isNull); |
| 115 expect(scanner.position, equals(0)); |
| 116 }); |
| 117 |
88 test("a matching scan returns true and changes the state", () { | 118 test("a matching scan returns true and changes the state", () { |
89 expect(scanner.scan(new RegExp('f(..)')), isTrue); | 119 expect(scanner.scan(new RegExp('f(..)')), isTrue); |
90 expect(scanner.lastMatch[1], equals('oo')); | 120 expect(scanner.lastMatch[1], equals('oo')); |
91 expect(scanner.position, equals(3)); | 121 expect(scanner.position, equals(3)); |
92 expect(scanner.rest, equals(' bar')); | 122 expect(scanner.rest, equals(' bar')); |
93 }); | 123 }); |
94 | 124 |
95 test("a non-matching scan returns false and sets lastMatch to null", () { | 125 test("a non-matching scan returns false and sets lastMatch to null", () { |
96 expect(scanner.matches(new RegExp('f(..)')), isTrue); | 126 expect(scanner.matches(new RegExp('f(..)')), isTrue); |
97 expect(scanner.lastMatch, isNotNull); | 127 expect(scanner.lastMatch, isNotNull); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 }); | 223 }); |
194 | 224 |
195 test('rest is empty', () { | 225 test('rest is empty', () { |
196 expect(scanner.rest, isEmpty); | 226 expect(scanner.rest, isEmpty); |
197 }); | 227 }); |
198 | 228 |
199 test('position is zero', () { | 229 test('position is zero', () { |
200 expect(scanner.position, equals(7)); | 230 expect(scanner.position, equals(7)); |
201 }); | 231 }); |
202 | 232 |
| 233 test("readChar fails and doesn't change the state", () { |
| 234 expect(scanner.readChar, throwsFormatException); |
| 235 expect(scanner.lastMatch, isNotNull); |
| 236 expect(scanner.position, equals(7)); |
| 237 }); |
| 238 |
| 239 test("peekChar returns null and doesn't change the state", () { |
| 240 expect(scanner.peekChar(), isNull); |
| 241 expect(scanner.lastMatch, isNotNull); |
| 242 expect(scanner.position, equals(7)); |
| 243 }); |
| 244 |
203 test("scan returns false and sets lastMatch to null", () { | 245 test("scan returns false and sets lastMatch to null", () { |
204 expect(scanner.scan(new RegExp('.')), isFalse); | 246 expect(scanner.scan(new RegExp('.')), isFalse); |
205 expect(scanner.lastMatch, isNull); | 247 expect(scanner.lastMatch, isNull); |
206 expect(scanner.position, equals(7)); | 248 expect(scanner.position, equals(7)); |
207 }); | 249 }); |
208 | 250 |
209 test("expect throws a FormatException and sets lastMatch to null", () { | 251 test("expect throws a FormatException and sets lastMatch to null", () { |
210 expect(() => scanner.expect(new RegExp('.')), throwsFormatException); | 252 expect(() => scanner.expect(new RegExp('.')), throwsFormatException); |
211 expect(scanner.lastMatch, isNull); | 253 expect(scanner.lastMatch, isNull); |
212 expect(scanner.position, equals(7)); | 254 expect(scanner.position, equals(7)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 expect(() => new StringScanner('foo bar', position: -1), | 300 expect(() => new StringScanner('foo bar', position: -1), |
259 throwsArgumentError); | 301 throwsArgumentError); |
260 }); | 302 }); |
261 | 303 |
262 test('throws an ArgumentError if the position is beyond the string', () { | 304 test('throws an ArgumentError if the position is beyond the string', () { |
263 expect(() => new StringScanner('foo bar', position: 8), | 305 expect(() => new StringScanner('foo bar', position: 8), |
264 throwsArgumentError); | 306 throwsArgumentError); |
265 }); | 307 }); |
266 }); | 308 }); |
267 } | 309 } |
OLD | NEW |