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/standard_ast_factory.dart'; |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 1954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 null, | 1965 null, |
1966 AstTestFactory.typeName4("A"), | 1966 AstTestFactory.typeName4("A"), |
1967 "a", | 1967 "a", |
1968 AstTestFactory.formalParameterList( | 1968 AstTestFactory.formalParameterList( |
1969 [AstTestFactory.simpleFormalParameter3("b")]))); | 1969 [AstTestFactory.simpleFormalParameter3("b")]))); |
1970 } | 1970 } |
1971 | 1971 |
1972 void test_visitFieldFormalParameter_functionTyped_typeParameters() { | 1972 void test_visitFieldFormalParameter_functionTyped_typeParameters() { |
1973 _assertSource( | 1973 _assertSource( |
1974 "A this.a<E, F>(b)", | 1974 "A this.a<E, F>(b)", |
1975 astFactory.fieldFormalParameter( | 1975 astFactory.fieldFormalParameter2( |
1976 null, | 1976 type: AstTestFactory.typeName4('A'), |
1977 null, | 1977 thisKeyword: TokenFactory.tokenFromKeyword(Keyword.THIS), |
1978 null, | 1978 period: TokenFactory.tokenFromType(TokenType.PERIOD), |
1979 AstTestFactory.typeName4('A'), | 1979 identifier: AstTestFactory.identifier3('a'), |
1980 TokenFactory.tokenFromKeyword(Keyword.THIS), | 1980 typeParameters: AstTestFactory.typeParameterList(['E', 'F']), |
1981 TokenFactory.tokenFromType(TokenType.PERIOD), | 1981 parameters: AstTestFactory.formalParameterList( |
1982 AstTestFactory.identifier3('a'), | |
1983 AstTestFactory.typeParameterList(['E', 'F']), | |
1984 AstTestFactory.formalParameterList( | |
1985 [AstTestFactory.simpleFormalParameter3("b")]))); | 1982 [AstTestFactory.simpleFormalParameter3("b")]))); |
1986 } | 1983 } |
1987 | 1984 |
1988 void test_visitFieldFormalParameter_keyword() { | 1985 void test_visitFieldFormalParameter_keyword() { |
1989 _assertSource("var this.a", | 1986 _assertSource("var this.a", |
1990 AstTestFactory.fieldFormalParameter(Keyword.VAR, null, "a")); | 1987 AstTestFactory.fieldFormalParameter(Keyword.VAR, null, "a")); |
1991 } | 1988 } |
1992 | 1989 |
1993 void test_visitFieldFormalParameter_keywordAndType() { | 1990 void test_visitFieldFormalParameter_keywordAndType() { |
1994 _assertSource( | 1991 _assertSource( |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2498 FunctionTypedFormalParameterImpl expected = AstTestFactory | 2495 FunctionTypedFormalParameterImpl expected = AstTestFactory |
2499 .functionTypedFormalParameter(AstTestFactory.typeName4("T"), "f"); | 2496 .functionTypedFormalParameter(AstTestFactory.typeName4("T"), "f"); |
2500 expected.covariantKeyword = | 2497 expected.covariantKeyword = |
2501 TokenFactory.tokenFromKeyword(Keyword.COVARIANT); | 2498 TokenFactory.tokenFromKeyword(Keyword.COVARIANT); |
2502 _assertSource("covariant T f()", expected); | 2499 _assertSource("covariant T f()", expected); |
2503 } | 2500 } |
2504 | 2501 |
2505 void test_visitFunctionTypedFormalParameter_typeParameters() { | 2502 void test_visitFunctionTypedFormalParameter_typeParameters() { |
2506 _assertSource( | 2503 _assertSource( |
2507 "T f<E>()", | 2504 "T f<E>()", |
2508 astFactory.functionTypedFormalParameter( | 2505 astFactory.functionTypedFormalParameter2( |
2509 null, | 2506 returnType: AstTestFactory.typeName4("T"), |
2510 null, | 2507 identifier: AstTestFactory.identifier3('f'), |
2511 AstTestFactory.typeName4("T"), | 2508 typeParameters: AstTestFactory.typeParameterList(['E']), |
2512 AstTestFactory.identifier3('f'), | 2509 parameters: AstTestFactory.formalParameterList([]))); |
2513 AstTestFactory.typeParameterList(['E']), | |
2514 AstTestFactory.formalParameterList([]))); | |
2515 } | 2510 } |
2516 | 2511 |
2517 void test_visitIfStatement_withElse() { | 2512 void test_visitIfStatement_withElse() { |
2518 _assertSource( | 2513 _assertSource( |
2519 "if (c) {} else {}", | 2514 "if (c) {} else {}", |
2520 AstTestFactory.ifStatement2(AstTestFactory.identifier3("c"), | 2515 AstTestFactory.ifStatement2(AstTestFactory.identifier3("c"), |
2521 AstTestFactory.block(), AstTestFactory.block())); | 2516 AstTestFactory.block(), AstTestFactory.block())); |
2522 } | 2517 } |
2523 | 2518 |
2524 void test_visitIfStatement_withoutElse() { | 2519 void test_visitIfStatement_withoutElse() { |
(...skipping 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4319 null, | 4314 null, |
4320 AstTestFactory.typeName4("A"), | 4315 AstTestFactory.typeName4("A"), |
4321 "a", | 4316 "a", |
4322 AstTestFactory.formalParameterList( | 4317 AstTestFactory.formalParameterList( |
4323 [AstTestFactory.simpleFormalParameter3("b")]))); | 4318 [AstTestFactory.simpleFormalParameter3("b")]))); |
4324 } | 4319 } |
4325 | 4320 |
4326 void test_visitFieldFormalParameter_functionTyped_typeParameters() { | 4321 void test_visitFieldFormalParameter_functionTyped_typeParameters() { |
4327 _assertSource( | 4322 _assertSource( |
4328 "A this.a<E, F>(b)", | 4323 "A this.a<E, F>(b)", |
4329 astFactory.fieldFormalParameter( | 4324 astFactory.fieldFormalParameter2( |
4330 null, | 4325 type: AstTestFactory.typeName4('A'), |
4331 null, | 4326 thisKeyword: TokenFactory.tokenFromKeyword(Keyword.THIS), |
4332 null, | 4327 period: TokenFactory.tokenFromType(TokenType.PERIOD), |
4333 AstTestFactory.typeName4('A'), | 4328 identifier: AstTestFactory.identifier3('a'), |
4334 TokenFactory.tokenFromKeyword(Keyword.THIS), | 4329 typeParameters: AstTestFactory.typeParameterList(['E', 'F']), |
4335 TokenFactory.tokenFromType(TokenType.PERIOD), | 4330 parameters: AstTestFactory.formalParameterList( |
4336 AstTestFactory.identifier3('a'), | |
4337 AstTestFactory.typeParameterList(['E', 'F']), | |
4338 AstTestFactory.formalParameterList( | |
4339 [AstTestFactory.simpleFormalParameter3("b")]))); | 4331 [AstTestFactory.simpleFormalParameter3("b")]))); |
4340 } | 4332 } |
4341 | 4333 |
4342 void test_visitFieldFormalParameter_keyword() { | 4334 void test_visitFieldFormalParameter_keyword() { |
4343 _assertSource("var this.a", | 4335 _assertSource("var this.a", |
4344 AstTestFactory.fieldFormalParameter(Keyword.VAR, null, "a")); | 4336 AstTestFactory.fieldFormalParameter(Keyword.VAR, null, "a")); |
4345 } | 4337 } |
4346 | 4338 |
4347 void test_visitFieldFormalParameter_keywordAndType() { | 4339 void test_visitFieldFormalParameter_keywordAndType() { |
4348 _assertSource( | 4340 _assertSource( |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4852 FunctionTypedFormalParameterImpl expected = AstTestFactory | 4844 FunctionTypedFormalParameterImpl expected = AstTestFactory |
4853 .functionTypedFormalParameter(AstTestFactory.typeName4("T"), "f"); | 4845 .functionTypedFormalParameter(AstTestFactory.typeName4("T"), "f"); |
4854 expected.covariantKeyword = | 4846 expected.covariantKeyword = |
4855 TokenFactory.tokenFromKeyword(Keyword.COVARIANT); | 4847 TokenFactory.tokenFromKeyword(Keyword.COVARIANT); |
4856 _assertSource("covariant T f()", expected); | 4848 _assertSource("covariant T f()", expected); |
4857 } | 4849 } |
4858 | 4850 |
4859 void test_visitFunctionTypedFormalParameter_typeParameters() { | 4851 void test_visitFunctionTypedFormalParameter_typeParameters() { |
4860 _assertSource( | 4852 _assertSource( |
4861 "T f<E>()", | 4853 "T f<E>()", |
4862 astFactory.functionTypedFormalParameter( | 4854 astFactory.functionTypedFormalParameter2( |
4863 null, | 4855 returnType: AstTestFactory.typeName4("T"), |
4864 null, | 4856 identifier: AstTestFactory.identifier3('f'), |
4865 AstTestFactory.typeName4("T"), | 4857 typeParameters: AstTestFactory.typeParameterList(['E']), |
4866 AstTestFactory.identifier3('f'), | 4858 parameters: AstTestFactory.formalParameterList([]))); |
4867 AstTestFactory.typeParameterList(['E']), | |
4868 AstTestFactory.formalParameterList([]))); | |
4869 } | 4859 } |
4870 | 4860 |
4871 void test_visitIfStatement_withElse() { | 4861 void test_visitIfStatement_withElse() { |
4872 _assertSource( | 4862 _assertSource( |
4873 "if (c) {} else {}", | 4863 "if (c) {} else {}", |
4874 AstTestFactory.ifStatement2(AstTestFactory.identifier3("c"), | 4864 AstTestFactory.ifStatement2(AstTestFactory.identifier3("c"), |
4875 AstTestFactory.block(), AstTestFactory.block())); | 4865 AstTestFactory.block(), AstTestFactory.block())); |
4876 } | 4866 } |
4877 | 4867 |
4878 void test_visitIfStatement_withoutElse() { | 4868 void test_visitIfStatement_withoutElse() { |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5840 /** | 5830 /** |
5841 * Assert that a `ToSourceVisitor` will produce the [expectedSource] when | 5831 * Assert that a `ToSourceVisitor` will produce the [expectedSource] when |
5842 * visiting the given [node]. | 5832 * visiting the given [node]. |
5843 */ | 5833 */ |
5844 void _assertSource(String expectedSource, AstNode node) { | 5834 void _assertSource(String expectedSource, AstNode node) { |
5845 PrintStringWriter writer = new PrintStringWriter(); | 5835 PrintStringWriter writer = new PrintStringWriter(); |
5846 node.accept(new ToSourceVisitor(writer)); | 5836 node.accept(new ToSourceVisitor(writer)); |
5847 expect(writer.toString(), expectedSource); | 5837 expect(writer.toString(), expectedSource); |
5848 } | 5838 } |
5849 } | 5839 } |
OLD | NEW |