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: packages/string_scanner/test/line_scanner_test.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 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
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.line_scanner_test; 5 import 'package:charcode/charcode.dart';
6
7 import 'package:string_scanner/string_scanner.dart'; 6 import 'package:string_scanner/string_scanner.dart';
8 import 'package:test/test.dart'; 7 import 'package:test/test.dart';
9 8
10 void main() { 9 void main() {
11 var scanner; 10 var scanner;
12 setUp(() { 11 setUp(() {
13 scanner = new LineScanner('foo\nbar\r\nbaz'); 12 scanner = new LineScanner('foo\nbar\r\nbaz');
14 }); 13 });
15 14
16 test('begins with line and column 0', () { 15 test('begins with line and column 0', () {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 scanner.readChar(); 74 scanner.readChar();
76 expect(scanner.line, equals(1)); 75 expect(scanner.line, equals(1));
77 expect(scanner.column, equals(4)); 76 expect(scanner.column, equals(4));
78 77
79 scanner.readChar(); 78 scanner.readChar();
80 expect(scanner.line, equals(2)); 79 expect(scanner.line, equals(2));
81 expect(scanner.column, equals(0)); 80 expect(scanner.column, equals(0));
82 }); 81 });
83 }); 82 });
84 83
84 group("scanChar()", () {
85 test("on a non-newline character increases the column but not the line",
86 () {
87 scanner.scanChar($f);
88 expect(scanner.line, equals(0));
89 expect(scanner.column, equals(1));
90 });
91
92 test("consuming a newline resets the column and increases the line", () {
93 scanner.expect('foo');
94 expect(scanner.line, equals(0));
95 expect(scanner.column, equals(3));
96
97 scanner.scanChar($lf);
98 expect(scanner.line, equals(1));
99 expect(scanner.column, equals(0));
100 });
101
102 test("consuming halfway through a CR LF doesn't count as a line", () {
103 scanner.expect('foo\nbar');
104 expect(scanner.line, equals(1));
105 expect(scanner.column, equals(3));
106
107 scanner.scanChar($cr);
108 expect(scanner.line, equals(1));
109 expect(scanner.column, equals(4));
110
111 scanner.scanChar($lf);
112 expect(scanner.line, equals(2));
113 expect(scanner.column, equals(0));
114 });
115 });
116
85 group("position=", () { 117 group("position=", () {
86 test("forward through newlines sets the line and column", () { 118 test("forward through newlines sets the line and column", () {
87 scanner.position = 10; // "foo\nbar\r\nb" 119 scanner.position = 10; // "foo\nbar\r\nb"
88 expect(scanner.line, equals(2)); 120 expect(scanner.line, equals(2));
89 expect(scanner.column, equals(1)); 121 expect(scanner.column, equals(1));
90 }); 122 });
91 123
92 test("forward through no newlines sets the column", () { 124 test("forward through no newlines sets the column", () {
93 scanner.position = 2; // "fo" 125 scanner.position = 2; // "fo"
94 expect(scanner.line, equals(0)); 126 expect(scanner.line, equals(0));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 expect(scanner.column, equals(1)); 159 expect(scanner.column, equals(1));
128 }); 160 });
129 161
130 test("state= rejects a foreign state", () { 162 test("state= rejects a foreign state", () {
131 scanner.scan('foo\nb'); 163 scanner.scan('foo\nb');
132 164
133 expect(() => new LineScanner(scanner.string).state = scanner.state, 165 expect(() => new LineScanner(scanner.string).state = scanner.state,
134 throwsArgumentError); 166 throwsArgumentError);
135 }); 167 });
136 } 168 }
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