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

Side by Side Diff: packages/string_scanner/test/line_scanner_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
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.line_scanner_test;
6
7 import 'package:string_scanner/string_scanner.dart';
8 import 'package:test/test.dart';
9
10 void main() {
11 var scanner;
12 setUp(() {
13 scanner = new LineScanner('foo\nbar\r\nbaz');
14 });
15
16 test('begins with line and column 0', () {
17 expect(scanner.line, equals(0));
18 expect(scanner.column, equals(0));
19 });
20
21 group("scan()", () {
22 test("consuming no newlines increases the column but not the line", () {
23 scanner.scan('foo');
24 expect(scanner.line, equals(0));
25 expect(scanner.column, equals(3));
26 });
27
28 test("consuming a newline resets the column and increases the line", () {
29 scanner.expect('foo\nba');
30 expect(scanner.line, equals(1));
31 expect(scanner.column, equals(2));
32 });
33
34 test("consuming multiple newlines resets the column and increases the line",
35 () {
36 scanner.expect('foo\nbar\r\nb');
37 expect(scanner.line, equals(2));
38 expect(scanner.column, equals(1));
39 });
40
41 test("consuming halfway through a CR LF doesn't count as a line", () {
42 scanner.expect('foo\nbar\r');
43 expect(scanner.line, equals(1));
44 expect(scanner.column, equals(4));
45
46 scanner.expect('\nb');
47 expect(scanner.line, equals(2));
48 expect(scanner.column, equals(1));
49 });
50 });
51
52 group("readChar()", () {
53 test("on a non-newline character increases the column but not the line",
54 () {
55 scanner.readChar();
56 expect(scanner.line, equals(0));
57 expect(scanner.column, equals(1));
58 });
59
60 test("consuming a newline resets the column and increases the line", () {
61 scanner.expect('foo');
62 expect(scanner.line, equals(0));
63 expect(scanner.column, equals(3));
64
65 scanner.readChar();
66 expect(scanner.line, equals(1));
67 expect(scanner.column, equals(0));
68 });
69
70 test("consuming halfway through a CR LF doesn't count as a line", () {
71 scanner.expect('foo\nbar');
72 expect(scanner.line, equals(1));
73 expect(scanner.column, equals(3));
74
75 scanner.readChar();
76 expect(scanner.line, equals(1));
77 expect(scanner.column, equals(4));
78
79 scanner.readChar();
80 expect(scanner.line, equals(2));
81 expect(scanner.column, equals(0));
82 });
83 });
84
85 group("position=", () {
86 test("forward through newlines sets the line and column", () {
87 scanner.position = 10; // "foo\nbar\r\nb"
88 expect(scanner.line, equals(2));
89 expect(scanner.column, equals(1));
90 });
91
92 test("forward through no newlines sets the column", () {
93 scanner.position = 2; // "fo"
94 expect(scanner.line, equals(0));
95 expect(scanner.column, equals(2));
96 });
97
98 test("backward through newlines sets the line and column", () {
99 scanner.scan("foo\nbar\r\nbaz");
100 scanner.position = 2; // "fo"
101 expect(scanner.line, equals(0));
102 expect(scanner.column, equals(2));
103 });
104
105 test("backward through no newlines sets the column", () {
106 scanner.scan("foo\nbar\r\nbaz");
107 scanner.position = 10; // "foo\nbar\r\nb"
108 expect(scanner.line, equals(2));
109 expect(scanner.column, equals(1));
110 });
111
112 test("forward halfway through a CR LF doesn't count as a line", () {
113 scanner.position = 8; // "foo\nbar\r"
114 expect(scanner.line, equals(1));
115 expect(scanner.column, equals(4));
116 });
117 });
118
119 test("state= restores the line, column, and position", () {
120 scanner.scan('foo\nb');
121 var state = scanner.state;
122
123 scanner.scan('ar\nba');
124 scanner.state = state;
125 expect(scanner.rest, equals('ar\r\nbaz'));
126 expect(scanner.line, equals(1));
127 expect(scanner.column, equals(1));
128 });
129
130 test("state= rejects a foreign state", () {
131 scanner.scan('foo\nb');
132
133 expect(() => new LineScanner(scanner.string).state = scanner.state,
134 throwsArgumentError);
135 });
136 }
OLDNEW
« no previous file with comments | « packages/string_scanner/test/error_test.dart ('k') | packages/string_scanner/test/span_scanner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698