| 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 analyzer.test.generated.scanner_test; | 5 library analyzer.test.generated.scanner_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
| 8 import 'package:analyzer/src/dart/ast/token.dart'; | 8 import 'package:analyzer/src/dart/ast/token.dart'; |
| 9 import 'package:analyzer/src/dart/scanner/reader.dart'; | 9 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 10 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 void test_lineInfo_slashN() { | 118 void test_lineInfo_slashN() { |
| 119 String source = "class Test {\n}"; | 119 String source = "class Test {\n}"; |
| 120 _assertLineInfo(source, [ | 120 _assertLineInfo(source, [ |
| 121 new ScannerTest_ExpectedLocation(0, 1, 1), | 121 new ScannerTest_ExpectedLocation(0, 1, 1), |
| 122 new ScannerTest_ExpectedLocation(source.indexOf("}"), 2, 1) | 122 new ScannerTest_ExpectedLocation(source.indexOf("}"), 2, 1) |
| 123 ]); | 123 ]); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void test_linestarts() { |
| 127 String source = "var\r\ni\n=\n1;\n"; |
| 128 GatheringErrorListener listener = new GatheringErrorListener(); |
| 129 Scanner scanner = |
| 130 new Scanner(null, new CharSequenceReader(source), listener); |
| 131 var token = scanner.tokenize(); |
| 132 expect(token.lexeme, 'var'); |
| 133 var lineStarts = scanner.lineStarts; |
| 134 expect(lineStarts, orderedEquals([0, 5, 7, 9, 12])); |
| 135 } |
| 136 |
| 126 void _assertLineInfo( | 137 void _assertLineInfo( |
| 127 String source, List<ScannerTest_ExpectedLocation> expectedLocations) { | 138 String source, List<ScannerTest_ExpectedLocation> expectedLocations) { |
| 128 GatheringErrorListener listener = new GatheringErrorListener(); | 139 GatheringErrorListener listener = new GatheringErrorListener(); |
| 129 _scanWithListener(source, listener); | 140 _scanWithListener(source, listener); |
| 130 listener.assertNoErrors(); | 141 listener.assertNoErrors(); |
| 131 LineInfo info = listener.getLineInfo(new TestSource()); | 142 LineInfo info = listener.getLineInfo(new TestSource()); |
| 132 expect(info, isNotNull); | 143 expect(info, isNotNull); |
| 133 int count = expectedLocations.length; | 144 int count = expectedLocations.length; |
| 134 for (int i = 0; i < count; i++) { | 145 for (int i = 0; i < count; i++) { |
| 135 ScannerTest_ExpectedLocation expectedLocation = expectedLocations[i]; | 146 ScannerTest_ExpectedLocation expectedLocation = expectedLocations[i]; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 buffer.write(token.type); | 238 buffer.write(token.type); |
| 228 buffer.write(", '"); | 239 buffer.write(", '"); |
| 229 buffer.write(token.lexeme); | 240 buffer.write(token.lexeme); |
| 230 buffer.write("', "); | 241 buffer.write("', "); |
| 231 buffer.write(token.offset); | 242 buffer.write(token.offset); |
| 232 buffer.write(", "); | 243 buffer.write(", "); |
| 233 buffer.write(token.length); | 244 buffer.write(token.length); |
| 234 buffer.write("]"); | 245 buffer.write("]"); |
| 235 } | 246 } |
| 236 } | 247 } |
| OLD | NEW |