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

Side by Side Diff: pkg/analyzer/test/generated/scanner_test.dart

Issue 156763002: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.scanner_test; 8 library engine.scanner_test;
9 9
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 _ut.test('test_KeywordState', () { 63 _ut.test('test_KeywordState', () {
64 final __test = new KeywordStateTest(); 64 final __test = new KeywordStateTest();
65 runJUnitTest(__test, __test.test_KeywordState); 65 runJUnitTest(__test, __test.test_KeywordState);
66 }); 66 });
67 }); 67 });
68 } 68 }
69 } 69 }
70 70
71 class CharSequenceReaderTest extends JUnitTestCase { 71 class CharSequenceReaderTest extends JUnitTestCase {
72 void test_advance() { 72 void test_advance() {
73 CharSequenceReader reader = new CharSequenceReader(new CharSequence("x")); 73 CharSequenceReader reader = new CharSequenceReader("x");
74 JUnitTestCase.assertEquals(0x78, reader.advance()); 74 JUnitTestCase.assertEquals(0x78, reader.advance());
75 JUnitTestCase.assertEquals(-1, reader.advance()); 75 JUnitTestCase.assertEquals(-1, reader.advance());
76 JUnitTestCase.assertEquals(-1, reader.advance()); 76 JUnitTestCase.assertEquals(-1, reader.advance());
77 } 77 }
78 78
79 void test_creation() { 79 void test_creation() {
80 JUnitTestCase.assertNotNull(new CharSequenceReader(new CharSequence("x"))); 80 JUnitTestCase.assertNotNull(new CharSequenceReader("x"));
81 } 81 }
82 82
83 void test_getOffset() { 83 void test_getOffset() {
84 CharSequenceReader reader = new CharSequenceReader(new CharSequence("x")); 84 CharSequenceReader reader = new CharSequenceReader("x");
85 JUnitTestCase.assertEquals(-1, reader.offset); 85 JUnitTestCase.assertEquals(-1, reader.offset);
86 reader.advance(); 86 reader.advance();
87 JUnitTestCase.assertEquals(0, reader.offset); 87 JUnitTestCase.assertEquals(0, reader.offset);
88 reader.advance(); 88 reader.advance();
89 JUnitTestCase.assertEquals(0, reader.offset); 89 JUnitTestCase.assertEquals(0, reader.offset);
90 } 90 }
91 91
92 void test_getString() { 92 void test_getString() {
93 CharSequenceReader reader = new CharSequenceReader(new CharSequence("xyzzy") ); 93 CharSequenceReader reader = new CharSequenceReader("xyzzy");
94 reader.offset = 3; 94 reader.offset = 3;
95 JUnitTestCase.assertEquals("yzz", reader.getString(1, 0)); 95 JUnitTestCase.assertEquals("yzz", reader.getString(1, 0));
96 JUnitTestCase.assertEquals("zzy", reader.getString(2, 1)); 96 JUnitTestCase.assertEquals("zzy", reader.getString(2, 1));
97 } 97 }
98 98
99 void test_peek() { 99 void test_peek() {
100 CharSequenceReader reader = new CharSequenceReader(new CharSequence("xy")); 100 CharSequenceReader reader = new CharSequenceReader("xy");
101 JUnitTestCase.assertEquals(0x78, reader.peek()); 101 JUnitTestCase.assertEquals(0x78, reader.peek());
102 JUnitTestCase.assertEquals(0x78, reader.peek()); 102 JUnitTestCase.assertEquals(0x78, reader.peek());
103 reader.advance(); 103 reader.advance();
104 JUnitTestCase.assertEquals(0x79, reader.peek()); 104 JUnitTestCase.assertEquals(0x79, reader.peek());
105 JUnitTestCase.assertEquals(0x79, reader.peek()); 105 JUnitTestCase.assertEquals(0x79, reader.peek());
106 reader.advance(); 106 reader.advance();
107 JUnitTestCase.assertEquals(-1, reader.peek()); 107 JUnitTestCase.assertEquals(-1, reader.peek());
108 JUnitTestCase.assertEquals(-1, reader.peek()); 108 JUnitTestCase.assertEquals(-1, reader.peek());
109 } 109 }
110 110
111 void test_setOffset() { 111 void test_setOffset() {
112 CharSequenceReader reader = new CharSequenceReader(new CharSequence("xyz")); 112 CharSequenceReader reader = new CharSequenceReader("xyz");
113 reader.offset = 2; 113 reader.offset = 2;
114 JUnitTestCase.assertEquals(2, reader.offset); 114 JUnitTestCase.assertEquals(2, reader.offset);
115 } 115 }
116 116
117 static dartSuite() { 117 static dartSuite() {
118 _ut.group('CharSequenceReaderTest', () { 118 _ut.group('CharSequenceReaderTest', () {
119 _ut.test('test_advance', () { 119 _ut.test('test_advance', () {
120 final __test = new CharSequenceReaderTest(); 120 final __test = new CharSequenceReaderTest();
121 runJUnitTest(__test, __test.test_advance); 121 runJUnitTest(__test, __test.test_advance);
122 }); 122 });
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 368
369 void test_colon() { 369 void test_colon() {
370 assertToken(TokenType.COLON, ":"); 370 assertToken(TokenType.COLON, ":");
371 } 371 }
372 372
373 void test_comma() { 373 void test_comma() {
374 assertToken(TokenType.COMMA, ","); 374 assertToken(TokenType.COMMA, ",");
375 } 375 }
376 376
377 void test_comment_disabled_multi() { 377 void test_comment_disabled_multi() {
378 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence( "/* comment */ ")), AnalysisErrorListener.NULL_LISTENER); 378 Scanner scanner = new Scanner(null, new CharSequenceReader("/* comment */ ") , AnalysisErrorListener.NULL_LISTENER);
379 scanner.preserveComments = false; 379 scanner.preserveComments = false;
380 Token token = scanner.tokenize(); 380 Token token = scanner.tokenize();
381 JUnitTestCase.assertNotNull(token); 381 JUnitTestCase.assertNotNull(token);
382 JUnitTestCase.assertNull(token.precedingComments); 382 JUnitTestCase.assertNull(token.precedingComments);
383 } 383 }
384 384
385 void test_comment_multi() { 385 void test_comment_multi() {
386 assertComment(TokenType.MULTI_LINE_COMMENT, "/* comment */"); 386 assertComment(TokenType.MULTI_LINE_COMMENT, "/* comment */");
387 } 387 }
388 388
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 assertToken(TokenType.SCRIPT_TAG, "#! /bin/dart"); 831 assertToken(TokenType.SCRIPT_TAG, "#! /bin/dart");
832 } 832 }
833 833
834 void test_semicolon() { 834 void test_semicolon() {
835 assertToken(TokenType.SEMICOLON, ";"); 835 assertToken(TokenType.SEMICOLON, ";");
836 } 836 }
837 837
838 void test_setSourceStart() { 838 void test_setSourceStart() {
839 int offsetDelta = 42; 839 int offsetDelta = 42;
840 GatheringErrorListener listener = new GatheringErrorListener(); 840 GatheringErrorListener listener = new GatheringErrorListener();
841 Scanner scanner = new Scanner(null, new SubSequenceReader(new CharSequence(" a"), offsetDelta), listener); 841 Scanner scanner = new Scanner(null, new SubSequenceReader("a", offsetDelta), listener);
842 scanner.setSourceStart(3, 9); 842 scanner.setSourceStart(3, 9);
843 scanner.tokenize(); 843 scanner.tokenize();
844 List<int> lineStarts = scanner.lineStarts; 844 List<int> lineStarts = scanner.lineStarts;
845 JUnitTestCase.assertNotNull(lineStarts); 845 JUnitTestCase.assertNotNull(lineStarts);
846 JUnitTestCase.assertEquals(3, lineStarts.length); 846 JUnitTestCase.assertEquals(3, lineStarts.length);
847 JUnitTestCase.assertEquals(33, lineStarts[2]); 847 JUnitTestCase.assertEquals(33, lineStarts[2]);
848 } 848 }
849 849
850 void test_slash() { 850 void test_slash() {
851 assertToken(TokenType.SLASH, "/"); 851 assertToken(TokenType.SLASH, "/");
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 } 1204 }
1205 1205
1206 Token scan(String source) { 1206 Token scan(String source) {
1207 GatheringErrorListener listener = new GatheringErrorListener(); 1207 GatheringErrorListener listener = new GatheringErrorListener();
1208 Token token = scan2(source, listener); 1208 Token token = scan2(source, listener);
1209 listener.assertNoErrors(); 1209 listener.assertNoErrors();
1210 return token; 1210 return token;
1211 } 1211 }
1212 1212
1213 Token scan2(String source, GatheringErrorListener listener) { 1213 Token scan2(String source, GatheringErrorListener listener) {
1214 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence( source)), listener); 1214 Scanner scanner = new Scanner(null, new CharSequenceReader(source), listener );
1215 Token result = scanner.tokenize(); 1215 Token result = scanner.tokenize();
1216 listener.setLineInfo(new TestSource(), scanner.lineStarts); 1216 listener.setLineInfo(new TestSource(), scanner.lineStarts);
1217 return result; 1217 return result;
1218 } 1218 }
1219 1219
1220 static dartSuite() { 1220 static dartSuite() {
1221 _ut.group('ScannerTest', () { 1221 _ut.group('ScannerTest', () {
1222 _ut.test('test_ampersand', () { 1222 _ut.test('test_ampersand', () {
1223 final __test = new ScannerTest(); 1223 final __test = new ScannerTest();
1224 runJUnitTest(__test, __test.test_ampersand); 1224 runJUnitTest(__test, __test.test_ampersand);
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 // Compute the information needed to perform the test. 2243 // Compute the information needed to perform the test.
2244 // 2244 //
2245 String originalContents = "${prefix}${removed}${suffix}"; 2245 String originalContents = "${prefix}${removed}${suffix}";
2246 String modifiedContents = "${prefix}${added}${suffix}"; 2246 String modifiedContents = "${prefix}${added}${suffix}";
2247 int replaceStart = prefix.length; 2247 int replaceStart = prefix.length;
2248 Source source = new TestSource(); 2248 Source source = new TestSource();
2249 // 2249 //
2250 // Scan the original contents. 2250 // Scan the original contents.
2251 // 2251 //
2252 GatheringErrorListener originalListener = new GatheringErrorListener(); 2252 GatheringErrorListener originalListener = new GatheringErrorListener();
2253 Scanner originalScanner = new Scanner(source, new CharSequenceReader(new Cha rSequence(originalContents)), originalListener); 2253 Scanner originalScanner = new Scanner(source, new CharSequenceReader(origina lContents), originalListener);
2254 _originalTokens = originalScanner.tokenize(); 2254 _originalTokens = originalScanner.tokenize();
2255 JUnitTestCase.assertNotNull(_originalTokens); 2255 JUnitTestCase.assertNotNull(_originalTokens);
2256 // 2256 //
2257 // Scan the modified contents. 2257 // Scan the modified contents.
2258 // 2258 //
2259 GatheringErrorListener modifiedListener = new GatheringErrorListener(); 2259 GatheringErrorListener modifiedListener = new GatheringErrorListener();
2260 Scanner modifiedScanner = new Scanner(source, new CharSequenceReader(new Cha rSequence(modifiedContents)), modifiedListener); 2260 Scanner modifiedScanner = new Scanner(source, new CharSequenceReader(modifie dContents), modifiedListener);
2261 Token modifiedTokens = modifiedScanner.tokenize(); 2261 Token modifiedTokens = modifiedScanner.tokenize();
2262 JUnitTestCase.assertNotNull(modifiedTokens); 2262 JUnitTestCase.assertNotNull(modifiedTokens);
2263 // 2263 //
2264 // Incrementally scan the modified contents. 2264 // Incrementally scan the modified contents.
2265 // 2265 //
2266 GatheringErrorListener incrementalListener = new GatheringErrorListener(); 2266 GatheringErrorListener incrementalListener = new GatheringErrorListener();
2267 _incrementalScanner = new IncrementalScanner(source, new CharSequenceReader( new CharSequence(modifiedContents)), incrementalListener); 2267 _incrementalScanner = new IncrementalScanner(source, new CharSequenceReader( modifiedContents), incrementalListener);
2268 _incrementalTokens = _incrementalScanner.rescan(_originalTokens, replaceStar t, removed.length, added.length); 2268 _incrementalTokens = _incrementalScanner.rescan(_originalTokens, replaceStar t, removed.length, added.length);
2269 // 2269 //
2270 // Validate that the results of the incremental scan are the same as the ful l scan of the 2270 // Validate that the results of the incremental scan are the same as the ful l scan of the
2271 // modified source. 2271 // modified source.
2272 // 2272 //
2273 Token incrementalToken = _incrementalTokens; 2273 Token incrementalToken = _incrementalTokens;
2274 JUnitTestCase.assertNotNull(incrementalToken); 2274 JUnitTestCase.assertNotNull(incrementalToken);
2275 while (incrementalToken.type != TokenType.EOF && modifiedTokens.type != Toke nType.EOF) { 2275 while (incrementalToken.type != TokenType.EOF && modifiedTokens.type != Toke nType.EOF) {
2276 JUnitTestCase.assertSameMsg("Wrong type for token", modifiedTokens.type, i ncrementalToken.type); 2276 JUnitTestCase.assertSameMsg("Wrong type for token", modifiedTokens.type, i ncrementalToken.type);
2277 JUnitTestCase.assertEqualsMsg("Wrong offset for token", modifiedTokens.off set, incrementalToken.offset); 2277 JUnitTestCase.assertEqualsMsg("Wrong offset for token", modifiedTokens.off set, incrementalToken.offset);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 } 2414 }
2415 } 2415 }
2416 2416
2417 main() { 2417 main() {
2418 CharSequenceReaderTest.dartSuite(); 2418 CharSequenceReaderTest.dartSuite();
2419 IncrementalScannerTest.dartSuite(); 2419 IncrementalScannerTest.dartSuite();
2420 KeywordStateTest.dartSuite(); 2420 KeywordStateTest.dartSuite();
2421 ScannerTest.dartSuite(); 2421 ScannerTest.dartSuite();
2422 TokenTypeTest.dartSuite(); 2422 TokenTypeTest.dartSuite();
2423 } 2423 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698