OLD | NEW |
1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
3 | 3 |
4 library engine.ast_test; | 4 library engine.ast_test; |
5 | 5 |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 import 'package:analyzer_experimental/src/generated/java_core.dart'; | 7 import 'package:analyzer_experimental/src/generated/java_core.dart'; |
8 import 'package:analyzer_experimental/src/generated/java_engine.dart'; | 8 import 'package:analyzer_experimental/src/generated/java_engine.dart'; |
9 import 'package:analyzer_experimental/src/generated/java_junit.dart'; | 9 import 'package:analyzer_experimental/src/generated/java_junit.dart'; |
10 import 'package:analyzer_experimental/src/generated/source.dart'; | 10 import 'package:analyzer_experimental/src/generated/source.dart'; |
11 import 'package:analyzer_experimental/src/generated/error.dart'; | 11 import 'package:analyzer_experimental/src/generated/error.dart'; |
12 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 12 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
13 import 'package:analyzer_experimental/src/generated/ast.dart'; | 13 import 'package:analyzer_experimental/src/generated/ast.dart'; |
14 import 'package:analyzer_experimental/src/generated/utilities_dart.dart'; | 14 import 'package:analyzer_experimental/src/generated/utilities_dart.dart'; |
15 import 'package:analyzer_experimental/src/generated/element.dart' show ClassElem
ent; | 15 import 'package:analyzer_experimental/src/generated/element.dart' show ClassElem
ent; |
16 import 'package:unittest/unittest.dart' as _ut; | 16 import 'package:unittest/unittest.dart' as _ut; |
17 import 'parser_test.dart' show ParserTestCase; | 17 import 'parser_test.dart' show ParserTestCase; |
18 import 'test_support.dart'; | 18 import 'test_support.dart'; |
19 import 'scanner_test.dart' show TokenFactory; | 19 import 'scanner_test.dart' show TokenFactory; |
20 | 20 |
21 class NodeLocatorTest extends ParserTestCase { | 21 class NodeLocatorTest extends ParserTestCase { |
22 void test_offset() { | 22 void test_offset() { |
23 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;",
[]); | 23 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;",
[]); |
24 assertLocate(unit, 10, SimpleIdentifier); | 24 assertLocate(unit, 10, SimpleIdentifier); |
25 } | 25 } |
| 26 void test_offsetAfterNode() { |
| 27 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr
eateSource(["class A {}", "class B {}"]), []); |
| 28 NodeLocator locator = new NodeLocator.con2(1024, 1024); |
| 29 ASTNode node = locator.searchWithin(unit.declarations[0]); |
| 30 JUnitTestCase.assertNull(node); |
| 31 } |
| 32 void test_offsetBeforeNode() { |
| 33 CompilationUnit unit = ParserTestCase.parseCompilationUnit(EngineTestCase.cr
eateSource(["class A {}", "class B {}"]), []); |
| 34 NodeLocator locator = new NodeLocator.con2(0, 0); |
| 35 ASTNode node = locator.searchWithin(unit.declarations[1]); |
| 36 JUnitTestCase.assertNull(node); |
| 37 } |
26 void test_range() { | 38 void test_range() { |
27 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;",
[]); | 39 CompilationUnit unit = ParserTestCase.parseCompilationUnit("library myLib;",
[]); |
28 assertLocate2(unit, 4, 10, LibraryDirective); | 40 assertLocate2(unit, 4, 10, LibraryDirective); |
29 } | 41 } |
30 void assertLocate(CompilationUnit unit, int offset, Type expectedClass) { | 42 void assertLocate(CompilationUnit unit, int offset, Type expectedClass) { |
31 assertLocate2(unit, offset, offset, expectedClass); | 43 assertLocate2(unit, offset, offset, expectedClass); |
32 } | 44 } |
33 void assertLocate2(CompilationUnit unit, int start, int end, Type expectedClas
s) { | 45 void assertLocate2(CompilationUnit unit, int start, int end, Type expectedClas
s) { |
34 NodeLocator locator = new NodeLocator.con2(start, end); | 46 NodeLocator locator = new NodeLocator.con2(start, end); |
35 ASTNode node = locator.searchWithin(unit); | 47 ASTNode node = locator.searchWithin(unit); |
36 JUnitTestCase.assertNotNull(node); | 48 JUnitTestCase.assertNotNull(node); |
37 JUnitTestCase.assertTrueMsg("Node starts after range", node.offset <= start)
; | 49 JUnitTestCase.assertTrueMsg("Node starts after range", node.offset <= start)
; |
38 JUnitTestCase.assertTrueMsg("Node ends before range", node.offset + node.len
gth > end); | 50 JUnitTestCase.assertTrueMsg("Node ends before range", node.offset + node.len
gth > end); |
39 EngineTestCase.assertInstanceOf(expectedClass, node); | 51 EngineTestCase.assertInstanceOf(expectedClass, node); |
40 } | 52 } |
41 static dartSuite() { | 53 static dartSuite() { |
42 _ut.group('NodeLocatorTest', () { | 54 _ut.group('NodeLocatorTest', () { |
43 _ut.test('test_offset', () { | 55 _ut.test('test_offset', () { |
44 final __test = new NodeLocatorTest(); | 56 final __test = new NodeLocatorTest(); |
45 runJUnitTest(__test, __test.test_offset); | 57 runJUnitTest(__test, __test.test_offset); |
46 }); | 58 }); |
| 59 _ut.test('test_offsetAfterNode', () { |
| 60 final __test = new NodeLocatorTest(); |
| 61 runJUnitTest(__test, __test.test_offsetAfterNode); |
| 62 }); |
| 63 _ut.test('test_offsetBeforeNode', () { |
| 64 final __test = new NodeLocatorTest(); |
| 65 runJUnitTest(__test, __test.test_offsetBeforeNode); |
| 66 }); |
47 _ut.test('test_range', () { | 67 _ut.test('test_range', () { |
48 final __test = new NodeLocatorTest(); | 68 final __test = new NodeLocatorTest(); |
49 runJUnitTest(__test, __test.test_range); | 69 runJUnitTest(__test, __test.test_range); |
50 }); | 70 }); |
51 }); | 71 }); |
52 } | 72 } |
53 } | 73 } |
54 class IndexExpressionTest extends EngineTestCase { | 74 class IndexExpressionTest extends EngineTestCase { |
55 void test_inGetterContext_assignment_compound_left() { | 75 void test_inGetterContext_assignment_compound_left() { |
56 IndexExpression expression = ASTFactory.indexExpression(ASTFactory.identifie
r3("a"), ASTFactory.identifier3("b")); | 76 IndexExpression expression = ASTFactory.indexExpression(ASTFactory.identifie
r3("a"), ASTFactory.identifier3("b")); |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 } | 569 } |
550 return identifier; | 570 return identifier; |
551 } | 571 } |
552 /** | 572 /** |
553 * Return the top-most node in the AST structure containing the given identifi
er. | 573 * Return the top-most node in the AST structure containing the given identifi
er. |
554 * @param identifier the identifier in the AST structure being traversed | 574 * @param identifier the identifier in the AST structure being traversed |
555 * @return the root of the AST structure containing the identifier | 575 * @return the root of the AST structure containing the identifier |
556 */ | 576 */ |
557 ASTNode topMostNode(SimpleIdentifier identifier) { | 577 ASTNode topMostNode(SimpleIdentifier identifier) { |
558 ASTNode child = identifier; | 578 ASTNode child = identifier; |
559 ASTNode parent19 = identifier.parent; | 579 ASTNode parent20 = identifier.parent; |
560 while (parent19 != null) { | 580 while (parent20 != null) { |
561 child = parent19; | 581 child = parent20; |
562 parent19 = parent19.parent; | 582 parent20 = parent20.parent; |
563 } | 583 } |
564 return child; | 584 return child; |
565 } | 585 } |
566 static dartSuite() { | 586 static dartSuite() { |
567 _ut.group('SimpleIdentifierTest', () { | 587 _ut.group('SimpleIdentifierTest', () { |
568 _ut.test('test_inDeclarationContext_argumentDefinition', () { | 588 _ut.test('test_inDeclarationContext_argumentDefinition', () { |
569 final __test = new SimpleIdentifierTest(); | 589 final __test = new SimpleIdentifierTest(); |
570 runJUnitTest(__test, __test.test_inDeclarationContext_argumentDefinition
); | 590 runJUnitTest(__test, __test.test_inDeclarationContext_argumentDefinition
); |
571 }); | 591 }); |
572 _ut.test('test_inDeclarationContext_catch_exception', () { | 592 _ut.test('test_inDeclarationContext_catch_exception', () { |
(...skipping 2278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2851 }); | 2871 }); |
2852 } | 2872 } |
2853 } | 2873 } |
2854 main() { | 2874 main() { |
2855 ConstantEvaluatorTest.dartSuite(); | 2875 ConstantEvaluatorTest.dartSuite(); |
2856 NodeLocatorTest.dartSuite(); | 2876 NodeLocatorTest.dartSuite(); |
2857 ToSourceVisitorTest.dartSuite(); | 2877 ToSourceVisitorTest.dartSuite(); |
2858 IndexExpressionTest.dartSuite(); | 2878 IndexExpressionTest.dartSuite(); |
2859 SimpleIdentifierTest.dartSuite(); | 2879 SimpleIdentifierTest.dartSuite(); |
2860 } | 2880 } |
OLD | NEW |