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

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

Issue 299973002: Add LineScanner and SpanScanner classes to string_scanner. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/string_scanner/test/error_test.dart ('k') | pkg/string_scanner/test/line_scanner_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library string_scanner.expect_error_test;
6
7 import 'package:string_scanner/string_scanner.dart';
8 import 'package:unittest/unittest.dart';
9
10 import 'utils.dart';
11
12 void main() {
13 test('points to the first unconsumed character', () {
14 var scanner = new StringScanner('foo bar baz');
15 scanner.expect('foo ');
16 expect(() => scanner.expect('foo'), throwsFormattedError('''
17 Error on line 1, column 5: expected "foo".
18 foo bar baz
19 ^'''));
20 });
21
22 test('prints the correct line', () {
23 var scanner = new StringScanner('foo bar baz\ndo re mi\nearth fire water');
24 scanner.expect('foo bar baz\ndo ');
25 expect(() => scanner.expect('foo'), throwsFormattedError('''
26 Error on line 2, column 4: expected "foo".
27 do re mi
28 ^'''));
29 });
30
31 test('handles the beginning of the string correctly', () {
32 var scanner = new StringScanner('foo bar baz');
33 expect(() => scanner.expect('zap'), throwsFormattedError('''
34 Error on line 1, column 1: expected "zap".
35 foo bar baz
36 ^'''));
37 });
38
39 test('handles the end of the string correctly', () {
40 var scanner = new StringScanner('foo bar baz');
41 scanner.expect('foo bar baz');
42 expect(() => scanner.expect('bang'), throwsFormattedError('''
43 Error on line 1, column 12: expected "bang".
44 foo bar baz
45 ^'''));
46 });
47
48 test('handles an empty string correctly', () {
49 expect(() => new StringScanner('').expect('foo'), throwsFormattedError('''
50 Error on line 1, column 1: expected "foo".
51
52 ^'''));
53 });
54
55 group("expected name", () {
56 test("uses the provided name", () {
57 expect(() => new StringScanner('').expect('foo bar', name: 'zap'),
58 throwsFormattedError('''
59 Error on line 1, column 1: expected zap.
60
61 ^'''));
62 });
63
64 test("escapes string quotes", () {
65 expect(() => new StringScanner('').expect('foo"bar'),
66 throwsFormattedError('''
67 Error on line 1, column 1: expected "foo\\"bar".
68
69 ^'''));
70 });
71
72 test("escapes string backslashes", () {
73 expect(() => new StringScanner('').expect('foo\\bar'),
74 throwsFormattedError('''
75 Error on line 1, column 1: expected "foo\\\\bar".
76
77 ^'''));
78 });
79
80 test("prints PERL-style regexps", () {
81 expect(() => new StringScanner('').expect(new RegExp(r'foo')),
82 throwsFormattedError('''
83 Error on line 1, column 1: expected /foo/.
84
85 ^'''));
86 });
87
88 test("escape regexp forward slashes", () {
89 expect(() => new StringScanner('').expect(new RegExp(r'foo/bar')),
90 throwsFormattedError('''
91 Error on line 1, column 1: expected /foo\\/bar/.
92
93 ^'''));
94 });
95
96 test("does not escape regexp backslashes", () {
97 expect(() => new StringScanner('').expect(new RegExp(r'foo\bar')),
98 throwsFormattedError('''
99 Error on line 1, column 1: expected /foo\\bar/.
100
101 ^'''));
102 });
103 });
104 }
OLDNEW
« no previous file with comments | « pkg/string_scanner/test/error_test.dart ('k') | pkg/string_scanner/test/line_scanner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698