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.src.dart.ast.utilities_test; | 5 library analyzer.test.src.dart.ast.utilities_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
8 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 11 import 'package:analyzer/dart/element/type.dart'; |
11 import 'package:analyzer/src/dart/ast/utilities.dart'; | 12 import 'package:analyzer/src/dart/ast/utilities.dart'; |
12 import 'package:analyzer/src/dart/element/element.dart'; | 13 import 'package:analyzer/src/dart/element/element.dart'; |
13 import 'package:analyzer/src/generated/java_core.dart'; | 14 import 'package:analyzer/src/generated/java_core.dart'; |
14 import 'package:analyzer/src/generated/java_engine.dart' show Predicate; | 15 import 'package:analyzer/src/generated/java_engine.dart' show Predicate; |
15 import 'package:analyzer/src/generated/java_engine.dart'; | 16 import 'package:analyzer/src/generated/java_engine.dart'; |
16 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; | 17 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; |
17 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 18 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 expect(node.offset <= start, isTrue, reason: "Node starts after range"); | 431 expect(node.offset <= start, isTrue, reason: "Node starts after range"); |
431 expect(node.offset + node.length > end, isTrue, | 432 expect(node.offset + node.length > end, isTrue, |
432 reason: "Node ends before range"); | 433 reason: "Node ends before range"); |
433 EngineTestCase.assertInstanceOf(predicate, expectedClass, node); | 434 EngineTestCase.assertInstanceOf(predicate, expectedClass, node); |
434 } | 435 } |
435 } | 436 } |
436 | 437 |
437 @reflectiveTest | 438 @reflectiveTest |
438 class ResolutionCopierTest extends EngineTestCase { | 439 class ResolutionCopierTest extends EngineTestCase { |
439 void test_visitAdjacentStrings() { | 440 void test_visitAdjacentStrings() { |
440 AdjacentStrings createNode() => new AdjacentStrings([ | 441 AdjacentStrings createNode() => astFactory.adjacentStrings([ |
441 new SimpleStringLiteral(null, 'hello'), | 442 astFactory.simpleStringLiteral(null, 'hello'), |
442 new SimpleStringLiteral(null, 'world') | 443 astFactory.simpleStringLiteral(null, 'world') |
443 ]); | 444 ]); |
444 | 445 |
445 AdjacentStrings fromNode = createNode(); | 446 AdjacentStrings fromNode = createNode(); |
446 DartType propagatedType = ElementFactory.classElement2("A").type; | 447 DartType propagatedType = ElementFactory.classElement2("A").type; |
447 fromNode.propagatedType = propagatedType; | 448 fromNode.propagatedType = propagatedType; |
448 DartType staticType = ElementFactory.classElement2("B").type; | 449 DartType staticType = ElementFactory.classElement2("B").type; |
449 fromNode.staticType = staticType; | 450 fromNode.staticType = staticType; |
450 | 451 |
451 AdjacentStrings toNode = createNode(); | 452 AdjacentStrings toNode = createNode(); |
452 ResolutionCopier.copyResolutionData(fromNode, toNode); | 453 ResolutionCopier.copyResolutionData(fromNode, toNode); |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 AstTestFactory.withClause([AstTestFactory.typeName4("M1")]), | 1549 AstTestFactory.withClause([AstTestFactory.typeName4("M1")]), |
1549 null); | 1550 null); |
1550 declaration.metadata.add( | 1551 declaration.metadata.add( |
1551 AstTestFactory.annotation(AstTestFactory.identifier3("deprecated"))); | 1552 AstTestFactory.annotation(AstTestFactory.identifier3("deprecated"))); |
1552 _assertSource("@deprecated class C = S with M1;", declaration); | 1553 _assertSource("@deprecated class C = S with M1;", declaration); |
1553 } | 1554 } |
1554 | 1555 |
1555 void test_visitComment() { | 1556 void test_visitComment() { |
1556 _assertSource( | 1557 _assertSource( |
1557 "", | 1558 "", |
1558 Comment.createBlockComment( | 1559 astFactory.blockComment( |
1559 <Token>[TokenFactory.tokenFromString("/* comment */")])); | 1560 <Token>[TokenFactory.tokenFromString("/* comment */")])); |
1560 } | 1561 } |
1561 | 1562 |
1562 void test_visitCommentReference() { | 1563 void test_visitCommentReference() { |
1563 _assertSource( | 1564 _assertSource( |
1564 "", new CommentReference(null, AstTestFactory.identifier3("a"))); | 1565 "", astFactory.commentReference(null, AstTestFactory.identifier3("a"))); |
1565 } | 1566 } |
1566 | 1567 |
1567 void test_visitCompilationUnit_declaration() { | 1568 void test_visitCompilationUnit_declaration() { |
1568 _assertSource( | 1569 _assertSource( |
1569 "var a;", | 1570 "var a;", |
1570 AstTestFactory.compilationUnit2([ | 1571 AstTestFactory.compilationUnit2([ |
1571 AstTestFactory.topLevelVariableDeclaration2( | 1572 AstTestFactory.topLevelVariableDeclaration2( |
1572 Keyword.VAR, [AstTestFactory.variableDeclaration("a")]) | 1573 Keyword.VAR, [AstTestFactory.variableDeclaration("a")]) |
1573 ])); | 1574 ])); |
1574 } | 1575 } |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 null, | 1941 null, |
1941 AstTestFactory.typeName4("A"), | 1942 AstTestFactory.typeName4("A"), |
1942 "a", | 1943 "a", |
1943 AstTestFactory.formalParameterList( | 1944 AstTestFactory.formalParameterList( |
1944 [AstTestFactory.simpleFormalParameter3("b")]))); | 1945 [AstTestFactory.simpleFormalParameter3("b")]))); |
1945 } | 1946 } |
1946 | 1947 |
1947 void test_visitFieldFormalParameter_functionTyped_typeParameters() { | 1948 void test_visitFieldFormalParameter_functionTyped_typeParameters() { |
1948 _assertSource( | 1949 _assertSource( |
1949 "A this.a<E, F>(b)", | 1950 "A this.a<E, F>(b)", |
1950 new FieldFormalParameter( | 1951 astFactory.fieldFormalParameter( |
1951 null, | 1952 null, |
1952 null, | 1953 null, |
1953 null, | 1954 null, |
1954 AstTestFactory.typeName4('A'), | 1955 AstTestFactory.typeName4('A'), |
1955 TokenFactory.tokenFromKeyword(Keyword.THIS), | 1956 TokenFactory.tokenFromKeyword(Keyword.THIS), |
1956 TokenFactory.tokenFromType(TokenType.PERIOD), | 1957 TokenFactory.tokenFromType(TokenType.PERIOD), |
1957 AstTestFactory.identifier3('a'), | 1958 AstTestFactory.identifier3('a'), |
1958 AstTestFactory.typeParameterList(['E', 'F']), | 1959 AstTestFactory.typeParameterList(['E', 'F']), |
1959 AstTestFactory.formalParameterList( | 1960 AstTestFactory.formalParameterList( |
1960 [AstTestFactory.simpleFormalParameter3("b")]))); | 1961 [AstTestFactory.simpleFormalParameter3("b")]))); |
(...skipping 21 matching lines...) Expand all Loading... |
1982 void test_visitForEachStatement_declared() { | 1983 void test_visitForEachStatement_declared() { |
1983 _assertSource( | 1984 _assertSource( |
1984 "for (var a in b) {}", | 1985 "for (var a in b) {}", |
1985 AstTestFactory.forEachStatement(AstTestFactory.declaredIdentifier3("a"), | 1986 AstTestFactory.forEachStatement(AstTestFactory.declaredIdentifier3("a"), |
1986 AstTestFactory.identifier3("b"), AstTestFactory.block())); | 1987 AstTestFactory.identifier3("b"), AstTestFactory.block())); |
1987 } | 1988 } |
1988 | 1989 |
1989 void test_visitForEachStatement_variable() { | 1990 void test_visitForEachStatement_variable() { |
1990 _assertSource( | 1991 _assertSource( |
1991 "for (a in b) {}", | 1992 "for (a in b) {}", |
1992 new ForEachStatement.withReference( | 1993 astFactory.forEachStatementWithReference( |
1993 null, | 1994 null, |
1994 TokenFactory.tokenFromKeyword(Keyword.FOR), | 1995 TokenFactory.tokenFromKeyword(Keyword.FOR), |
1995 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | 1996 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), |
1996 AstTestFactory.identifier3("a"), | 1997 AstTestFactory.identifier3("a"), |
1997 TokenFactory.tokenFromKeyword(Keyword.IN), | 1998 TokenFactory.tokenFromKeyword(Keyword.IN), |
1998 AstTestFactory.identifier3("b"), | 1999 AstTestFactory.identifier3("b"), |
1999 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | 2000 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), |
2000 AstTestFactory.block())); | 2001 AstTestFactory.block())); |
2001 } | 2002 } |
2002 | 2003 |
2003 void test_visitForEachStatement_variable_await() { | 2004 void test_visitForEachStatement_variable_await() { |
2004 _assertSource( | 2005 _assertSource( |
2005 "await for (a in b) {}", | 2006 "await for (a in b) {}", |
2006 new ForEachStatement.withReference( | 2007 astFactory.forEachStatementWithReference( |
2007 TokenFactory.tokenFromString("await"), | 2008 TokenFactory.tokenFromString("await"), |
2008 TokenFactory.tokenFromKeyword(Keyword.FOR), | 2009 TokenFactory.tokenFromKeyword(Keyword.FOR), |
2009 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | 2010 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), |
2010 AstTestFactory.identifier3("a"), | 2011 AstTestFactory.identifier3("a"), |
2011 TokenFactory.tokenFromKeyword(Keyword.IN), | 2012 TokenFactory.tokenFromKeyword(Keyword.IN), |
2012 AstTestFactory.identifier3("b"), | 2013 AstTestFactory.identifier3("b"), |
2013 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | 2014 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), |
2014 AstTestFactory.block())); | 2015 AstTestFactory.block())); |
2015 } | 2016 } |
2016 | 2017 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2298 _assertSource( | 2299 _assertSource( |
2299 "get f() {}", | 2300 "get f() {}", |
2300 AstTestFactory.functionDeclaration( | 2301 AstTestFactory.functionDeclaration( |
2301 null, Keyword.GET, "f", AstTestFactory.functionExpression())); | 2302 null, Keyword.GET, "f", AstTestFactory.functionExpression())); |
2302 } | 2303 } |
2303 | 2304 |
2304 void test_visitFunctionDeclaration_local_blockBody() { | 2305 void test_visitFunctionDeclaration_local_blockBody() { |
2305 FunctionDeclaration f = AstTestFactory.functionDeclaration( | 2306 FunctionDeclaration f = AstTestFactory.functionDeclaration( |
2306 null, null, "f", AstTestFactory.functionExpression()); | 2307 null, null, "f", AstTestFactory.functionExpression()); |
2307 FunctionDeclarationStatement fStatement = | 2308 FunctionDeclarationStatement fStatement = |
2308 new FunctionDeclarationStatement(f); | 2309 astFactory.functionDeclarationStatement(f); |
2309 _assertSource( | 2310 _assertSource( |
2310 "main() {f() {} 42;}", | 2311 "main() {f() {} 42;}", |
2311 AstTestFactory.functionDeclaration( | 2312 AstTestFactory.functionDeclaration( |
2312 null, | 2313 null, |
2313 null, | 2314 null, |
2314 "main", | 2315 "main", |
2315 AstTestFactory.functionExpression2( | 2316 AstTestFactory.functionExpression2( |
2316 AstTestFactory.formalParameterList(), | 2317 AstTestFactory.formalParameterList(), |
2317 AstTestFactory.blockFunctionBody2([ | 2318 AstTestFactory.blockFunctionBody2([ |
2318 fStatement, | 2319 fStatement, |
2319 AstTestFactory.expressionStatement(AstTestFactory.integer(42)) | 2320 AstTestFactory.expressionStatement(AstTestFactory.integer(42)) |
2320 ])))); | 2321 ])))); |
2321 } | 2322 } |
2322 | 2323 |
2323 void test_visitFunctionDeclaration_local_expressionBody() { | 2324 void test_visitFunctionDeclaration_local_expressionBody() { |
2324 FunctionDeclaration f = AstTestFactory.functionDeclaration( | 2325 FunctionDeclaration f = AstTestFactory.functionDeclaration( |
2325 null, | 2326 null, |
2326 null, | 2327 null, |
2327 "f", | 2328 "f", |
2328 AstTestFactory.functionExpression2(AstTestFactory.formalParameterList(), | 2329 AstTestFactory.functionExpression2(AstTestFactory.formalParameterList(), |
2329 AstTestFactory.expressionFunctionBody(AstTestFactory.integer(1)))); | 2330 AstTestFactory.expressionFunctionBody(AstTestFactory.integer(1)))); |
2330 FunctionDeclarationStatement fStatement = | 2331 FunctionDeclarationStatement fStatement = |
2331 new FunctionDeclarationStatement(f); | 2332 astFactory.functionDeclarationStatement(f); |
2332 _assertSource( | 2333 _assertSource( |
2333 "main() {f() => 1; 2;}", | 2334 "main() {f() => 1; 2;}", |
2334 AstTestFactory.functionDeclaration( | 2335 AstTestFactory.functionDeclaration( |
2335 null, | 2336 null, |
2336 null, | 2337 null, |
2337 "main", | 2338 "main", |
2338 AstTestFactory.functionExpression2( | 2339 AstTestFactory.functionExpression2( |
2339 AstTestFactory.formalParameterList(), | 2340 AstTestFactory.formalParameterList(), |
2340 AstTestFactory.blockFunctionBody2([ | 2341 AstTestFactory.blockFunctionBody2([ |
2341 fStatement, | 2342 fStatement, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2457 void test_visitFunctionTypedFormalParameter_type() { | 2458 void test_visitFunctionTypedFormalParameter_type() { |
2458 _assertSource( | 2459 _assertSource( |
2459 "T f()", | 2460 "T f()", |
2460 AstTestFactory.functionTypedFormalParameter( | 2461 AstTestFactory.functionTypedFormalParameter( |
2461 AstTestFactory.typeName4("T"), "f")); | 2462 AstTestFactory.typeName4("T"), "f")); |
2462 } | 2463 } |
2463 | 2464 |
2464 void test_visitFunctionTypedFormalParameter_typeParameters() { | 2465 void test_visitFunctionTypedFormalParameter_typeParameters() { |
2465 _assertSource( | 2466 _assertSource( |
2466 "T f<E>()", | 2467 "T f<E>()", |
2467 new FunctionTypedFormalParameter( | 2468 astFactory.functionTypedFormalParameter( |
2468 null, | 2469 null, |
2469 null, | 2470 null, |
2470 AstTestFactory.typeName4("T"), | 2471 AstTestFactory.typeName4("T"), |
2471 AstTestFactory.identifier3('f'), | 2472 AstTestFactory.identifier3('f'), |
2472 AstTestFactory.typeParameterList(['E']), | 2473 AstTestFactory.typeParameterList(['E']), |
2473 AstTestFactory.formalParameterList([]))); | 2474 AstTestFactory.formalParameterList([]))); |
2474 } | 2475 } |
2475 | 2476 |
2476 void test_visitIfStatement_withElse() { | 2477 void test_visitIfStatement_withElse() { |
2477 _assertSource( | 2478 _assertSource( |
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3878 AstTestFactory.withClause([AstTestFactory.typeName4("M1")]), | 3879 AstTestFactory.withClause([AstTestFactory.typeName4("M1")]), |
3879 null); | 3880 null); |
3880 declaration.metadata.add( | 3881 declaration.metadata.add( |
3881 AstTestFactory.annotation(AstTestFactory.identifier3("deprecated"))); | 3882 AstTestFactory.annotation(AstTestFactory.identifier3("deprecated"))); |
3882 _assertSource("@deprecated class C = S with M1;", declaration); | 3883 _assertSource("@deprecated class C = S with M1;", declaration); |
3883 } | 3884 } |
3884 | 3885 |
3885 void test_visitComment() { | 3886 void test_visitComment() { |
3886 _assertSource( | 3887 _assertSource( |
3887 "", | 3888 "", |
3888 Comment.createBlockComment( | 3889 astFactory.blockComment( |
3889 <Token>[TokenFactory.tokenFromString("/* comment */")])); | 3890 <Token>[TokenFactory.tokenFromString("/* comment */")])); |
3890 } | 3891 } |
3891 | 3892 |
3892 void test_visitCommentReference() { | 3893 void test_visitCommentReference() { |
3893 _assertSource( | 3894 _assertSource( |
3894 "", new CommentReference(null, AstTestFactory.identifier3("a"))); | 3895 "", astFactory.commentReference(null, AstTestFactory.identifier3("a"))); |
3895 } | 3896 } |
3896 | 3897 |
3897 void test_visitCompilationUnit_declaration() { | 3898 void test_visitCompilationUnit_declaration() { |
3898 _assertSource( | 3899 _assertSource( |
3899 "var a;", | 3900 "var a;", |
3900 AstTestFactory.compilationUnit2([ | 3901 AstTestFactory.compilationUnit2([ |
3901 AstTestFactory.topLevelVariableDeclaration2( | 3902 AstTestFactory.topLevelVariableDeclaration2( |
3902 Keyword.VAR, [AstTestFactory.variableDeclaration("a")]) | 3903 Keyword.VAR, [AstTestFactory.variableDeclaration("a")]) |
3903 ])); | 3904 ])); |
3904 } | 3905 } |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4270 null, | 4271 null, |
4271 AstTestFactory.typeName4("A"), | 4272 AstTestFactory.typeName4("A"), |
4272 "a", | 4273 "a", |
4273 AstTestFactory.formalParameterList( | 4274 AstTestFactory.formalParameterList( |
4274 [AstTestFactory.simpleFormalParameter3("b")]))); | 4275 [AstTestFactory.simpleFormalParameter3("b")]))); |
4275 } | 4276 } |
4276 | 4277 |
4277 void test_visitFieldFormalParameter_functionTyped_typeParameters() { | 4278 void test_visitFieldFormalParameter_functionTyped_typeParameters() { |
4278 _assertSource( | 4279 _assertSource( |
4279 "A this.a<E, F>(b)", | 4280 "A this.a<E, F>(b)", |
4280 new FieldFormalParameter( | 4281 astFactory.fieldFormalParameter( |
4281 null, | 4282 null, |
4282 null, | 4283 null, |
4283 null, | 4284 null, |
4284 AstTestFactory.typeName4('A'), | 4285 AstTestFactory.typeName4('A'), |
4285 TokenFactory.tokenFromKeyword(Keyword.THIS), | 4286 TokenFactory.tokenFromKeyword(Keyword.THIS), |
4286 TokenFactory.tokenFromType(TokenType.PERIOD), | 4287 TokenFactory.tokenFromType(TokenType.PERIOD), |
4287 AstTestFactory.identifier3('a'), | 4288 AstTestFactory.identifier3('a'), |
4288 AstTestFactory.typeParameterList(['E', 'F']), | 4289 AstTestFactory.typeParameterList(['E', 'F']), |
4289 AstTestFactory.formalParameterList( | 4290 AstTestFactory.formalParameterList( |
4290 [AstTestFactory.simpleFormalParameter3("b")]))); | 4291 [AstTestFactory.simpleFormalParameter3("b")]))); |
(...skipping 21 matching lines...) Expand all Loading... |
4312 void test_visitForEachStatement_declared() { | 4313 void test_visitForEachStatement_declared() { |
4313 _assertSource( | 4314 _assertSource( |
4314 "for (var a in b) {}", | 4315 "for (var a in b) {}", |
4315 AstTestFactory.forEachStatement(AstTestFactory.declaredIdentifier3("a"), | 4316 AstTestFactory.forEachStatement(AstTestFactory.declaredIdentifier3("a"), |
4316 AstTestFactory.identifier3("b"), AstTestFactory.block())); | 4317 AstTestFactory.identifier3("b"), AstTestFactory.block())); |
4317 } | 4318 } |
4318 | 4319 |
4319 void test_visitForEachStatement_variable() { | 4320 void test_visitForEachStatement_variable() { |
4320 _assertSource( | 4321 _assertSource( |
4321 "for (a in b) {}", | 4322 "for (a in b) {}", |
4322 new ForEachStatement.withReference( | 4323 astFactory.forEachStatementWithReference( |
4323 null, | 4324 null, |
4324 TokenFactory.tokenFromKeyword(Keyword.FOR), | 4325 TokenFactory.tokenFromKeyword(Keyword.FOR), |
4325 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | 4326 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), |
4326 AstTestFactory.identifier3("a"), | 4327 AstTestFactory.identifier3("a"), |
4327 TokenFactory.tokenFromKeyword(Keyword.IN), | 4328 TokenFactory.tokenFromKeyword(Keyword.IN), |
4328 AstTestFactory.identifier3("b"), | 4329 AstTestFactory.identifier3("b"), |
4329 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | 4330 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), |
4330 AstTestFactory.block())); | 4331 AstTestFactory.block())); |
4331 } | 4332 } |
4332 | 4333 |
4333 void test_visitForEachStatement_variable_await() { | 4334 void test_visitForEachStatement_variable_await() { |
4334 _assertSource( | 4335 _assertSource( |
4335 "await for (a in b) {}", | 4336 "await for (a in b) {}", |
4336 new ForEachStatement.withReference( | 4337 astFactory.forEachStatementWithReference( |
4337 TokenFactory.tokenFromString("await"), | 4338 TokenFactory.tokenFromString("await"), |
4338 TokenFactory.tokenFromKeyword(Keyword.FOR), | 4339 TokenFactory.tokenFromKeyword(Keyword.FOR), |
4339 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | 4340 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), |
4340 AstTestFactory.identifier3("a"), | 4341 AstTestFactory.identifier3("a"), |
4341 TokenFactory.tokenFromKeyword(Keyword.IN), | 4342 TokenFactory.tokenFromKeyword(Keyword.IN), |
4342 AstTestFactory.identifier3("b"), | 4343 AstTestFactory.identifier3("b"), |
4343 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | 4344 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), |
4344 AstTestFactory.block())); | 4345 AstTestFactory.block())); |
4345 } | 4346 } |
4346 | 4347 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4628 _assertSource( | 4629 _assertSource( |
4629 "get f() {}", | 4630 "get f() {}", |
4630 AstTestFactory.functionDeclaration( | 4631 AstTestFactory.functionDeclaration( |
4631 null, Keyword.GET, "f", AstTestFactory.functionExpression())); | 4632 null, Keyword.GET, "f", AstTestFactory.functionExpression())); |
4632 } | 4633 } |
4633 | 4634 |
4634 void test_visitFunctionDeclaration_local_blockBody() { | 4635 void test_visitFunctionDeclaration_local_blockBody() { |
4635 FunctionDeclaration f = AstTestFactory.functionDeclaration( | 4636 FunctionDeclaration f = AstTestFactory.functionDeclaration( |
4636 null, null, "f", AstTestFactory.functionExpression()); | 4637 null, null, "f", AstTestFactory.functionExpression()); |
4637 FunctionDeclarationStatement fStatement = | 4638 FunctionDeclarationStatement fStatement = |
4638 new FunctionDeclarationStatement(f); | 4639 astFactory.functionDeclarationStatement(f); |
4639 _assertSource( | 4640 _assertSource( |
4640 "main() {f() {} 42;}", | 4641 "main() {f() {} 42;}", |
4641 AstTestFactory.functionDeclaration( | 4642 AstTestFactory.functionDeclaration( |
4642 null, | 4643 null, |
4643 null, | 4644 null, |
4644 "main", | 4645 "main", |
4645 AstTestFactory.functionExpression2( | 4646 AstTestFactory.functionExpression2( |
4646 AstTestFactory.formalParameterList(), | 4647 AstTestFactory.formalParameterList(), |
4647 AstTestFactory.blockFunctionBody2([ | 4648 AstTestFactory.blockFunctionBody2([ |
4648 fStatement, | 4649 fStatement, |
4649 AstTestFactory.expressionStatement(AstTestFactory.integer(42)) | 4650 AstTestFactory.expressionStatement(AstTestFactory.integer(42)) |
4650 ])))); | 4651 ])))); |
4651 } | 4652 } |
4652 | 4653 |
4653 void test_visitFunctionDeclaration_local_expressionBody() { | 4654 void test_visitFunctionDeclaration_local_expressionBody() { |
4654 FunctionDeclaration f = AstTestFactory.functionDeclaration( | 4655 FunctionDeclaration f = AstTestFactory.functionDeclaration( |
4655 null, | 4656 null, |
4656 null, | 4657 null, |
4657 "f", | 4658 "f", |
4658 AstTestFactory.functionExpression2(AstTestFactory.formalParameterList(), | 4659 AstTestFactory.functionExpression2(AstTestFactory.formalParameterList(), |
4659 AstTestFactory.expressionFunctionBody(AstTestFactory.integer(1)))); | 4660 AstTestFactory.expressionFunctionBody(AstTestFactory.integer(1)))); |
4660 FunctionDeclarationStatement fStatement = | 4661 FunctionDeclarationStatement fStatement = |
4661 new FunctionDeclarationStatement(f); | 4662 astFactory.functionDeclarationStatement(f); |
4662 _assertSource( | 4663 _assertSource( |
4663 "main() {f() => 1; 2;}", | 4664 "main() {f() => 1; 2;}", |
4664 AstTestFactory.functionDeclaration( | 4665 AstTestFactory.functionDeclaration( |
4665 null, | 4666 null, |
4666 null, | 4667 null, |
4667 "main", | 4668 "main", |
4668 AstTestFactory.functionExpression2( | 4669 AstTestFactory.functionExpression2( |
4669 AstTestFactory.formalParameterList(), | 4670 AstTestFactory.formalParameterList(), |
4670 AstTestFactory.blockFunctionBody2([ | 4671 AstTestFactory.blockFunctionBody2([ |
4671 fStatement, | 4672 fStatement, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4787 void test_visitFunctionTypedFormalParameter_type() { | 4788 void test_visitFunctionTypedFormalParameter_type() { |
4788 _assertSource( | 4789 _assertSource( |
4789 "T f()", | 4790 "T f()", |
4790 AstTestFactory.functionTypedFormalParameter( | 4791 AstTestFactory.functionTypedFormalParameter( |
4791 AstTestFactory.typeName4("T"), "f")); | 4792 AstTestFactory.typeName4("T"), "f")); |
4792 } | 4793 } |
4793 | 4794 |
4794 void test_visitFunctionTypedFormalParameter_typeParameters() { | 4795 void test_visitFunctionTypedFormalParameter_typeParameters() { |
4795 _assertSource( | 4796 _assertSource( |
4796 "T f<E>()", | 4797 "T f<E>()", |
4797 new FunctionTypedFormalParameter( | 4798 astFactory.functionTypedFormalParameter( |
4798 null, | 4799 null, |
4799 null, | 4800 null, |
4800 AstTestFactory.typeName4("T"), | 4801 AstTestFactory.typeName4("T"), |
4801 AstTestFactory.identifier3('f'), | 4802 AstTestFactory.identifier3('f'), |
4802 AstTestFactory.typeParameterList(['E']), | 4803 AstTestFactory.typeParameterList(['E']), |
4803 AstTestFactory.formalParameterList([]))); | 4804 AstTestFactory.formalParameterList([]))); |
4804 } | 4805 } |
4805 | 4806 |
4806 void test_visitIfStatement_withElse() { | 4807 void test_visitIfStatement_withElse() { |
4807 _assertSource( | 4808 _assertSource( |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5767 /** | 5768 /** |
5768 * Assert that a `ToSourceVisitor` will produce the [expectedSource] when | 5769 * Assert that a `ToSourceVisitor` will produce the [expectedSource] when |
5769 * visiting the given [node]. | 5770 * visiting the given [node]. |
5770 */ | 5771 */ |
5771 void _assertSource(String expectedSource, AstNode node) { | 5772 void _assertSource(String expectedSource, AstNode node) { |
5772 PrintStringWriter writer = new PrintStringWriter(); | 5773 PrintStringWriter writer = new PrintStringWriter(); |
5773 node.accept(new ToSourceVisitor(writer)); | 5774 node.accept(new ToSourceVisitor(writer)); |
5774 expect(writer.toString(), expectedSource); | 5775 expect(writer.toString(), expectedSource); |
5775 } | 5776 } |
5776 } | 5777 } |
OLD | NEW |