| 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 import 'package:charcode/charcode.dart'; | 5 import 'package:charcode/charcode.dart'; |
| 6 import 'package:string_scanner/string_scanner.dart'; | 6 import 'package:string_scanner/string_scanner.dart'; |
| 7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
| 8 | 8 |
| 9 void main() { | 9 void main() { |
| 10 group('with an empty string', () { | 10 group('with an empty string', () { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 254 |
| 255 expect(scanner.scan(new RegExp(' b(..)')), isTrue); | 255 expect(scanner.scan(new RegExp(' b(..)')), isTrue); |
| 256 expect(scanner.lastMatch[1], equals('ar')); | 256 expect(scanner.lastMatch[1], equals('ar')); |
| 257 expect(scanner.position, equals(7)); | 257 expect(scanner.position, equals(7)); |
| 258 expect(scanner.rest, equals('')); | 258 expect(scanner.rest, equals('')); |
| 259 expect(scanner.isDone, isTrue); | 259 expect(scanner.isDone, isTrue); |
| 260 expect(scanner.expectDone, isNot(throwsFormatException)); | 260 expect(scanner.expectDone, isNot(throwsFormatException)); |
| 261 }); | 261 }); |
| 262 }); | 262 }); |
| 263 | 263 |
| 264 group('after a scan', () { |
| 265 var scanner; |
| 266 setUp(() { |
| 267 scanner = new StringScanner('foo bar'); |
| 268 expect(scanner.scan('foo'), isTrue); |
| 269 }); |
| 270 |
| 271 test('readChar returns the first character and unsets the last match', () { |
| 272 expect(scanner.readChar(), equals($space)); |
| 273 expect(scanner.lastMatch, isNull); |
| 274 expect(scanner.position, equals(4)); |
| 275 }); |
| 276 |
| 277 test('a matching scanChar returns true and unsets the last match', () { |
| 278 expect(scanner.scanChar($space), isTrue); |
| 279 expect(scanner.lastMatch, isNull); |
| 280 expect(scanner.position, equals(4)); |
| 281 }); |
| 282 |
| 283 test('a matching expectChar returns true and unsets the last match', () { |
| 284 scanner.expectChar($space); |
| 285 expect(scanner.lastMatch, isNull); |
| 286 expect(scanner.position, equals(4)); |
| 287 }); |
| 288 }); |
| 289 |
| 264 group('at the end of a string', () { | 290 group('at the end of a string', () { |
| 265 var scanner; | 291 var scanner; |
| 266 setUp(() { | 292 setUp(() { |
| 267 scanner = new StringScanner('foo bar'); | 293 scanner = new StringScanner('foo bar'); |
| 268 expect(scanner.scan('foo bar'), isTrue); | 294 expect(scanner.scan('foo bar'), isTrue); |
| 269 }); | 295 }); |
| 270 | 296 |
| 271 test('is done', () { | 297 test('is done', () { |
| 272 expect(scanner.isDone, isTrue); | 298 expect(scanner.isDone, isTrue); |
| 273 expect(scanner.expectDone, isNot(throwsFormatException)); | 299 expect(scanner.expectDone, isNot(throwsFormatException)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 scanner.position = 1; | 365 scanner.position = 1; |
| 340 expect(scanner.position, equals(1)); | 366 expect(scanner.position, equals(1)); |
| 341 expect(scanner.rest, equals('oo bar')); | 367 expect(scanner.rest, equals('oo bar')); |
| 342 | 368 |
| 343 expect(scanner.scan(new RegExp('oo.')), isTrue); | 369 expect(scanner.scan(new RegExp('oo.')), isTrue); |
| 344 expect(scanner.lastMatch[0], equals('oo ')); | 370 expect(scanner.lastMatch[0], equals('oo ')); |
| 345 expect(scanner.position, equals(4)); | 371 expect(scanner.position, equals(4)); |
| 346 expect(scanner.rest, equals('bar')); | 372 expect(scanner.rest, equals('bar')); |
| 347 }); | 373 }); |
| 348 | 374 |
| 375 test('setting and resetting position clears lastMatch', () { |
| 376 var oldPosition = scanner.position; |
| 377 scanner.position = 1; |
| 378 scanner.position = oldPosition; |
| 379 expect(scanner.lastMatch, isNull); |
| 380 }); |
| 381 |
| 349 test('setting position beyond the string throws an ArgumentError', () { | 382 test('setting position beyond the string throws an ArgumentError', () { |
| 350 expect(() { | 383 expect(() { |
| 351 scanner.position = 8; | 384 scanner.position = 8; |
| 352 }, throwsArgumentError); | 385 }, throwsArgumentError); |
| 353 }); | 386 }); |
| 354 | 387 |
| 355 test('setting position to -1 throws an ArgumentError', () { | 388 test('setting position to -1 throws an ArgumentError', () { |
| 356 expect(() { | 389 expect(() { |
| 357 scanner.position = -1; | 390 scanner.position = -1; |
| 358 }, throwsArgumentError); | 391 }, throwsArgumentError); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 375 expect(() => new StringScanner('foo bar', position: -1), | 408 expect(() => new StringScanner('foo bar', position: -1), |
| 376 throwsArgumentError); | 409 throwsArgumentError); |
| 377 }); | 410 }); |
| 378 | 411 |
| 379 test('throws an ArgumentError if the position is beyond the string', () { | 412 test('throws an ArgumentError if the position is beyond the string', () { |
| 380 expect( | 413 expect( |
| 381 () => new StringScanner('foo bar', position: 8), throwsArgumentError); | 414 () => new StringScanner('foo bar', position: 8), throwsArgumentError); |
| 382 }); | 415 }); |
| 383 }); | 416 }); |
| 384 } | 417 } |
| OLD | NEW |