| 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.utilities_test; | 5 library analyzer.test.generated.utilities_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/src/dart/ast/utilities.dart'; | 10 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 11 import 'package:analyzer/src/generated/java_core.dart'; | 11 import 'package:analyzer/src/generated/java_core.dart'; |
| 12 import 'package:analyzer/src/generated/java_engine.dart'; | 12 import 'package:analyzer/src/generated/java_engine.dart'; |
| 13 import 'package:analyzer/src/generated/parser.dart'; |
| 13 import 'package:analyzer/src/generated/scanner.dart'; | 14 import 'package:analyzer/src/generated/scanner.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 16 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 16 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 17 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
| 17 import 'package:analyzer/src/generated/utilities_collection.dart'; | 18 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 18 import 'package:unittest/unittest.dart'; | 19 import 'package:unittest/unittest.dart'; |
| 19 | 20 |
| 20 import '../reflective_tests.dart'; | 21 import '../reflective_tests.dart'; |
| 21 import '../utils.dart'; | 22 import '../utils.dart'; |
| 22 import 'test_support.dart'; | 23 import 'test_support.dart'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 fail('Failed to copy token: ${first.lexeme} (${first.offset})'); | 57 fail('Failed to copy token: ${first.lexeme} (${first.offset})'); |
| 57 return false; | 58 return false; |
| 58 } | 59 } |
| 59 return super.isEqualTokens(first, second); | 60 return super.isEqualTokens(first, second); |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 @reflectiveTest | 64 @reflectiveTest |
| 64 class AstClonerTest extends EngineTestCase { | 65 class AstClonerTest extends EngineTestCase { |
| 65 void test_visitAdjacentStrings() { | 66 void test_visitAdjacentStrings() { |
| 66 _assertClone(AstFactory | 67 _assertCloneExpression("'a' 'b'"); |
| 67 .adjacentStrings([AstFactory.string2("a"), AstFactory.string2("b")])); | |
| 68 } | 68 } |
| 69 | 69 |
| 70 void test_visitAnnotation_constant() { | 70 void test_visitAnnotation_constant() { |
| 71 _assertClone(AstFactory.annotation(AstFactory.identifier3("A"))); | 71 _assertCloneUnitMember('@A main() {}'); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void test_visitAnnotation_constructor() { | 74 void test_visitAnnotation_constructor() { |
| 75 _assertClone(AstFactory.annotation2(AstFactory.identifier3("A"), | 75 _assertCloneUnitMember('@A.c() main() {}'); |
| 76 AstFactory.identifier3("c"), AstFactory.argumentList())); | |
| 77 } | 76 } |
| 78 | 77 |
| 79 void test_visitArgumentList() { | 78 void test_visitArgumentList() { |
| 80 _assertClone(AstFactory.argumentList( | 79 _assertCloneExpression('m(a, b)'); |
| 81 [AstFactory.identifier3("a"), AstFactory.identifier3("b")])); | |
| 82 } | 80 } |
| 83 | 81 |
| 84 void test_visitAsExpression() { | 82 void test_visitAsExpression() { |
| 85 _assertClone(AstFactory.asExpression( | 83 _assertCloneExpression('e as T'); |
| 86 AstFactory.identifier3("e"), AstFactory.typeName4("T"))); | |
| 87 } | 84 } |
| 88 | 85 |
| 89 void test_visitAssertStatement() { | 86 void test_visitAssertStatement() { |
| 90 _assertClone(AstFactory.assertStatement(AstFactory.identifier3("a"))); | 87 _assertCloneStatement('assert(a);'); |
| 91 } | 88 } |
| 92 | 89 |
| 93 void test_visitAssignmentExpression() { | 90 void test_visitAssignmentExpression() { |
| 94 _assertClone(AstFactory.assignmentExpression(AstFactory.identifier3("a"), | 91 _assertCloneStatement('a = b;'); |
| 95 TokenType.EQ, AstFactory.identifier3("b"))); | |
| 96 } | 92 } |
| 97 | 93 |
| 98 void test_visitAwaitExpression() { | 94 void test_visitAwaitExpression() { |
| 99 _assertClone(AstFactory.awaitExpression(AstFactory.identifier3("a"))); | 95 _assertCloneStatement('await a;'); |
| 100 } | 96 } |
| 101 | 97 |
| 102 void test_visitBinaryExpression() { | 98 void test_visitBinaryExpression() { |
| 103 _assertClone(AstFactory.binaryExpression(AstFactory.identifier3("a"), | 99 _assertCloneExpression('a + b'); |
| 104 TokenType.PLUS, AstFactory.identifier3("b"))); | |
| 105 } | 100 } |
| 106 | 101 |
| 107 void test_visitBlock_empty() { | 102 void test_visitBlock_empty() { |
| 108 _assertClone(AstFactory.block()); | 103 _assertCloneStatement('{}'); |
| 109 } | 104 } |
| 110 | 105 |
| 111 void test_visitBlock_nonEmpty() { | 106 void test_visitBlock_nonEmpty() { |
| 112 _assertClone(AstFactory | 107 _assertCloneStatement('{ print(1); print(2); }'); |
| 113 .block([AstFactory.breakStatement(), AstFactory.breakStatement()])); | |
| 114 } | 108 } |
| 115 | 109 |
| 116 void test_visitBlockFunctionBody() { | 110 void test_visitBlockFunctionBody() { |
| 117 _assertClone(AstFactory.blockFunctionBody2()); | 111 _assertCloneUnitMember('main() {}'); |
| 118 } | 112 } |
| 119 | 113 |
| 120 void test_visitBooleanLiteral_false() { | 114 void test_visitBooleanLiteral_false() { |
| 121 _assertClone(AstFactory.booleanLiteral(false)); | 115 _assertCloneExpression('false'); |
| 122 } | 116 } |
| 123 | 117 |
| 124 void test_visitBooleanLiteral_true() { | 118 void test_visitBooleanLiteral_true() { |
| 125 _assertClone(AstFactory.booleanLiteral(true)); | 119 _assertCloneExpression('true'); |
| 126 } | 120 } |
| 127 | 121 |
| 128 void test_visitBreakStatement_label() { | 122 void test_visitBreakStatement_label() { |
| 129 _assertClone(AstFactory.breakStatement2("l")); | 123 _assertCloneStatement('l: while(true) { break l; }'); |
| 130 } | 124 } |
| 131 | 125 |
| 132 void test_visitBreakStatement_noLabel() { | 126 void test_visitBreakStatement_noLabel() { |
| 133 _assertClone(AstFactory.breakStatement()); | 127 _assertCloneStatement('while(true) { break; }'); |
| 134 } | 128 } |
| 135 | 129 |
| 136 void test_visitCascadeExpression_field() { | 130 void test_visitCascadeExpression_field() { |
| 137 _assertClone(AstFactory.cascadeExpression(AstFactory.identifier3("a"), [ | 131 _assertCloneExpression('a..b..c'); |
| 138 AstFactory.cascadedPropertyAccess("b"), | |
| 139 AstFactory.cascadedPropertyAccess("c") | |
| 140 ])); | |
| 141 } | 132 } |
| 142 | 133 |
| 143 void test_visitCascadeExpression_index() { | 134 void test_visitCascadeExpression_index() { |
| 144 _assertClone(AstFactory.cascadeExpression(AstFactory.identifier3("a"), [ | 135 _assertCloneExpression('a..[0]..[1]'); |
| 145 AstFactory.cascadedIndexExpression(AstFactory.integer(0)), | |
| 146 AstFactory.cascadedIndexExpression(AstFactory.integer(1)) | |
| 147 ])); | |
| 148 } | 136 } |
| 149 | 137 |
| 150 void test_visitCascadeExpression_method() { | 138 void test_visitCascadeExpression_method() { |
| 151 _assertClone(AstFactory.cascadeExpression(AstFactory.identifier3("a"), [ | 139 _assertCloneExpression('a..b()..c()'); |
| 152 AstFactory.cascadedMethodInvocation("b"), | |
| 153 AstFactory.cascadedMethodInvocation("c") | |
| 154 ])); | |
| 155 } | 140 } |
| 156 | 141 |
| 157 void test_visitCatchClause_catch_noStack() { | 142 void test_visitCatchClause_catch_noStack() { |
| 158 _assertClone(AstFactory.catchClause("e")); | 143 _assertCloneStatement('try {} catch (e) {}'); |
| 159 } | 144 } |
| 160 | 145 |
| 161 void test_visitCatchClause_catch_stack() { | 146 void test_visitCatchClause_catch_stack() { |
| 162 _assertClone(AstFactory.catchClause2("e", "s")); | 147 _assertCloneStatement('try {} catch (e, s) {}'); |
| 163 } | 148 } |
| 164 | 149 |
| 165 void test_visitCatchClause_on() { | 150 void test_visitCatchClause_on() { |
| 166 _assertClone(AstFactory.catchClause3(AstFactory.typeName4("E"))); | 151 _assertCloneStatement('try {} on E {}'); |
| 167 } | 152 } |
| 168 | 153 |
| 169 void test_visitCatchClause_on_catch() { | 154 void test_visitCatchClause_on_catch() { |
| 170 _assertClone(AstFactory.catchClause4(AstFactory.typeName4("E"), "e")); | 155 _assertCloneStatement('try {} on E catch (e) {}'); |
| 171 } | 156 } |
| 172 | 157 |
| 173 void test_visitClassDeclaration_abstract() { | 158 void test_visitClassDeclaration_abstract() { |
| 174 _assertClone(AstFactory.classDeclaration( | 159 _assertCloneUnitMember('abstract class C {}'); |
| 175 Keyword.ABSTRACT, "C", null, null, null, null)); | |
| 176 } | 160 } |
| 177 | 161 |
| 178 void test_visitClassDeclaration_empty() { | 162 void test_visitClassDeclaration_empty() { |
| 179 _assertClone( | 163 _assertCloneUnitMember('class C {}'); |
| 180 AstFactory.classDeclaration(null, "C", null, null, null, null)); | |
| 181 } | 164 } |
| 182 | 165 |
| 183 void test_visitClassDeclaration_extends() { | 166 void test_visitClassDeclaration_extends() { |
| 184 _assertClone(AstFactory.classDeclaration(null, "C", null, | 167 _assertCloneUnitMember('class C extends A {}'); |
| 185 AstFactory.extendsClause(AstFactory.typeName4("A")), null, null)); | |
| 186 } | 168 } |
| 187 | 169 |
| 188 void test_visitClassDeclaration_extends_implements() { | 170 void test_visitClassDeclaration_extends_implements() { |
| 189 _assertClone(AstFactory.classDeclaration( | 171 _assertCloneUnitMember('class C extends A implements B {}'); |
| 190 null, | |
| 191 "C", | |
| 192 null, | |
| 193 AstFactory.extendsClause(AstFactory.typeName4("A")), | |
| 194 null, | |
| 195 AstFactory.implementsClause([AstFactory.typeName4("B")]))); | |
| 196 } | 172 } |
| 197 | 173 |
| 198 void test_visitClassDeclaration_extends_with() { | 174 void test_visitClassDeclaration_extends_with() { |
| 199 _assertClone(AstFactory.classDeclaration( | 175 _assertCloneUnitMember('class C extends A with M {}'); |
| 200 null, | |
| 201 "C", | |
| 202 null, | |
| 203 AstFactory.extendsClause(AstFactory.typeName4("A")), | |
| 204 AstFactory.withClause([AstFactory.typeName4("M")]), | |
| 205 null)); | |
| 206 } | 176 } |
| 207 | 177 |
| 208 void test_visitClassDeclaration_extends_with_implements() { | 178 void test_visitClassDeclaration_extends_with_implements() { |
| 209 _assertClone(AstFactory.classDeclaration( | 179 _assertCloneUnitMember('class C extends A with M implements B {}'); |
| 210 null, | |
| 211 "C", | |
| 212 null, | |
| 213 AstFactory.extendsClause(AstFactory.typeName4("A")), | |
| 214 AstFactory.withClause([AstFactory.typeName4("M")]), | |
| 215 AstFactory.implementsClause([AstFactory.typeName4("B")]))); | |
| 216 } | 180 } |
| 217 | 181 |
| 218 void test_visitClassDeclaration_implements() { | 182 void test_visitClassDeclaration_implements() { |
| 219 _assertClone(AstFactory.classDeclaration(null, "C", null, null, null, | 183 _assertCloneUnitMember('class C implements B {}'); |
| 220 AstFactory.implementsClause([AstFactory.typeName4("B")]))); | |
| 221 } | 184 } |
| 222 | 185 |
| 223 void test_visitClassDeclaration_multipleMember() { | 186 void test_visitClassDeclaration_multipleMember() { |
| 224 _assertClone( | 187 _assertCloneUnitMember('class C { var a; var b; }'); |
| 225 AstFactory.classDeclaration(null, "C", null, null, null, null, [ | |
| 226 AstFactory.fieldDeclaration2( | |
| 227 false, Keyword.VAR, [AstFactory.variableDeclaration("a")]), | |
| 228 AstFactory.fieldDeclaration2( | |
| 229 false, Keyword.VAR, [AstFactory.variableDeclaration("b")]) | |
| 230 ])); | |
| 231 } | 188 } |
| 232 | 189 |
| 233 void test_visitClassDeclaration_parameters() { | 190 void test_visitClassDeclaration_parameters() { |
| 234 _assertClone(AstFactory.classDeclaration( | 191 _assertCloneUnitMember('class C<E> {}'); |
| 235 null, "C", AstFactory.typeParameterList(["E"]), null, null, null)); | |
| 236 } | 192 } |
| 237 | 193 |
| 238 void test_visitClassDeclaration_parameters_extends() { | 194 void test_visitClassDeclaration_parameters_extends() { |
| 239 _assertClone(AstFactory.classDeclaration( | 195 _assertCloneUnitMember('class C<E> extends A {}'); |
| 240 null, | |
| 241 "C", | |
| 242 AstFactory.typeParameterList(["E"]), | |
| 243 AstFactory.extendsClause(AstFactory.typeName4("A")), | |
| 244 null, | |
| 245 null)); | |
| 246 } | 196 } |
| 247 | 197 |
| 248 void test_visitClassDeclaration_parameters_extends_implements() { | 198 void test_visitClassDeclaration_parameters_extends_implements() { |
| 249 _assertClone(AstFactory.classDeclaration( | 199 _assertCloneUnitMember('class C<E> extends A implements B {}'); |
| 250 null, | |
| 251 "C", | |
| 252 AstFactory.typeParameterList(["E"]), | |
| 253 AstFactory.extendsClause(AstFactory.typeName4("A")), | |
| 254 null, | |
| 255 AstFactory.implementsClause([AstFactory.typeName4("B")]))); | |
| 256 } | 200 } |
| 257 | 201 |
| 258 void test_visitClassDeclaration_parameters_extends_with() { | 202 void test_visitClassDeclaration_parameters_extends_with() { |
| 259 _assertClone(AstFactory.classDeclaration( | 203 _assertCloneUnitMember('class C<E> extends A with M {}'); |
| 260 null, | |
| 261 "C", | |
| 262 AstFactory.typeParameterList(["E"]), | |
| 263 AstFactory.extendsClause(AstFactory.typeName4("A")), | |
| 264 AstFactory.withClause([AstFactory.typeName4("M")]), | |
| 265 null)); | |
| 266 } | 204 } |
| 267 | 205 |
| 268 void test_visitClassDeclaration_parameters_extends_with_implements() { | 206 void test_visitClassDeclaration_parameters_extends_with_implements() { |
| 269 _assertClone(AstFactory.classDeclaration( | 207 _assertCloneUnitMember('class C<E> extends A with M implements B {}'); |
| 270 null, | |
| 271 "C", | |
| 272 AstFactory.typeParameterList(["E"]), | |
| 273 AstFactory.extendsClause(AstFactory.typeName4("A")), | |
| 274 AstFactory.withClause([AstFactory.typeName4("M")]), | |
| 275 AstFactory.implementsClause([AstFactory.typeName4("B")]))); | |
| 276 } | 208 } |
| 277 | 209 |
| 278 void test_visitClassDeclaration_parameters_implements() { | 210 void test_visitClassDeclaration_parameters_implements() { |
| 279 _assertClone(AstFactory.classDeclaration( | 211 _assertCloneUnitMember('class C<E> implements B {}'); |
| 280 null, | |
| 281 "C", | |
| 282 AstFactory.typeParameterList(["E"]), | |
| 283 null, | |
| 284 null, | |
| 285 AstFactory.implementsClause([AstFactory.typeName4("B")]))); | |
| 286 } | 212 } |
| 287 | 213 |
| 288 void test_visitClassDeclaration_singleMember() { | 214 void test_visitClassDeclaration_singleMember() { |
| 289 _assertClone( | 215 _assertCloneUnitMember('class C { var a; }'); |
| 290 AstFactory.classDeclaration(null, "C", null, null, null, null, [ | |
| 291 AstFactory.fieldDeclaration2( | |
| 292 false, Keyword.VAR, [AstFactory.variableDeclaration("a")]) | |
| 293 ])); | |
| 294 } | 216 } |
| 295 | 217 |
| 296 void test_visitClassDeclaration_withMetadata() { | 218 void test_visitClassDeclaration_withMetadata() { |
| 297 ClassDeclaration declaration = | 219 _assertCloneUnitMember('@deprecated class C {}'); |
| 298 AstFactory.classDeclaration(null, "C", null, null, null, null); | |
| 299 declaration.metadata | |
| 300 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 301 _assertClone(declaration); | |
| 302 } | 220 } |
| 303 | 221 |
| 304 void test_visitClassTypeAlias_abstract() { | 222 void test_visitClassTypeAlias_abstract() { |
| 305 _assertClone(AstFactory.classTypeAlias( | 223 _assertCloneUnitMember('abstract class C = S with M1;'); |
| 306 "C", | |
| 307 null, | |
| 308 Keyword.ABSTRACT, | |
| 309 AstFactory.typeName4("S"), | |
| 310 AstFactory.withClause([AstFactory.typeName4("M1")]), | |
| 311 null)); | |
| 312 } | 224 } |
| 313 | 225 |
| 314 void test_visitClassTypeAlias_abstract_implements() { | 226 void test_visitClassTypeAlias_abstract_implements() { |
| 315 _assertClone(AstFactory.classTypeAlias( | 227 _assertCloneUnitMember('abstract class C = S with M1 implements I;'); |
| 316 "C", | |
| 317 null, | |
| 318 Keyword.ABSTRACT, | |
| 319 AstFactory.typeName4("S"), | |
| 320 AstFactory.withClause([AstFactory.typeName4("M1")]), | |
| 321 AstFactory.implementsClause([AstFactory.typeName4("I")]))); | |
| 322 } | 228 } |
| 323 | 229 |
| 324 void test_visitClassTypeAlias_generic() { | 230 void test_visitClassTypeAlias_generic() { |
| 325 _assertClone(AstFactory.classTypeAlias( | 231 _assertCloneUnitMember('class C<E> = S<E> with M1<E>;'); |
| 326 "C", | |
| 327 AstFactory.typeParameterList(["E"]), | |
| 328 null, | |
| 329 AstFactory.typeName4("S", [AstFactory.typeName4("E")]), | |
| 330 AstFactory.withClause([ | |
| 331 AstFactory.typeName4("M1", [AstFactory.typeName4("E")]) | |
| 332 ]), | |
| 333 null)); | |
| 334 } | 232 } |
| 335 | 233 |
| 336 void test_visitClassTypeAlias_implements() { | 234 void test_visitClassTypeAlias_implements() { |
| 337 _assertClone(AstFactory.classTypeAlias( | 235 _assertCloneUnitMember('class C = S with M1 implements I;'); |
| 338 "C", | |
| 339 null, | |
| 340 null, | |
| 341 AstFactory.typeName4("S"), | |
| 342 AstFactory.withClause([AstFactory.typeName4("M1")]), | |
| 343 AstFactory.implementsClause([AstFactory.typeName4("I")]))); | |
| 344 } | 236 } |
| 345 | 237 |
| 346 void test_visitClassTypeAlias_minimal() { | 238 void test_visitClassTypeAlias_minimal() { |
| 347 _assertClone(AstFactory.classTypeAlias( | 239 _assertCloneUnitMember('class C = S with M1;'); |
| 348 "C", | |
| 349 null, | |
| 350 null, | |
| 351 AstFactory.typeName4("S"), | |
| 352 AstFactory.withClause([AstFactory.typeName4("M1")]), | |
| 353 null)); | |
| 354 } | 240 } |
| 355 | 241 |
| 356 void test_visitClassTypeAlias_parameters_abstract() { | 242 void test_visitClassTypeAlias_parameters_abstract() { |
| 357 _assertClone(AstFactory.classTypeAlias( | 243 _assertCloneUnitMember('abstract class C = S<E> with M1;'); |
| 358 "C", | |
| 359 AstFactory.typeParameterList(["E"]), | |
| 360 Keyword.ABSTRACT, | |
| 361 AstFactory.typeName4("S"), | |
| 362 AstFactory.withClause([AstFactory.typeName4("M1")]), | |
| 363 null)); | |
| 364 } | 244 } |
| 365 | 245 |
| 366 void test_visitClassTypeAlias_parameters_abstract_implements() { | 246 void test_visitClassTypeAlias_parameters_abstract_implements() { |
| 367 _assertClone(AstFactory.classTypeAlias( | 247 _assertCloneUnitMember('abstract class C = S<E> with M1 implements I;'); |
| 368 "C", | |
| 369 AstFactory.typeParameterList(["E"]), | |
| 370 Keyword.ABSTRACT, | |
| 371 AstFactory.typeName4("S"), | |
| 372 AstFactory.withClause([AstFactory.typeName4("M1")]), | |
| 373 AstFactory.implementsClause([AstFactory.typeName4("I")]))); | |
| 374 } | 248 } |
| 375 | 249 |
| 376 void test_visitClassTypeAlias_parameters_implements() { | 250 void test_visitClassTypeAlias_parameters_implements() { |
| 377 _assertClone(AstFactory.classTypeAlias( | 251 _assertCloneUnitMember('class C = S<E> with M1 implements I;'); |
| 378 "C", | |
| 379 AstFactory.typeParameterList(["E"]), | |
| 380 null, | |
| 381 AstFactory.typeName4("S"), | |
| 382 AstFactory.withClause([AstFactory.typeName4("M1")]), | |
| 383 AstFactory.implementsClause([AstFactory.typeName4("I")]))); | |
| 384 } | 252 } |
| 385 | 253 |
| 386 void test_visitClassTypeAlias_withMetadata() { | 254 void test_visitClassTypeAlias_withMetadata() { |
| 387 ClassTypeAlias declaration = AstFactory.classTypeAlias( | 255 _assertCloneUnitMember('@deprecated class C = S with M;'); |
| 388 "C", | |
| 389 null, | |
| 390 null, | |
| 391 AstFactory.typeName4("S"), | |
| 392 AstFactory.withClause([AstFactory.typeName4("M1")]), | |
| 393 null); | |
| 394 declaration.metadata | |
| 395 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 396 _assertClone(declaration); | |
| 397 } | 256 } |
| 398 | 257 |
| 399 void test_visitComment() { | 258 void test_visitComment() { |
| 400 _assertClone(Comment.createBlockComment( | 259 _assertCloneUnitMember('main() { print(1); /* comment */ print(2); }'); |
| 401 <Token>[TokenFactory.tokenFromString("/* comment */")])); | 260 } |
| 261 |
| 262 void test_visitComment_beginToken() { |
| 263 _assertCloneUnitMember('/** comment */ main() {}'); |
| 402 } | 264 } |
| 403 | 265 |
| 404 void test_visitCommentReference() { | 266 void test_visitCommentReference() { |
| 405 _assertClone(new CommentReference(null, AstFactory.identifier3("a"))); | 267 _assertCloneUnitMember('/** ref [a]. */ main(a) {}'); |
| 406 } | 268 } |
| 407 | 269 |
| 408 void test_visitCompilationUnit_declaration() { | 270 void test_visitCompilationUnit_declaration() { |
| 409 _assertClone(AstFactory.compilationUnit2([ | 271 _assertCloneUnitMember('var a;'); |
| 410 AstFactory.topLevelVariableDeclaration2( | |
| 411 Keyword.VAR, [AstFactory.variableDeclaration("a")]) | |
| 412 ])); | |
| 413 } | 272 } |
| 414 | 273 |
| 415 void test_visitCompilationUnit_directive() { | 274 void test_visitCompilationUnit_directive() { |
| 416 _assertClone( | 275 _assertCloneUnit('library l;'); |
| 417 AstFactory.compilationUnit3([AstFactory.libraryDirective2("l")])); | |
| 418 } | 276 } |
| 419 | 277 |
| 420 void test_visitCompilationUnit_directive_declaration() { | 278 void test_visitCompilationUnit_directive_declaration() { |
| 421 _assertClone(AstFactory.compilationUnit4([ | 279 _assertCloneUnit('library l; var a;'); |
| 422 AstFactory.libraryDirective2("l") | |
| 423 ], [ | |
| 424 AstFactory.topLevelVariableDeclaration2( | |
| 425 Keyword.VAR, [AstFactory.variableDeclaration("a")]) | |
| 426 ])); | |
| 427 } | 280 } |
| 428 | 281 |
| 429 void test_visitCompilationUnit_empty() { | 282 void test_visitCompilationUnit_empty() { |
| 430 _assertClone(AstFactory.compilationUnit()); | 283 _assertCloneUnit(''); |
| 431 } | 284 } |
| 432 | 285 |
| 433 void test_visitCompilationUnit_script() { | 286 void test_visitCompilationUnit_script() { |
| 434 _assertClone(AstFactory.compilationUnit5("!#/bin/dartvm")); | 287 _assertCloneUnit('#!/bin/dartvm'); |
| 435 } | 288 } |
| 436 | 289 |
| 437 void test_visitCompilationUnit_script_declaration() { | 290 void test_visitCompilationUnit_script_declaration() { |
| 438 _assertClone(AstFactory.compilationUnit6("!#/bin/dartvm", [ | 291 _assertCloneUnit('#!/bin/dartvm \n var a;'); |
| 439 AstFactory.topLevelVariableDeclaration2( | |
| 440 Keyword.VAR, [AstFactory.variableDeclaration("a")]) | |
| 441 ])); | |
| 442 } | 292 } |
| 443 | 293 |
| 444 void test_visitCompilationUnit_script_directive() { | 294 void test_visitCompilationUnit_script_directive() { |
| 445 _assertClone(AstFactory.compilationUnit7( | 295 _assertCloneUnit('#!/bin/dartvm \n library l;'); |
| 446 "!#/bin/dartvm", [AstFactory.libraryDirective2("l")])); | |
| 447 } | 296 } |
| 448 | 297 |
| 449 void test_visitCompilationUnit_script_directives_declarations() { | 298 void test_visitCompilationUnit_script_directives_declarations() { |
| 450 _assertClone(AstFactory.compilationUnit8("!#/bin/dartvm", [ | 299 _assertCloneUnit('#!/bin/dartvm \n library l; var a;'); |
| 451 AstFactory.libraryDirective2("l") | |
| 452 ], [ | |
| 453 AstFactory.topLevelVariableDeclaration2( | |
| 454 Keyword.VAR, [AstFactory.variableDeclaration("a")]) | |
| 455 ])); | |
| 456 } | 300 } |
| 457 | 301 |
| 458 void test_visitConditionalExpression() { | 302 void test_visitConditionalExpression() { |
| 459 _assertClone(AstFactory.conditionalExpression(AstFactory.identifier3("a"), | 303 _assertCloneExpression('a ? b : c'); |
| 460 AstFactory.identifier3("b"), AstFactory.identifier3("c"))); | |
| 461 } | 304 } |
| 462 | 305 |
| 463 void test_visitConstructorDeclaration_const() { | 306 void test_visitConstructorDeclaration_const() { |
| 464 _assertClone(AstFactory.constructorDeclaration2( | 307 _assertCloneUnitMember('class C { const C(); }'); |
| 465 Keyword.CONST, | |
| 466 null, | |
| 467 AstFactory.identifier3("C"), | |
| 468 null, | |
| 469 AstFactory.formalParameterList(), | |
| 470 null, | |
| 471 AstFactory.blockFunctionBody2())); | |
| 472 } | 308 } |
| 473 | 309 |
| 474 void test_visitConstructorDeclaration_external() { | 310 void test_visitConstructorDeclaration_external() { |
| 475 _assertClone(AstFactory.constructorDeclaration(AstFactory.identifier3("C"), | 311 _assertCloneUnitMember('class C { external C(); }'); |
| 476 null, AstFactory.formalParameterList(), null)); | |
| 477 } | 312 } |
| 478 | 313 |
| 479 void test_visitConstructorDeclaration_minimal() { | 314 void test_visitConstructorDeclaration_minimal() { |
| 480 _assertClone(AstFactory.constructorDeclaration2( | 315 _assertCloneUnitMember('class C { C() {} }'); |
| 481 null, | |
| 482 null, | |
| 483 AstFactory.identifier3("C"), | |
| 484 null, | |
| 485 AstFactory.formalParameterList(), | |
| 486 null, | |
| 487 AstFactory.blockFunctionBody2())); | |
| 488 } | 316 } |
| 489 | 317 |
| 490 void test_visitConstructorDeclaration_multipleInitializers() { | 318 void test_visitConstructorDeclaration_multipleInitializers() { |
| 491 _assertClone(AstFactory.constructorDeclaration2( | 319 _assertCloneUnitMember('class C { C() : a = b, c = d {} }'); |
| 492 null, | |
| 493 null, | |
| 494 AstFactory.identifier3("C"), | |
| 495 null, | |
| 496 AstFactory.formalParameterList(), | |
| 497 [ | |
| 498 AstFactory.constructorFieldInitializer( | |
| 499 false, "a", AstFactory.identifier3("b")), | |
| 500 AstFactory.constructorFieldInitializer( | |
| 501 false, "c", AstFactory.identifier3("d")) | |
| 502 ], | |
| 503 AstFactory.blockFunctionBody2())); | |
| 504 } | 320 } |
| 505 | 321 |
| 506 void test_visitConstructorDeclaration_multipleParameters() { | 322 void test_visitConstructorDeclaration_multipleParameters() { |
| 507 _assertClone(AstFactory.constructorDeclaration2( | 323 _assertCloneUnitMember('class C { C(var a, var b) {} }'); |
| 508 null, | |
| 509 null, | |
| 510 AstFactory.identifier3("C"), | |
| 511 null, | |
| 512 AstFactory.formalParameterList([ | |
| 513 AstFactory.simpleFormalParameter(Keyword.VAR, "a"), | |
| 514 AstFactory.simpleFormalParameter(Keyword.VAR, "b") | |
| 515 ]), | |
| 516 null, | |
| 517 AstFactory.blockFunctionBody2())); | |
| 518 } | 324 } |
| 519 | 325 |
| 520 void test_visitConstructorDeclaration_named() { | 326 void test_visitConstructorDeclaration_named() { |
| 521 _assertClone(AstFactory.constructorDeclaration2( | 327 _assertCloneUnitMember('class C { C.m() {} }'); |
| 522 null, | |
| 523 null, | |
| 524 AstFactory.identifier3("C"), | |
| 525 "m", | |
| 526 AstFactory.formalParameterList(), | |
| 527 null, | |
| 528 AstFactory.blockFunctionBody2())); | |
| 529 } | 328 } |
| 530 | 329 |
| 531 void test_visitConstructorDeclaration_singleInitializer() { | 330 void test_visitConstructorDeclaration_singleInitializer() { |
| 532 _assertClone(AstFactory.constructorDeclaration2( | 331 _assertCloneUnitMember('class C { C() : a = b {} }'); |
| 533 null, | |
| 534 null, | |
| 535 AstFactory.identifier3("C"), | |
| 536 null, | |
| 537 AstFactory.formalParameterList(), | |
| 538 [ | |
| 539 AstFactory.constructorFieldInitializer( | |
| 540 false, "a", AstFactory.identifier3("b")) | |
| 541 ], | |
| 542 AstFactory.blockFunctionBody2())); | |
| 543 } | 332 } |
| 544 | 333 |
| 545 void test_visitConstructorDeclaration_withMetadata() { | 334 void test_visitConstructorDeclaration_withMetadata() { |
| 546 ConstructorDeclaration declaration = AstFactory.constructorDeclaration2( | 335 _assertCloneUnitMember('class C { @deprecated C() {} }'); |
| 547 null, | |
| 548 null, | |
| 549 AstFactory.identifier3("C"), | |
| 550 null, | |
| 551 AstFactory.formalParameterList(), | |
| 552 null, | |
| 553 AstFactory.blockFunctionBody2()); | |
| 554 declaration.metadata | |
| 555 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 556 _assertClone(declaration); | |
| 557 } | 336 } |
| 558 | 337 |
| 559 void test_visitConstructorFieldInitializer_withoutThis() { | 338 void test_visitConstructorFieldInitializer_withoutThis() { |
| 560 _assertClone(AstFactory.constructorFieldInitializer( | 339 _assertCloneUnitMember('class C { C() : a = b {} }'); |
| 561 false, "a", AstFactory.identifier3("b"))); | |
| 562 } | 340 } |
| 563 | 341 |
| 564 void test_visitConstructorFieldInitializer_withThis() { | 342 void test_visitConstructorFieldInitializer_withThis() { |
| 565 _assertClone(AstFactory.constructorFieldInitializer( | 343 _assertCloneUnitMember('class C { C() : this.a = b {} }'); |
| 566 true, "a", AstFactory.identifier3("b"))); | |
| 567 } | 344 } |
| 568 | 345 |
| 569 void test_visitConstructorName_named_prefix() { | 346 void test_visitConstructorName_named_prefix() { |
| 570 _assertClone( | 347 _assertCloneExpression('new p.C.n()'); |
| 571 AstFactory.constructorName(AstFactory.typeName4("p.C.n"), null)); | |
| 572 } | 348 } |
| 573 | 349 |
| 574 void test_visitConstructorName_unnamed_noPrefix() { | 350 void test_visitConstructorName_unnamed_noPrefix() { |
| 575 _assertClone(AstFactory.constructorName(AstFactory.typeName4("C"), null)); | 351 _assertCloneExpression('new C()'); |
| 576 } | 352 } |
| 577 | 353 |
| 578 void test_visitConstructorName_unnamed_prefix() { | 354 void test_visitConstructorName_unnamed_prefix() { |
| 579 _assertClone(AstFactory.constructorName( | 355 _assertCloneExpression('new p.C()'); |
| 580 AstFactory.typeName3(AstFactory.identifier5("p", "C")), null)); | |
| 581 } | 356 } |
| 582 | 357 |
| 583 void test_visitContinueStatement_label() { | 358 void test_visitContinueStatement_label() { |
| 584 _assertClone(AstFactory.continueStatement("l")); | 359 _assertCloneStatement('l: while (true) { continue l; }'); |
| 585 } | 360 } |
| 586 | 361 |
| 587 void test_visitContinueStatement_noLabel() { | 362 void test_visitContinueStatement_noLabel() { |
| 588 _assertClone(AstFactory.continueStatement()); | 363 _assertCloneStatement('while (true) { continue; }'); |
| 589 } | 364 } |
| 590 | 365 |
| 591 void test_visitDefaultFormalParameter_named_noValue() { | 366 void test_visitDefaultFormalParameter_named_noValue() { |
| 592 _assertClone(AstFactory.namedFormalParameter( | 367 _assertCloneUnitMember('main({p}) {}'); |
| 593 AstFactory.simpleFormalParameter3("p"), null)); | |
| 594 } | 368 } |
| 595 | 369 |
| 596 void test_visitDefaultFormalParameter_named_value() { | 370 void test_visitDefaultFormalParameter_named_value() { |
| 597 _assertClone(AstFactory.namedFormalParameter( | 371 _assertCloneUnitMember('main({p : 0}) {}'); |
| 598 AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0))); | |
| 599 } | 372 } |
| 600 | 373 |
| 601 void test_visitDefaultFormalParameter_positional_noValue() { | 374 void test_visitDefaultFormalParameter_positional_noValue() { |
| 602 _assertClone(AstFactory.positionalFormalParameter( | 375 _assertCloneUnitMember('main([p]) {}'); |
| 603 AstFactory.simpleFormalParameter3("p"), null)); | |
| 604 } | 376 } |
| 605 | 377 |
| 606 void test_visitDefaultFormalParameter_positional_value() { | 378 void test_visitDefaultFormalParameter_positional_value() { |
| 607 _assertClone(AstFactory.positionalFormalParameter( | 379 _assertCloneUnitMember('main([p = 0]) {}'); |
| 608 AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0))); | |
| 609 } | 380 } |
| 610 | 381 |
| 611 void test_visitDoStatement() { | 382 void test_visitDoStatement() { |
| 612 _assertClone(AstFactory.doStatement( | 383 _assertCloneStatement('do {} while (c);'); |
| 613 AstFactory.block(), AstFactory.identifier3("c"))); | |
| 614 } | 384 } |
| 615 | 385 |
| 616 void test_visitDoubleLiteral() { | 386 void test_visitDoubleLiteral() { |
| 617 _assertClone(AstFactory.doubleLiteral(4.2)); | 387 _assertCloneExpression('4.2'); |
| 618 } | 388 } |
| 619 | 389 |
| 620 void test_visitEmptyFunctionBody() { | 390 void test_visitEmptyFunctionBody() { |
| 621 _assertClone(AstFactory.emptyFunctionBody()); | 391 _assertCloneUnitMember('main() {}'); |
| 622 } | 392 } |
| 623 | 393 |
| 624 void test_visitEmptyStatement() { | 394 void test_visitEmptyStatement() { |
| 625 _assertClone(AstFactory.emptyStatement()); | 395 _assertCloneUnitMember('main() { ; }'); |
| 626 } | 396 } |
| 627 | 397 |
| 628 void test_visitExportDirective_combinator() { | 398 void test_visitExportDirective_combinator() { |
| 629 _assertClone(AstFactory.exportDirective2("a.dart", [ | 399 _assertCloneUnit('export "a.dart" show A;'); |
| 630 AstFactory.showCombinator([AstFactory.identifier3("A")]) | |
| 631 ])); | |
| 632 } | 400 } |
| 633 | 401 |
| 634 void test_visitExportDirective_combinators() { | 402 void test_visitExportDirective_combinators() { |
| 635 _assertClone(AstFactory.exportDirective2("a.dart", [ | 403 _assertCloneUnit('export "a.dart" show A hide B;'); |
| 636 AstFactory.showCombinator([AstFactory.identifier3("A")]), | |
| 637 AstFactory.hideCombinator([AstFactory.identifier3("B")]) | |
| 638 ])); | |
| 639 } | 404 } |
| 640 | 405 |
| 641 void test_visitExportDirective_minimal() { | 406 void test_visitExportDirective_minimal() { |
| 642 _assertClone(AstFactory.exportDirective2("a.dart")); | 407 _assertCloneUnit('export "a.dart";'); |
| 643 } | 408 } |
| 644 | 409 |
| 645 void test_visitExportDirective_withMetadata() { | 410 void test_visitExportDirective_withMetadata() { |
| 646 ExportDirective directive = AstFactory.exportDirective2("a.dart"); | 411 _assertCloneUnit('@deprecated export "a.dart";'); |
| 647 directive.metadata | |
| 648 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 649 _assertClone(directive); | |
| 650 } | 412 } |
| 651 | 413 |
| 652 void test_visitExpressionFunctionBody() { | 414 void test_visitExpressionFunctionBody() { |
| 653 _assertClone( | 415 _assertCloneUnitMember('main() => a;'); |
| 654 AstFactory.expressionFunctionBody(AstFactory.identifier3("a"))); | |
| 655 } | 416 } |
| 656 | 417 |
| 657 void test_visitExpressionStatement() { | 418 void test_visitExpressionStatement() { |
| 658 _assertClone(AstFactory.expressionStatement(AstFactory.identifier3("a"))); | 419 _assertCloneStatement('a;'); |
| 659 } | 420 } |
| 660 | 421 |
| 661 void test_visitExtendsClause() { | 422 void test_visitExtendsClause() { |
| 662 _assertClone(AstFactory.extendsClause(AstFactory.typeName4("C"))); | 423 _assertCloneUnitMember('class A extends B {}'); |
| 663 } | 424 } |
| 664 | 425 |
| 665 void test_visitFieldDeclaration_instance() { | 426 void test_visitFieldDeclaration_instance() { |
| 666 _assertClone(AstFactory.fieldDeclaration2( | 427 _assertCloneUnitMember('class C { var a; }'); |
| 667 false, Keyword.VAR, [AstFactory.variableDeclaration("a")])); | |
| 668 } | 428 } |
| 669 | 429 |
| 670 void test_visitFieldDeclaration_static() { | 430 void test_visitFieldDeclaration_static() { |
| 671 _assertClone(AstFactory.fieldDeclaration2( | 431 _assertCloneUnitMember('class C { static var a; }'); |
| 672 true, Keyword.VAR, [AstFactory.variableDeclaration("a")])); | |
| 673 } | 432 } |
| 674 | 433 |
| 675 void test_visitFieldDeclaration_withMetadata() { | 434 void test_visitFieldDeclaration_withMetadata() { |
| 676 FieldDeclaration declaration = AstFactory.fieldDeclaration2( | 435 _assertCloneUnitMember('class C { @deprecated var a; }'); |
| 677 false, Keyword.VAR, [AstFactory.variableDeclaration("a")]); | |
| 678 declaration.metadata | |
| 679 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 680 _assertClone(declaration); | |
| 681 } | 436 } |
| 682 | 437 |
| 683 void test_visitFieldFormalParameter_functionTyped() { | 438 void test_visitFieldFormalParameter_functionTyped() { |
| 684 _assertClone(AstFactory.fieldFormalParameter( | 439 _assertCloneUnitMember('class C { C(A this.a(b)); }'); |
| 685 null, | |
| 686 AstFactory.typeName4("A"), | |
| 687 "a", | |
| 688 AstFactory | |
| 689 .formalParameterList([AstFactory.simpleFormalParameter3("b")]))); | |
| 690 } | 440 } |
| 691 | 441 |
| 692 void test_visitFieldFormalParameter_keyword() { | 442 void test_visitFieldFormalParameter_keyword() { |
| 693 _assertClone(AstFactory.fieldFormalParameter(Keyword.VAR, null, "a")); | 443 _assertCloneUnitMember('class C { C(var this.a); }'); |
| 694 } | 444 } |
| 695 | 445 |
| 696 void test_visitFieldFormalParameter_keywordAndType() { | 446 void test_visitFieldFormalParameter_keywordAndType() { |
| 697 _assertClone(AstFactory.fieldFormalParameter( | 447 _assertCloneUnitMember('class C { C(final A this.a); }'); |
| 698 Keyword.FINAL, AstFactory.typeName4("A"), "a")); | |
| 699 } | 448 } |
| 700 | 449 |
| 701 void test_visitFieldFormalParameter_type() { | 450 void test_visitFieldFormalParameter_type() { |
| 702 _assertClone( | 451 _assertCloneUnitMember('class C { C(A this.a); }'); |
| 703 AstFactory.fieldFormalParameter(null, AstFactory.typeName4("A"), "a")); | |
| 704 } | 452 } |
| 705 | 453 |
| 706 void test_visitForEachStatement_declared() { | 454 void test_visitForEachStatement_declared() { |
| 707 _assertClone(AstFactory.forEachStatement( | 455 _assertCloneStatement('for (var a in b) {}'); |
| 708 AstFactory.declaredIdentifier3("a"), | |
| 709 AstFactory.identifier3("b"), | |
| 710 AstFactory.block())); | |
| 711 } | 456 } |
| 712 | 457 |
| 713 void test_visitForEachStatement_variable() { | 458 void test_visitForEachStatement_variable() { |
| 714 _assertClone(new ForEachStatement.withReference( | 459 _assertCloneStatement('for (a in b) {}'); |
| 715 null, | |
| 716 TokenFactory.tokenFromKeyword(Keyword.FOR), | |
| 717 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
| 718 AstFactory.identifier3("a"), | |
| 719 TokenFactory.tokenFromKeyword(Keyword.IN), | |
| 720 AstFactory.identifier3("b"), | |
| 721 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
| 722 AstFactory.block())); | |
| 723 } | 460 } |
| 724 | 461 |
| 725 void test_visitForEachStatement_variable_await() { | 462 void test_visitForEachStatement_variable_await() { |
| 726 _assertClone(new ForEachStatement.withReference( | 463 _assertCloneUnitMember('main(s) async { await for (a in s) {} }'); |
| 727 TokenFactory.tokenFromString("await"), | |
| 728 TokenFactory.tokenFromKeyword(Keyword.FOR), | |
| 729 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), | |
| 730 AstFactory.identifier3("a"), | |
| 731 TokenFactory.tokenFromKeyword(Keyword.IN), | |
| 732 AstFactory.identifier3("b"), | |
| 733 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), | |
| 734 AstFactory.block())); | |
| 735 } | 464 } |
| 736 | 465 |
| 737 void test_visitFormalParameterList_empty() { | 466 void test_visitFormalParameterList_empty() { |
| 738 _assertClone(AstFactory.formalParameterList()); | 467 _assertCloneUnitMember('main() {}'); |
| 739 } | 468 } |
| 740 | 469 |
| 741 void test_visitFormalParameterList_n() { | 470 void test_visitFormalParameterList_n() { |
| 742 _assertClone(AstFactory.formalParameterList([ | 471 _assertCloneUnitMember('main({a: 0}) {}'); |
| 743 AstFactory.namedFormalParameter( | |
| 744 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)) | |
| 745 ])); | |
| 746 } | 472 } |
| 747 | 473 |
| 748 void test_visitFormalParameterList_nn() { | 474 void test_visitFormalParameterList_nn() { |
| 749 _assertClone(AstFactory.formalParameterList([ | 475 _assertCloneUnitMember('main({a: 0, b: 1}) {}'); |
| 750 AstFactory.namedFormalParameter( | |
| 751 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)), | |
| 752 AstFactory.namedFormalParameter( | |
| 753 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)) | |
| 754 ])); | |
| 755 } | 476 } |
| 756 | 477 |
| 757 void test_visitFormalParameterList_p() { | 478 void test_visitFormalParameterList_p() { |
| 758 _assertClone(AstFactory.formalParameterList([ | 479 _assertCloneUnitMember('main([a = 0]) {}'); |
| 759 AstFactory.positionalFormalParameter( | |
| 760 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)) | |
| 761 ])); | |
| 762 } | 480 } |
| 763 | 481 |
| 764 void test_visitFormalParameterList_pp() { | 482 void test_visitFormalParameterList_pp() { |
| 765 _assertClone(AstFactory.formalParameterList([ | 483 _assertCloneUnitMember('main([a = 0, b = 1]) {}'); |
| 766 AstFactory.positionalFormalParameter( | |
| 767 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)), | |
| 768 AstFactory.positionalFormalParameter( | |
| 769 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)) | |
| 770 ])); | |
| 771 } | 484 } |
| 772 | 485 |
| 773 void test_visitFormalParameterList_r() { | 486 void test_visitFormalParameterList_r() { |
| 774 _assertClone(AstFactory | 487 _assertCloneUnitMember('main(a) {}'); |
| 775 .formalParameterList([AstFactory.simpleFormalParameter3("a")])); | |
| 776 } | 488 } |
| 777 | 489 |
| 778 void test_visitFormalParameterList_rn() { | 490 void test_visitFormalParameterList_rn() { |
| 779 _assertClone(AstFactory.formalParameterList([ | 491 _assertCloneUnitMember('main(a, {b: 1}) {}'); |
| 780 AstFactory.simpleFormalParameter3("a"), | |
| 781 AstFactory.namedFormalParameter( | |
| 782 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)) | |
| 783 ])); | |
| 784 } | 492 } |
| 785 | 493 |
| 786 void test_visitFormalParameterList_rnn() { | 494 void test_visitFormalParameterList_rnn() { |
| 787 _assertClone(AstFactory.formalParameterList([ | 495 _assertCloneUnitMember('main(a, {b: 1, c: 2}) {}'); |
| 788 AstFactory.simpleFormalParameter3("a"), | |
| 789 AstFactory.namedFormalParameter( | |
| 790 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)), | |
| 791 AstFactory.namedFormalParameter( | |
| 792 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(2)) | |
| 793 ])); | |
| 794 } | 496 } |
| 795 | 497 |
| 796 void test_visitFormalParameterList_rp() { | 498 void test_visitFormalParameterList_rp() { |
| 797 _assertClone(AstFactory.formalParameterList([ | 499 _assertCloneUnitMember('main(a, [b = 1]) {}'); |
| 798 AstFactory.simpleFormalParameter3("a"), | |
| 799 AstFactory.positionalFormalParameter( | |
| 800 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)) | |
| 801 ])); | |
| 802 } | 500 } |
| 803 | 501 |
| 804 void test_visitFormalParameterList_rpp() { | 502 void test_visitFormalParameterList_rpp() { |
| 805 _assertClone(AstFactory.formalParameterList([ | 503 _assertCloneUnitMember('main(a, [b = 1, c = 2]) {}'); |
| 806 AstFactory.simpleFormalParameter3("a"), | |
| 807 AstFactory.positionalFormalParameter( | |
| 808 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)), | |
| 809 AstFactory.positionalFormalParameter( | |
| 810 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(2)) | |
| 811 ])); | |
| 812 } | 504 } |
| 813 | 505 |
| 814 void test_visitFormalParameterList_rr() { | 506 void test_visitFormalParameterList_rr() { |
| 815 _assertClone(AstFactory.formalParameterList([ | 507 _assertCloneUnitMember('main(a, b) {}'); |
| 816 AstFactory.simpleFormalParameter3("a"), | |
| 817 AstFactory.simpleFormalParameter3("b") | |
| 818 ])); | |
| 819 } | 508 } |
| 820 | 509 |
| 821 void test_visitFormalParameterList_rrn() { | 510 void test_visitFormalParameterList_rrn() { |
| 822 _assertClone(AstFactory.formalParameterList([ | 511 _assertCloneUnitMember('main(a, b, {c: 3}) {}'); |
| 823 AstFactory.simpleFormalParameter3("a"), | |
| 824 AstFactory.simpleFormalParameter3("b"), | |
| 825 AstFactory.namedFormalParameter( | |
| 826 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)) | |
| 827 ])); | |
| 828 } | 512 } |
| 829 | 513 |
| 830 void test_visitFormalParameterList_rrnn() { | 514 void test_visitFormalParameterList_rrnn() { |
| 831 _assertClone(AstFactory.formalParameterList([ | 515 _assertCloneUnitMember('main(a, b, {c: 3, d: 4}) {}'); |
| 832 AstFactory.simpleFormalParameter3("a"), | |
| 833 AstFactory.simpleFormalParameter3("b"), | |
| 834 AstFactory.namedFormalParameter( | |
| 835 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)), | |
| 836 AstFactory.namedFormalParameter( | |
| 837 AstFactory.simpleFormalParameter3("d"), AstFactory.integer(4)) | |
| 838 ])); | |
| 839 } | 516 } |
| 840 | 517 |
| 841 void test_visitFormalParameterList_rrp() { | 518 void test_visitFormalParameterList_rrp() { |
| 842 _assertClone(AstFactory.formalParameterList([ | 519 _assertCloneUnitMember('main(a, b, [c = 3]) {}'); |
| 843 AstFactory.simpleFormalParameter3("a"), | |
| 844 AstFactory.simpleFormalParameter3("b"), | |
| 845 AstFactory.positionalFormalParameter( | |
| 846 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)) | |
| 847 ])); | |
| 848 } | 520 } |
| 849 | 521 |
| 850 void test_visitFormalParameterList_rrpp() { | 522 void test_visitFormalParameterList_rrpp() { |
| 851 _assertClone(AstFactory.formalParameterList([ | 523 _assertCloneUnitMember('main(a, b, [c = 3, d = 4]) {}'); |
| 852 AstFactory.simpleFormalParameter3("a"), | |
| 853 AstFactory.simpleFormalParameter3("b"), | |
| 854 AstFactory.positionalFormalParameter( | |
| 855 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)), | |
| 856 AstFactory.positionalFormalParameter( | |
| 857 AstFactory.simpleFormalParameter3("d"), AstFactory.integer(4)) | |
| 858 ])); | |
| 859 } | 524 } |
| 860 | 525 |
| 861 void test_visitForStatement_c() { | 526 void test_visitForStatement_c() { |
| 862 _assertClone(AstFactory.forStatement( | 527 _assertCloneStatement('for (; c;) {}'); |
| 863 null, AstFactory.identifier3("c"), null, AstFactory.block())); | |
| 864 } | 528 } |
| 865 | 529 |
| 866 void test_visitForStatement_cu() { | 530 void test_visitForStatement_cu() { |
| 867 _assertClone(AstFactory.forStatement(null, AstFactory.identifier3("c"), | 531 _assertCloneStatement('for (; c; u) {}'); |
| 868 [AstFactory.identifier3("u")], AstFactory.block())); | |
| 869 } | 532 } |
| 870 | 533 |
| 871 void test_visitForStatement_e() { | 534 void test_visitForStatement_e() { |
| 872 _assertClone(AstFactory.forStatement( | 535 _assertCloneStatement('for (e; ;) {}'); |
| 873 AstFactory.identifier3("e"), null, null, AstFactory.block())); | |
| 874 } | 536 } |
| 875 | 537 |
| 876 void test_visitForStatement_ec() { | 538 void test_visitForStatement_ec() { |
| 877 _assertClone(AstFactory.forStatement(AstFactory.identifier3("e"), | 539 _assertCloneStatement('for (e; c;) {}'); |
| 878 AstFactory.identifier3("c"), null, AstFactory.block())); | |
| 879 } | 540 } |
| 880 | 541 |
| 881 void test_visitForStatement_ecu() { | 542 void test_visitForStatement_ecu() { |
| 882 _assertClone(AstFactory.forStatement( | 543 _assertCloneStatement('for (e; c; u) {}'); |
| 883 AstFactory.identifier3("e"), | |
| 884 AstFactory.identifier3("c"), | |
| 885 [AstFactory.identifier3("u")], | |
| 886 AstFactory.block())); | |
| 887 } | 544 } |
| 888 | 545 |
| 889 void test_visitForStatement_eu() { | 546 void test_visitForStatement_eu() { |
| 890 _assertClone(AstFactory.forStatement(AstFactory.identifier3("e"), null, | 547 _assertCloneStatement('for (e; ; u) {}'); |
| 891 [AstFactory.identifier3("u")], AstFactory.block())); | |
| 892 } | 548 } |
| 893 | 549 |
| 894 void test_visitForStatement_i() { | 550 void test_visitForStatement_i() { |
| 895 _assertClone(AstFactory.forStatement2( | 551 _assertCloneStatement('for (var i; ;) {}'); |
| 896 AstFactory.variableDeclarationList2( | |
| 897 Keyword.VAR, [AstFactory.variableDeclaration("i")]), | |
| 898 null, | |
| 899 null, | |
| 900 AstFactory.block())); | |
| 901 } | 552 } |
| 902 | 553 |
| 903 void test_visitForStatement_ic() { | 554 void test_visitForStatement_ic() { |
| 904 _assertClone(AstFactory.forStatement2( | 555 _assertCloneStatement('for (var i; c;) {}'); |
| 905 AstFactory.variableDeclarationList2( | |
| 906 Keyword.VAR, [AstFactory.variableDeclaration("i")]), | |
| 907 AstFactory.identifier3("c"), | |
| 908 null, | |
| 909 AstFactory.block())); | |
| 910 } | 556 } |
| 911 | 557 |
| 912 void test_visitForStatement_icu() { | 558 void test_visitForStatement_icu() { |
| 913 _assertClone(AstFactory.forStatement2( | 559 _assertCloneStatement('for (var i; c; u) {}'); |
| 914 AstFactory.variableDeclarationList2( | |
| 915 Keyword.VAR, [AstFactory.variableDeclaration("i")]), | |
| 916 AstFactory.identifier3("c"), | |
| 917 [AstFactory.identifier3("u")], | |
| 918 AstFactory.block())); | |
| 919 } | 560 } |
| 920 | 561 |
| 921 void test_visitForStatement_iu() { | 562 void test_visitForStatement_iu() { |
| 922 _assertClone(AstFactory.forStatement2( | 563 _assertCloneStatement('for (var i; ; u) {}'); |
| 923 AstFactory.variableDeclarationList2( | |
| 924 Keyword.VAR, [AstFactory.variableDeclaration("i")]), | |
| 925 null, | |
| 926 [AstFactory.identifier3("u")], | |
| 927 AstFactory.block())); | |
| 928 } | 564 } |
| 929 | 565 |
| 930 void test_visitForStatement_u() { | 566 void test_visitForStatement_u() { |
| 931 _assertClone(AstFactory.forStatement( | 567 _assertCloneStatement('for (; ; u) {}'); |
| 932 null, null, [AstFactory.identifier3("u")], AstFactory.block())); | |
| 933 } | 568 } |
| 934 | 569 |
| 935 void test_visitFunctionDeclaration_getter() { | 570 void test_visitFunctionDeclaration_getter() { |
| 936 _assertClone(AstFactory.functionDeclaration( | 571 _assertCloneUnitMember('get f {}'); |
| 937 null, Keyword.GET, "f", AstFactory.functionExpression())); | |
| 938 } | 572 } |
| 939 | 573 |
| 940 void test_visitFunctionDeclaration_normal() { | 574 void test_visitFunctionDeclaration_normal() { |
| 941 _assertClone(AstFactory.functionDeclaration( | 575 _assertCloneUnitMember('f() {}'); |
| 942 null, null, "f", AstFactory.functionExpression())); | |
| 943 } | 576 } |
| 944 | 577 |
| 945 void test_visitFunctionDeclaration_setter() { | 578 void test_visitFunctionDeclaration_setter() { |
| 946 _assertClone(AstFactory.functionDeclaration( | 579 _assertCloneUnitMember('set f(x) {}'); |
| 947 null, Keyword.SET, "f", AstFactory.functionExpression())); | |
| 948 } | 580 } |
| 949 | 581 |
| 950 void test_visitFunctionDeclaration_withMetadata() { | 582 void test_visitFunctionDeclaration_withMetadata() { |
| 951 FunctionDeclaration declaration = AstFactory.functionDeclaration( | 583 _assertCloneUnitMember('@deprecated f() {}'); |
| 952 null, null, "f", AstFactory.functionExpression()); | |
| 953 declaration.metadata | |
| 954 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 955 _assertClone(declaration); | |
| 956 } | 584 } |
| 957 | 585 |
| 958 void test_visitFunctionDeclarationStatement() { | 586 void test_visitFunctionDeclarationStatement() { |
| 959 _assertClone(AstFactory.functionDeclarationStatement( | 587 _assertCloneStatement('f() {}'); |
| 960 null, null, "f", AstFactory.functionExpression())); | |
| 961 } | |
| 962 | |
| 963 void test_visitFunctionExpression() { | |
| 964 _assertClone(AstFactory.functionExpression()); | |
| 965 } | 588 } |
| 966 | 589 |
| 967 void test_visitFunctionExpressionInvocation() { | 590 void test_visitFunctionExpressionInvocation() { |
| 968 _assertClone( | 591 _assertCloneStatement('{ () {}(); }'); |
| 969 AstFactory.functionExpressionInvocation(AstFactory.identifier3("f"))); | |
| 970 } | 592 } |
| 971 | 593 |
| 972 void test_visitFunctionTypeAlias_generic() { | 594 void test_visitFunctionTypeAlias_generic() { |
| 973 _assertClone(AstFactory.typeAlias(AstFactory.typeName4("A"), "F", | 595 _assertCloneUnitMember('typedef A F<B>();'); |
| 974 AstFactory.typeParameterList(["B"]), AstFactory.formalParameterList())); | |
| 975 } | 596 } |
| 976 | 597 |
| 977 void test_visitFunctionTypeAlias_nonGeneric() { | 598 void test_visitFunctionTypeAlias_nonGeneric() { |
| 978 _assertClone(AstFactory.typeAlias(AstFactory.typeName4("A"), "F", null, | 599 _assertCloneUnitMember('typedef A F();'); |
| 979 AstFactory.formalParameterList())); | |
| 980 } | 600 } |
| 981 | 601 |
| 982 void test_visitFunctionTypeAlias_withMetadata() { | 602 void test_visitFunctionTypeAlias_withMetadata() { |
| 983 FunctionTypeAlias declaration = AstFactory.typeAlias( | 603 _assertCloneUnitMember('@deprecated typedef A F();'); |
| 984 AstFactory.typeName4("A"), "F", null, AstFactory.formalParameterList()); | |
| 985 declaration.metadata | |
| 986 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 987 _assertClone(declaration); | |
| 988 } | 604 } |
| 989 | 605 |
| 990 void test_visitFunctionTypedFormalParameter_noType() { | 606 void test_visitFunctionTypedFormalParameter_noType() { |
| 991 _assertClone(AstFactory.functionTypedFormalParameter(null, "f")); | 607 _assertCloneUnitMember('main( f() ) {}'); |
| 992 } | 608 } |
| 993 | 609 |
| 994 void test_visitFunctionTypedFormalParameter_type() { | 610 void test_visitFunctionTypedFormalParameter_type() { |
| 995 _assertClone(AstFactory.functionTypedFormalParameter( | 611 _assertCloneUnitMember('main( T f() ) {}'); |
| 996 AstFactory.typeName4("T"), "f")); | |
| 997 } | 612 } |
| 998 | 613 |
| 999 void test_visitIfStatement_withElse() { | 614 void test_visitIfStatement_withElse() { |
| 1000 _assertClone(AstFactory.ifStatement2( | 615 _assertCloneStatement('if (c) {} else {}'); |
| 1001 AstFactory.identifier3("c"), AstFactory.block(), AstFactory.block())); | |
| 1002 } | 616 } |
| 1003 | 617 |
| 1004 void test_visitIfStatement_withoutElse() { | 618 void test_visitIfStatement_withoutElse() { |
| 1005 _assertClone(AstFactory.ifStatement( | 619 _assertCloneStatement('if (c) {}'); |
| 1006 AstFactory.identifier3("c"), AstFactory.block())); | |
| 1007 } | 620 } |
| 1008 | 621 |
| 1009 void test_visitImplementsClause_multiple() { | 622 void test_visitImplementsClause_multiple() { |
| 1010 _assertClone(AstFactory.implementsClause( | 623 _assertCloneUnitMember('class A implements B, C {}'); |
| 1011 [AstFactory.typeName4("A"), AstFactory.typeName4("B")])); | |
| 1012 } | 624 } |
| 1013 | 625 |
| 1014 void test_visitImplementsClause_single() { | 626 void test_visitImplementsClause_single() { |
| 1015 _assertClone(AstFactory.implementsClause([AstFactory.typeName4("A")])); | 627 _assertCloneUnitMember('class A implements B {}'); |
| 1016 } | 628 } |
| 1017 | 629 |
| 1018 void test_visitImportDirective_combinator() { | 630 void test_visitImportDirective_combinator() { |
| 1019 _assertClone(AstFactory.importDirective3("a.dart", null, [ | 631 _assertCloneUnit('import "a.dart" show A;'); |
| 1020 AstFactory.showCombinator([AstFactory.identifier3("A")]) | |
| 1021 ])); | |
| 1022 } | 632 } |
| 1023 | 633 |
| 1024 void test_visitImportDirective_combinators() { | 634 void test_visitImportDirective_combinators() { |
| 1025 _assertClone(AstFactory.importDirective3("a.dart", null, [ | 635 _assertCloneUnit('import "a.dart" show A hide B;'); |
| 1026 AstFactory.showCombinator([AstFactory.identifier3("A")]), | |
| 1027 AstFactory.hideCombinator([AstFactory.identifier3("B")]) | |
| 1028 ])); | |
| 1029 } | 636 } |
| 1030 | 637 |
| 1031 void test_visitImportDirective_minimal() { | 638 void test_visitImportDirective_minimal() { |
| 1032 _assertClone(AstFactory.importDirective3("a.dart", null)); | 639 _assertCloneUnit('import "a.dart";'); |
| 1033 } | 640 } |
| 1034 | 641 |
| 1035 void test_visitImportDirective_prefix() { | 642 void test_visitImportDirective_prefix() { |
| 1036 _assertClone(AstFactory.importDirective3("a.dart", "p")); | 643 _assertCloneUnit('import "a.dart" as p;'); |
| 1037 } | 644 } |
| 1038 | 645 |
| 1039 void test_visitImportDirective_prefix_combinator() { | 646 void test_visitImportDirective_prefix_combinator() { |
| 1040 _assertClone(AstFactory.importDirective3("a.dart", "p", [ | 647 _assertCloneUnit('import "a.dart" as p show A;'); |
| 1041 AstFactory.showCombinator([AstFactory.identifier3("A")]) | |
| 1042 ])); | |
| 1043 } | 648 } |
| 1044 | 649 |
| 1045 void test_visitImportDirective_prefix_combinators() { | 650 void test_visitImportDirective_prefix_combinators() { |
| 1046 _assertClone(AstFactory.importDirective3("a.dart", "p", [ | 651 _assertCloneUnit('import "a.dart" as p show A hide B;'); |
| 1047 AstFactory.showCombinator([AstFactory.identifier3("A")]), | |
| 1048 AstFactory.hideCombinator([AstFactory.identifier3("B")]) | |
| 1049 ])); | |
| 1050 } | 652 } |
| 1051 | 653 |
| 1052 void test_visitImportDirective_withMetadata() { | 654 void test_visitImportDirective_withMetadata() { |
| 1053 ImportDirective directive = AstFactory.importDirective3("a.dart", null); | 655 _assertCloneUnit('@deprecated import "a.dart";'); |
| 1054 directive.metadata | |
| 1055 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 1056 _assertClone(directive); | |
| 1057 } | 656 } |
| 1058 | 657 |
| 1059 void test_visitImportHideCombinator_multiple() { | 658 void test_visitImportHideCombinator_multiple() { |
| 1060 _assertClone(AstFactory.hideCombinator( | 659 _assertCloneUnit('import "a.dart" hide a, b;'); |
| 1061 [AstFactory.identifier3("a"), AstFactory.identifier3("b")])); | |
| 1062 } | 660 } |
| 1063 | 661 |
| 1064 void test_visitImportHideCombinator_single() { | 662 void test_visitImportHideCombinator_single() { |
| 1065 _assertClone(AstFactory.hideCombinator([AstFactory.identifier3("a")])); | 663 _assertCloneUnit('import "a.dart" hide a;'); |
| 1066 } | 664 } |
| 1067 | 665 |
| 1068 void test_visitImportShowCombinator_multiple() { | 666 void test_visitImportShowCombinator_multiple() { |
| 1069 _assertClone(AstFactory.showCombinator( | 667 _assertCloneUnit('import "a.dart" show a, b;'); |
| 1070 [AstFactory.identifier3("a"), AstFactory.identifier3("b")])); | |
| 1071 } | 668 } |
| 1072 | 669 |
| 1073 void test_visitImportShowCombinator_single() { | 670 void test_visitImportShowCombinator_single() { |
| 1074 _assertClone(AstFactory.showCombinator([AstFactory.identifier3("a")])); | 671 _assertCloneUnit('import "a.dart" show a;'); |
| 1075 } | 672 } |
| 1076 | 673 |
| 1077 void test_visitIndexExpression() { | 674 void test_visitIndexExpression() { |
| 1078 _assertClone(AstFactory.indexExpression( | 675 _assertCloneExpression('a[i]'); |
| 1079 AstFactory.identifier3("a"), AstFactory.identifier3("i"))); | |
| 1080 } | 676 } |
| 1081 | 677 |
| 1082 void test_visitInstanceCreationExpression_const() { | 678 void test_visitInstanceCreationExpression_const() { |
| 1083 _assertClone(AstFactory.instanceCreationExpression2( | 679 _assertCloneExpression('const C()'); |
| 1084 Keyword.CONST, AstFactory.typeName4("C"))); | |
| 1085 } | 680 } |
| 1086 | 681 |
| 1087 void test_visitInstanceCreationExpression_named() { | 682 void test_visitInstanceCreationExpression_named() { |
| 1088 _assertClone(AstFactory.instanceCreationExpression3( | 683 _assertCloneExpression('new C.c()'); |
| 1089 Keyword.NEW, AstFactory.typeName4("C"), "c")); | |
| 1090 } | 684 } |
| 1091 | 685 |
| 1092 void test_visitInstanceCreationExpression_unnamed() { | 686 void test_visitInstanceCreationExpression_unnamed() { |
| 1093 _assertClone(AstFactory.instanceCreationExpression2( | 687 _assertCloneExpression('new C()'); |
| 1094 Keyword.NEW, AstFactory.typeName4("C"))); | |
| 1095 } | 688 } |
| 1096 | 689 |
| 1097 void test_visitIntegerLiteral() { | 690 void test_visitIntegerLiteral() { |
| 1098 _assertClone(AstFactory.integer(42)); | 691 _assertCloneExpression('42'); |
| 1099 } | 692 } |
| 1100 | 693 |
| 1101 void test_visitInterpolationExpression_expression() { | 694 void test_visitInterpolationExpression_expression() { |
| 1102 _assertClone( | 695 _assertCloneExpression(r'"${c}"'); |
| 1103 AstFactory.interpolationExpression(AstFactory.identifier3("a"))); | |
| 1104 } | 696 } |
| 1105 | 697 |
| 1106 void test_visitInterpolationExpression_identifier() { | 698 void test_visitInterpolationExpression_identifier() { |
| 1107 _assertClone(AstFactory.interpolationExpression2("a")); | 699 _assertCloneExpression(r'"$c"'); |
| 1108 } | |
| 1109 | |
| 1110 void test_visitInterpolationString() { | |
| 1111 _assertClone(AstFactory.interpolationString("'x", "x")); | |
| 1112 } | 700 } |
| 1113 | 701 |
| 1114 void test_visitIsExpression_negated() { | 702 void test_visitIsExpression_negated() { |
| 1115 _assertClone(AstFactory.isExpression( | 703 _assertCloneExpression('a is! C'); |
| 1116 AstFactory.identifier3("a"), true, AstFactory.typeName4("C"))); | |
| 1117 } | 704 } |
| 1118 | 705 |
| 1119 void test_visitIsExpression_normal() { | 706 void test_visitIsExpression_normal() { |
| 1120 _assertClone(AstFactory.isExpression( | 707 _assertCloneExpression('a is C'); |
| 1121 AstFactory.identifier3("a"), false, AstFactory.typeName4("C"))); | |
| 1122 } | 708 } |
| 1123 | 709 |
| 1124 void test_visitLabel() { | 710 void test_visitLabel() { |
| 1125 _assertClone(AstFactory.label2("a")); | 711 _assertCloneStatement('a: return;'); |
| 1126 } | 712 } |
| 1127 | 713 |
| 1128 void test_visitLabeledStatement_multiple() { | 714 void test_visitLabeledStatement_multiple() { |
| 1129 _assertClone(AstFactory.labeledStatement( | 715 _assertCloneStatement('a: b: return;'); |
| 1130 [AstFactory.label2("a"), AstFactory.label2("b")], | |
| 1131 AstFactory.returnStatement())); | |
| 1132 } | 716 } |
| 1133 | 717 |
| 1134 void test_visitLabeledStatement_single() { | 718 void test_visitLabeledStatement_single() { |
| 1135 _assertClone(AstFactory.labeledStatement( | 719 _assertCloneStatement('a: return;'); |
| 1136 [AstFactory.label2("a")], AstFactory.returnStatement())); | |
| 1137 } | 720 } |
| 1138 | 721 |
| 1139 void test_visitLibraryDirective() { | 722 void test_visitLibraryDirective() { |
| 1140 _assertClone(AstFactory.libraryDirective2("l")); | 723 _assertCloneUnit('library l;'); |
| 1141 } | 724 } |
| 1142 | 725 |
| 1143 void test_visitLibraryDirective_withMetadata() { | 726 void test_visitLibraryDirective_withMetadata() { |
| 1144 LibraryDirective directive = AstFactory.libraryDirective2("l"); | 727 _assertCloneUnit('@deprecated library l;'); |
| 1145 directive.metadata | |
| 1146 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 1147 _assertClone(directive); | |
| 1148 } | 728 } |
| 1149 | 729 |
| 1150 void test_visitLibraryIdentifier_multiple() { | 730 void test_visitLibraryIdentifier_multiple() { |
| 1151 _assertClone(AstFactory.libraryIdentifier([ | 731 _assertCloneUnit('library a.b.c;'); |
| 1152 AstFactory.identifier3("a"), | |
| 1153 AstFactory.identifier3("b"), | |
| 1154 AstFactory.identifier3("c") | |
| 1155 ])); | |
| 1156 } | 732 } |
| 1157 | 733 |
| 1158 void test_visitLibraryIdentifier_single() { | 734 void test_visitLibraryIdentifier_single() { |
| 1159 _assertClone(AstFactory.libraryIdentifier([AstFactory.identifier3("a")])); | 735 _assertCloneUnit('library a;'); |
| 1160 } | 736 } |
| 1161 | 737 |
| 1162 void test_visitListLiteral_const() { | 738 void test_visitListLiteral_const() { |
| 1163 _assertClone(AstFactory.listLiteral2(Keyword.CONST, null)); | 739 _assertCloneExpression('const []'); |
| 1164 } | 740 } |
| 1165 | 741 |
| 1166 void test_visitListLiteral_empty() { | 742 void test_visitListLiteral_empty() { |
| 1167 _assertClone(AstFactory.listLiteral()); | 743 _assertCloneExpression('[]'); |
| 1168 } | 744 } |
| 1169 | 745 |
| 1170 void test_visitListLiteral_nonEmpty() { | 746 void test_visitListLiteral_nonEmpty() { |
| 1171 _assertClone(AstFactory.listLiteral([ | 747 _assertCloneExpression('[a, b, c]'); |
| 1172 AstFactory.identifier3("a"), | |
| 1173 AstFactory.identifier3("b"), | |
| 1174 AstFactory.identifier3("c") | |
| 1175 ])); | |
| 1176 } | 748 } |
| 1177 | 749 |
| 1178 void test_visitMapLiteral_const() { | 750 void test_visitMapLiteral_const() { |
| 1179 _assertClone(AstFactory.mapLiteral(Keyword.CONST, null)); | 751 _assertCloneExpression('const {}'); |
| 1180 } | 752 } |
| 1181 | 753 |
| 1182 void test_visitMapLiteral_empty() { | 754 void test_visitMapLiteral_empty() { |
| 1183 _assertClone(AstFactory.mapLiteral2()); | 755 _assertCloneExpression('{}'); |
| 1184 } | 756 } |
| 1185 | 757 |
| 1186 void test_visitMapLiteral_nonEmpty() { | 758 void test_visitMapLiteral_nonEmpty() { |
| 1187 _assertClone(AstFactory.mapLiteral2([ | 759 _assertCloneExpression('{a: a, b: b, c: c}'); |
| 1188 AstFactory.mapLiteralEntry("a", AstFactory.identifier3("a")), | |
| 1189 AstFactory.mapLiteralEntry("b", AstFactory.identifier3("b")), | |
| 1190 AstFactory.mapLiteralEntry("c", AstFactory.identifier3("c")) | |
| 1191 ])); | |
| 1192 } | |
| 1193 | |
| 1194 void test_visitMapLiteralEntry() { | |
| 1195 _assertClone(AstFactory.mapLiteralEntry("a", AstFactory.identifier3("b"))); | |
| 1196 } | 760 } |
| 1197 | 761 |
| 1198 void test_visitMethodDeclaration_external() { | 762 void test_visitMethodDeclaration_external() { |
| 1199 _assertClone(AstFactory.methodDeclaration(null, null, null, null, | 763 _assertCloneUnitMember('class C { external m(); }'); |
| 1200 AstFactory.identifier3("m"), AstFactory.formalParameterList())); | |
| 1201 } | 764 } |
| 1202 | 765 |
| 1203 void test_visitMethodDeclaration_external_returnType() { | 766 void test_visitMethodDeclaration_external_returnType() { |
| 1204 _assertClone(AstFactory.methodDeclaration( | 767 _assertCloneUnitMember('class C { T m(); }'); |
| 1205 null, | |
| 1206 AstFactory.typeName4("T"), | |
| 1207 null, | |
| 1208 null, | |
| 1209 AstFactory.identifier3("m"), | |
| 1210 AstFactory.formalParameterList())); | |
| 1211 } | 768 } |
| 1212 | 769 |
| 1213 void test_visitMethodDeclaration_getter() { | 770 void test_visitMethodDeclaration_getter() { |
| 1214 _assertClone(AstFactory.methodDeclaration2(null, null, Keyword.GET, null, | 771 _assertCloneUnitMember('class C { get m {} }'); |
| 1215 AstFactory.identifier3("m"), null, AstFactory.blockFunctionBody2())); | |
| 1216 } | 772 } |
| 1217 | 773 |
| 1218 void test_visitMethodDeclaration_getter_returnType() { | 774 void test_visitMethodDeclaration_getter_returnType() { |
| 1219 _assertClone(AstFactory.methodDeclaration2( | 775 _assertCloneUnitMember('class C { T get m {} }'); |
| 1220 null, | |
| 1221 AstFactory.typeName4("T"), | |
| 1222 Keyword.GET, | |
| 1223 null, | |
| 1224 AstFactory.identifier3("m"), | |
| 1225 null, | |
| 1226 AstFactory.blockFunctionBody2())); | |
| 1227 } | |
| 1228 | |
| 1229 void test_visitMethodDeclaration_getter_seturnType() { | |
| 1230 _assertClone(AstFactory.methodDeclaration2( | |
| 1231 null, | |
| 1232 AstFactory.typeName4("T"), | |
| 1233 Keyword.SET, | |
| 1234 null, | |
| 1235 AstFactory.identifier3("m"), | |
| 1236 AstFactory.formalParameterList( | |
| 1237 [AstFactory.simpleFormalParameter(Keyword.VAR, "v")]), | |
| 1238 AstFactory.blockFunctionBody2())); | |
| 1239 } | 776 } |
| 1240 | 777 |
| 1241 void test_visitMethodDeclaration_minimal() { | 778 void test_visitMethodDeclaration_minimal() { |
| 1242 _assertClone(AstFactory.methodDeclaration2( | 779 _assertCloneUnitMember('class C { m() {} }'); |
| 1243 null, | |
| 1244 null, | |
| 1245 null, | |
| 1246 null, | |
| 1247 AstFactory.identifier3("m"), | |
| 1248 AstFactory.formalParameterList(), | |
| 1249 AstFactory.blockFunctionBody2())); | |
| 1250 } | 780 } |
| 1251 | 781 |
| 1252 void test_visitMethodDeclaration_multipleParameters() { | 782 void test_visitMethodDeclaration_multipleParameters() { |
| 1253 _assertClone(AstFactory.methodDeclaration2( | 783 _assertCloneUnitMember('class C { m(var a, var b) {} }'); |
| 1254 null, | |
| 1255 null, | |
| 1256 null, | |
| 1257 null, | |
| 1258 AstFactory.identifier3("m"), | |
| 1259 AstFactory.formalParameterList([ | |
| 1260 AstFactory.simpleFormalParameter(Keyword.VAR, "a"), | |
| 1261 AstFactory.simpleFormalParameter(Keyword.VAR, "b") | |
| 1262 ]), | |
| 1263 AstFactory.blockFunctionBody2())); | |
| 1264 } | 784 } |
| 1265 | 785 |
| 1266 void test_visitMethodDeclaration_operator() { | 786 void test_visitMethodDeclaration_operator() { |
| 1267 _assertClone(AstFactory.methodDeclaration2( | 787 _assertCloneUnitMember('class C { operator+() {} }'); |
| 1268 null, | |
| 1269 null, | |
| 1270 null, | |
| 1271 Keyword.OPERATOR, | |
| 1272 AstFactory.identifier3("+"), | |
| 1273 AstFactory.formalParameterList(), | |
| 1274 AstFactory.blockFunctionBody2())); | |
| 1275 } | 788 } |
| 1276 | 789 |
| 1277 void test_visitMethodDeclaration_operator_returnType() { | 790 void test_visitMethodDeclaration_operator_returnType() { |
| 1278 _assertClone(AstFactory.methodDeclaration2( | 791 _assertCloneUnitMember('class C { T operator+() {} }'); |
| 1279 null, | |
| 1280 AstFactory.typeName4("T"), | |
| 1281 null, | |
| 1282 Keyword.OPERATOR, | |
| 1283 AstFactory.identifier3("+"), | |
| 1284 AstFactory.formalParameterList(), | |
| 1285 AstFactory.blockFunctionBody2())); | |
| 1286 } | 792 } |
| 1287 | 793 |
| 1288 void test_visitMethodDeclaration_returnType() { | 794 void test_visitMethodDeclaration_returnType() { |
| 1289 _assertClone(AstFactory.methodDeclaration2( | 795 _assertCloneUnitMember('class C { T m() {} }'); |
| 1290 null, | |
| 1291 AstFactory.typeName4("T"), | |
| 1292 null, | |
| 1293 null, | |
| 1294 AstFactory.identifier3("m"), | |
| 1295 AstFactory.formalParameterList(), | |
| 1296 AstFactory.blockFunctionBody2())); | |
| 1297 } | 796 } |
| 1298 | 797 |
| 1299 void test_visitMethodDeclaration_setter() { | 798 void test_visitMethodDeclaration_setter() { |
| 1300 _assertClone(AstFactory.methodDeclaration2( | 799 _assertCloneUnitMember('class C { set m(var v) {} }'); |
| 1301 null, | 800 } |
| 1302 null, | 801 |
| 1303 Keyword.SET, | 802 void test_visitMethodDeclaration_setter_returnType() { |
| 1304 null, | 803 _assertCloneUnitMember('class C { T set m(v) {} }'); |
| 1305 AstFactory.identifier3("m"), | |
| 1306 AstFactory.formalParameterList( | |
| 1307 [AstFactory.simpleFormalParameter(Keyword.VAR, "v")]), | |
| 1308 AstFactory.blockFunctionBody2())); | |
| 1309 } | 804 } |
| 1310 | 805 |
| 1311 void test_visitMethodDeclaration_static() { | 806 void test_visitMethodDeclaration_static() { |
| 1312 _assertClone(AstFactory.methodDeclaration2( | 807 _assertCloneUnitMember('class C { static m() {} }'); |
| 1313 Keyword.STATIC, | |
| 1314 null, | |
| 1315 null, | |
| 1316 null, | |
| 1317 AstFactory.identifier3("m"), | |
| 1318 AstFactory.formalParameterList(), | |
| 1319 AstFactory.blockFunctionBody2())); | |
| 1320 } | 808 } |
| 1321 | 809 |
| 1322 void test_visitMethodDeclaration_static_returnType() { | 810 void test_visitMethodDeclaration_static_returnType() { |
| 1323 _assertClone(AstFactory.methodDeclaration2( | 811 _assertCloneUnitMember('class C { static T m() {} }'); |
| 1324 Keyword.STATIC, | |
| 1325 AstFactory.typeName4("T"), | |
| 1326 null, | |
| 1327 null, | |
| 1328 AstFactory.identifier3("m"), | |
| 1329 AstFactory.formalParameterList(), | |
| 1330 AstFactory.blockFunctionBody2())); | |
| 1331 } | 812 } |
| 1332 | 813 |
| 1333 void test_visitMethodDeclaration_withMetadata() { | 814 void test_visitMethodDeclaration_withMetadata() { |
| 1334 MethodDeclaration declaration = AstFactory.methodDeclaration2( | 815 _assertCloneUnitMember('class C { @deprecated m() {} }'); |
| 1335 null, | |
| 1336 null, | |
| 1337 null, | |
| 1338 null, | |
| 1339 AstFactory.identifier3("m"), | |
| 1340 AstFactory.formalParameterList(), | |
| 1341 AstFactory.blockFunctionBody2()); | |
| 1342 declaration.metadata | |
| 1343 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 1344 _assertClone(declaration); | |
| 1345 } | 816 } |
| 1346 | 817 |
| 1347 void test_visitMethodInvocation_noTarget() { | 818 void test_visitMethodInvocation_noTarget() { |
| 1348 _assertClone(AstFactory.methodInvocation2("m")); | 819 _assertCloneExpression('m()'); |
| 1349 } | 820 } |
| 1350 | 821 |
| 1351 void test_visitMethodInvocation_target() { | 822 void test_visitMethodInvocation_target() { |
| 1352 _assertClone(AstFactory.methodInvocation(AstFactory.identifier3("t"), "m")); | 823 _assertCloneExpression('t.m()'); |
| 1353 } | 824 } |
| 1354 | 825 |
| 1355 void test_visitNamedExpression() { | 826 void test_visitNamedExpression() { |
| 1356 _assertClone(AstFactory.namedExpression2("a", AstFactory.identifier3("b"))); | 827 _assertCloneExpression('m(a: b)'); |
| 1357 } | |
| 1358 | |
| 1359 void test_visitNamedFormalParameter() { | |
| 1360 _assertClone(AstFactory.namedFormalParameter( | |
| 1361 AstFactory.simpleFormalParameter(Keyword.VAR, "a"), | |
| 1362 AstFactory.integer(0))); | |
| 1363 } | 828 } |
| 1364 | 829 |
| 1365 void test_visitNativeClause() { | 830 void test_visitNativeClause() { |
| 1366 _assertClone(AstFactory.nativeClause("code")); | 831 _assertCloneUnitMember('f() native "code";'); |
| 1367 } | 832 } |
| 1368 | 833 |
| 1369 void test_visitNativeFunctionBody() { | 834 void test_visitNativeFunctionBody() { |
| 1370 _assertClone(AstFactory.nativeFunctionBody("str")); | 835 _assertCloneUnitMember('f() native "str";'); |
| 1371 } | 836 } |
| 1372 | 837 |
| 1373 void test_visitNullLiteral() { | 838 void test_visitNullLiteral() { |
| 1374 _assertClone(AstFactory.nullLiteral()); | 839 _assertCloneExpression('null'); |
| 1375 } | 840 } |
| 1376 | 841 |
| 1377 void test_visitParenthesizedExpression() { | 842 void test_visitParenthesizedExpression() { |
| 1378 _assertClone( | 843 _assertCloneExpression('(a)'); |
| 1379 AstFactory.parenthesizedExpression(AstFactory.identifier3("a"))); | |
| 1380 } | 844 } |
| 1381 | 845 |
| 1382 void test_visitPartDirective() { | 846 void test_visitPartDirective() { |
| 1383 _assertClone(AstFactory.partDirective2("a.dart")); | 847 _assertCloneUnit('part "a.dart";'); |
| 1384 } | 848 } |
| 1385 | 849 |
| 1386 void test_visitPartDirective_withMetadata() { | 850 void test_visitPartDirective_withMetadata() { |
| 1387 PartDirective directive = AstFactory.partDirective2("a.dart"); | 851 _assertCloneUnit('@deprecated part "a.dart";'); |
| 1388 directive.metadata | |
| 1389 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 1390 _assertClone(directive); | |
| 1391 } | 852 } |
| 1392 | 853 |
| 1393 void test_visitPartOfDirective() { | 854 void test_visitPartOfDirective() { |
| 1394 _assertClone( | 855 _assertCloneUnit('part of l;'); |
| 1395 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["l"]))); | |
| 1396 } | 856 } |
| 1397 | 857 |
| 1398 void test_visitPartOfDirective_withMetadata() { | 858 void test_visitPartOfDirective_withMetadata() { |
| 1399 PartOfDirective directive = | 859 _assertCloneUnit('@deprecated part of l;'); |
| 1400 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["l"])); | |
| 1401 directive.metadata | |
| 1402 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 1403 _assertClone(directive); | |
| 1404 } | 860 } |
| 1405 | 861 |
| 1406 void test_visitPositionalFormalParameter() { | 862 void test_visitPositionalFormalParameter() { |
| 1407 _assertClone(AstFactory.positionalFormalParameter( | 863 _assertCloneUnitMember('main([var p = 0]) {}'); |
| 1408 AstFactory.simpleFormalParameter(Keyword.VAR, "a"), | |
| 1409 AstFactory.integer(0))); | |
| 1410 } | 864 } |
| 1411 | 865 |
| 1412 void test_visitPostfixExpression() { | 866 void test_visitPostfixExpression() { |
| 1413 _assertClone(AstFactory.postfixExpression( | 867 _assertCloneExpression('a++'); |
| 1414 AstFactory.identifier3("a"), TokenType.PLUS_PLUS)); | |
| 1415 } | 868 } |
| 1416 | 869 |
| 1417 void test_visitPrefixedIdentifier() { | 870 void test_visitPrefixedIdentifier() { |
| 1418 _assertClone(AstFactory.identifier5("a", "b")); | 871 _assertCloneExpression('a.b'); |
| 1419 } | 872 } |
| 1420 | 873 |
| 1421 void test_visitPrefixExpression() { | 874 void test_visitPrefixExpression() { |
| 1422 _assertClone(AstFactory.prefixExpression( | 875 _assertCloneExpression('-a'); |
| 1423 TokenType.MINUS, AstFactory.identifier3("a"))); | |
| 1424 } | 876 } |
| 1425 | 877 |
| 1426 void test_visitPropertyAccess() { | 878 void test_visitPropertyAccess() { |
| 1427 _assertClone(AstFactory.propertyAccess2(AstFactory.identifier3("a"), "b")); | 879 _assertCloneExpression('a.b.c'); |
| 1428 } | 880 } |
| 1429 | 881 |
| 1430 void test_visitRedirectingConstructorInvocation_named() { | 882 void test_visitRedirectingConstructorInvocation_named() { |
| 1431 _assertClone(AstFactory.redirectingConstructorInvocation2("c")); | 883 _assertCloneUnitMember('class A { factory A() = B.b; }'); |
| 1432 } | 884 } |
| 1433 | 885 |
| 1434 void test_visitRedirectingConstructorInvocation_unnamed() { | 886 void test_visitRedirectingConstructorInvocation_unnamed() { |
| 1435 _assertClone(AstFactory.redirectingConstructorInvocation()); | 887 _assertCloneUnitMember('class A { factory A() = B; }'); |
| 1436 } | 888 } |
| 1437 | 889 |
| 1438 void test_visitRethrowExpression() { | 890 void test_visitRethrowExpression() { |
| 1439 _assertClone(AstFactory.rethrowExpression()); | 891 _assertCloneExpression('rethrow'); |
| 1440 } | 892 } |
| 1441 | 893 |
| 1442 void test_visitReturnStatement_expression() { | 894 void test_visitReturnStatement_expression() { |
| 1443 _assertClone(AstFactory.returnStatement2(AstFactory.identifier3("a"))); | 895 _assertCloneStatement('return a;'); |
| 1444 } | 896 } |
| 1445 | 897 |
| 1446 void test_visitReturnStatement_noExpression() { | 898 void test_visitReturnStatement_noExpression() { |
| 1447 _assertClone(AstFactory.returnStatement()); | 899 _assertCloneStatement('return;'); |
| 1448 } | 900 } |
| 1449 | 901 |
| 1450 void test_visitScriptTag() { | 902 void test_visitScriptTag() { |
| 1451 String scriptTag = "!#/bin/dart.exe"; | 903 _assertCloneUnit('#!/bin/dart.exe'); |
| 1452 _assertClone(AstFactory.scriptTag(scriptTag)); | |
| 1453 } | 904 } |
| 1454 | 905 |
| 1455 void test_visitSimpleFormalParameter_keyword() { | 906 void test_visitSimpleFormalParameter_keyword() { |
| 1456 _assertClone(AstFactory.simpleFormalParameter(Keyword.VAR, "a")); | 907 _assertCloneUnitMember('main(var a) {}'); |
| 1457 } | 908 } |
| 1458 | 909 |
| 1459 void test_visitSimpleFormalParameter_keyword_type() { | 910 void test_visitSimpleFormalParameter_keyword_type() { |
| 1460 _assertClone(AstFactory.simpleFormalParameter2( | 911 _assertCloneUnitMember('main(final A a) {}'); |
| 1461 Keyword.FINAL, AstFactory.typeName4("A"), "a")); | |
| 1462 } | 912 } |
| 1463 | 913 |
| 1464 void test_visitSimpleFormalParameter_type() { | 914 void test_visitSimpleFormalParameter_type() { |
| 1465 _assertClone( | 915 _assertCloneUnitMember('main(A a) {}'); |
| 1466 AstFactory.simpleFormalParameter4(AstFactory.typeName4("A"), "a")); | |
| 1467 } | 916 } |
| 1468 | 917 |
| 1469 void test_visitSimpleIdentifier() { | 918 void test_visitSimpleIdentifier() { |
| 1470 _assertClone(AstFactory.identifier3("a")); | 919 _assertCloneExpression('a'); |
| 1471 } | 920 } |
| 1472 | 921 |
| 1473 void test_visitSimpleStringLiteral() { | 922 void test_visitSimpleStringLiteral() { |
| 1474 _assertClone(AstFactory.string2("a")); | 923 _assertCloneExpression("'a'"); |
| 1475 } | 924 } |
| 1476 | 925 |
| 1477 void test_visitStringInterpolation() { | 926 void test_visitStringInterpolation() { |
| 1478 _assertClone(AstFactory.string([ | 927 _assertCloneExpression(r"'a${e}b'"); |
| 1479 AstFactory.interpolationString("'a", "a"), | |
| 1480 AstFactory.interpolationExpression(AstFactory.identifier3("e")), | |
| 1481 AstFactory.interpolationString("b'", "b") | |
| 1482 ])); | |
| 1483 } | 928 } |
| 1484 | 929 |
| 1485 void test_visitSuperConstructorInvocation() { | 930 void test_visitSuperConstructorInvocation() { |
| 1486 _assertClone(AstFactory.superConstructorInvocation()); | 931 _assertCloneUnitMember('class C { C() : super(); }'); |
| 1487 } | 932 } |
| 1488 | 933 |
| 1489 void test_visitSuperConstructorInvocation_named() { | 934 void test_visitSuperConstructorInvocation_named() { |
| 1490 _assertClone(AstFactory.superConstructorInvocation2("c")); | 935 _assertCloneUnitMember('class C { C() : super.c(); }'); |
| 1491 } | 936 } |
| 1492 | 937 |
| 1493 void test_visitSuperExpression() { | 938 void test_visitSuperExpression() { |
| 1494 _assertClone(AstFactory.superExpression()); | 939 _assertCloneUnitMember('class C { m() { super.m(); } }'); |
| 1495 } | 940 } |
| 1496 | 941 |
| 1497 void test_visitSwitchCase_multipleLabels() { | 942 void test_visitSwitchCase_multipleLabels() { |
| 1498 _assertClone(AstFactory.switchCase2( | 943 _assertCloneStatement('switch (v) {l1: l2: case a: {} }'); |
| 1499 [AstFactory.label2("l1"), AstFactory.label2("l2")], | |
| 1500 AstFactory.identifier3("a"), | |
| 1501 [AstFactory.block()])); | |
| 1502 } | 944 } |
| 1503 | 945 |
| 1504 void test_visitSwitchCase_multipleStatements() { | 946 void test_visitSwitchCase_multipleStatements() { |
| 1505 _assertClone(AstFactory.switchCase( | 947 _assertCloneStatement('switch (v) { case a: {} {} }'); |
| 1506 AstFactory.identifier3("a"), [AstFactory.block(), AstFactory.block()])); | |
| 1507 } | 948 } |
| 1508 | 949 |
| 1509 void test_visitSwitchCase_noLabels() { | 950 void test_visitSwitchCase_noLabels() { |
| 1510 _assertClone(AstFactory | 951 _assertCloneStatement('switch (v) { case a: {} }'); |
| 1511 .switchCase(AstFactory.identifier3("a"), [AstFactory.block()])); | |
| 1512 } | 952 } |
| 1513 | 953 |
| 1514 void test_visitSwitchCase_singleLabel() { | 954 void test_visitSwitchCase_singleLabel() { |
| 1515 _assertClone(AstFactory.switchCase2([AstFactory.label2("l1")], | 955 _assertCloneStatement('switch (v) { l1: case a: {} }'); |
| 1516 AstFactory.identifier3("a"), [AstFactory.block()])); | |
| 1517 } | 956 } |
| 1518 | 957 |
| 1519 void test_visitSwitchDefault_multipleLabels() { | 958 void test_visitSwitchDefault_multipleLabels() { |
| 1520 _assertClone(AstFactory.switchDefault( | 959 _assertCloneStatement('switch (v) { l1: l2: default: {} }'); |
| 1521 [AstFactory.label2("l1"), AstFactory.label2("l2")], | |
| 1522 [AstFactory.block()])); | |
| 1523 } | 960 } |
| 1524 | 961 |
| 1525 void test_visitSwitchDefault_multipleStatements() { | 962 void test_visitSwitchDefault_multipleStatements() { |
| 1526 _assertClone( | 963 _assertCloneStatement('switch (v) { default: {} {} }'); |
| 1527 AstFactory.switchDefault2([AstFactory.block(), AstFactory.block()])); | |
| 1528 } | 964 } |
| 1529 | 965 |
| 1530 void test_visitSwitchDefault_noLabels() { | 966 void test_visitSwitchDefault_noLabels() { |
| 1531 _assertClone(AstFactory.switchDefault2([AstFactory.block()])); | 967 _assertCloneStatement('switch (v) { default: {} }'); |
| 1532 } | 968 } |
| 1533 | 969 |
| 1534 void test_visitSwitchDefault_singleLabel() { | 970 void test_visitSwitchDefault_singleLabel() { |
| 1535 _assertClone(AstFactory | 971 _assertCloneStatement('switch (v) { l1: default: {} }'); |
| 1536 .switchDefault([AstFactory.label2("l1")], [AstFactory.block()])); | |
| 1537 } | 972 } |
| 1538 | 973 |
| 1539 void test_visitSwitchStatement() { | 974 void test_visitSwitchStatement() { |
| 1540 _assertClone(AstFactory.switchStatement(AstFactory.identifier3("a"), [ | 975 _assertCloneStatement('switch (a) { case b: {} default: {} }'); |
| 1541 AstFactory.switchCase(AstFactory.string2("b"), [AstFactory.block()]), | |
| 1542 AstFactory.switchDefault2([AstFactory.block()]) | |
| 1543 ])); | |
| 1544 } | 976 } |
| 1545 | 977 |
| 1546 void test_visitSymbolLiteral_multiple() { | 978 void test_visitSymbolLiteral_multiple() { |
| 1547 _assertClone(AstFactory.symbolLiteral(["a", "b", "c"])); | 979 _assertCloneExpression('#a.b.c'); |
| 1548 } | 980 } |
| 1549 | 981 |
| 1550 void test_visitSymbolLiteral_single() { | 982 void test_visitSymbolLiteral_single() { |
| 1551 _assertClone(AstFactory.symbolLiteral(["a"])); | 983 _assertCloneExpression('#a'); |
| 1552 } | 984 } |
| 1553 | 985 |
| 1554 void test_visitThisExpression() { | 986 void test_visitThisExpression() { |
| 1555 _assertClone(AstFactory.thisExpression()); | 987 _assertCloneExpression('this'); |
| 1556 } | 988 } |
| 1557 | 989 |
| 1558 void test_visitThrowStatement() { | 990 void test_visitThrowStatement() { |
| 1559 _assertClone(AstFactory.throwExpression2(AstFactory.identifier3("e"))); | 991 _assertCloneStatement('throw e;'); |
| 1560 } | 992 } |
| 1561 | 993 |
| 1562 void test_visitTopLevelVariableDeclaration_multiple() { | 994 void test_visitTopLevelVariableDeclaration_multiple() { |
| 1563 _assertClone(AstFactory.topLevelVariableDeclaration2( | 995 _assertCloneUnitMember('var a;'); |
| 1564 Keyword.VAR, [AstFactory.variableDeclaration("a")])); | |
| 1565 } | 996 } |
| 1566 | 997 |
| 1567 void test_visitTopLevelVariableDeclaration_single() { | 998 void test_visitTopLevelVariableDeclaration_single() { |
| 1568 _assertClone(AstFactory.topLevelVariableDeclaration2(Keyword.VAR, [ | 999 _assertCloneUnitMember('var a, b;'); |
| 1569 AstFactory.variableDeclaration("a"), | |
| 1570 AstFactory.variableDeclaration("b") | |
| 1571 ])); | |
| 1572 } | 1000 } |
| 1573 | 1001 |
| 1574 void test_visitTryStatement_catch() { | 1002 void test_visitTryStatement_catch() { |
| 1575 _assertClone(AstFactory.tryStatement2(AstFactory.block(), | 1003 _assertCloneStatement('try {} on E {}'); |
| 1576 [AstFactory.catchClause3(AstFactory.typeName4("E"))])); | |
| 1577 } | 1004 } |
| 1578 | 1005 |
| 1579 void test_visitTryStatement_catches() { | 1006 void test_visitTryStatement_catches() { |
| 1580 _assertClone(AstFactory.tryStatement2(AstFactory.block(), [ | 1007 _assertCloneStatement('try {} on E {} on F {}'); |
| 1581 AstFactory.catchClause3(AstFactory.typeName4("E")), | |
| 1582 AstFactory.catchClause3(AstFactory.typeName4("F")) | |
| 1583 ])); | |
| 1584 } | 1008 } |
| 1585 | 1009 |
| 1586 void test_visitTryStatement_catchFinally() { | 1010 void test_visitTryStatement_catchFinally() { |
| 1587 _assertClone(AstFactory.tryStatement3( | 1011 _assertCloneStatement('try {} on E {} finally {}'); |
| 1588 AstFactory.block(), | |
| 1589 [AstFactory.catchClause3(AstFactory.typeName4("E"))], | |
| 1590 AstFactory.block())); | |
| 1591 } | 1012 } |
| 1592 | 1013 |
| 1593 void test_visitTryStatement_finally() { | 1014 void test_visitTryStatement_finally() { |
| 1594 _assertClone( | 1015 _assertCloneStatement('try {} finally {}'); |
| 1595 AstFactory.tryStatement(AstFactory.block(), AstFactory.block())); | |
| 1596 } | |
| 1597 | |
| 1598 void test_visitTypeArgumentList_multiple() { | |
| 1599 _assertClone(AstFactory.typeArgumentList( | |
| 1600 [AstFactory.typeName4("E"), AstFactory.typeName4("F")])); | |
| 1601 } | |
| 1602 | |
| 1603 void test_visitTypeArgumentList_single() { | |
| 1604 _assertClone(AstFactory.typeArgumentList([AstFactory.typeName4("E")])); | |
| 1605 } | 1016 } |
| 1606 | 1017 |
| 1607 void test_visitTypeName_multipleArgs() { | 1018 void test_visitTypeName_multipleArgs() { |
| 1608 _assertClone(AstFactory.typeName4( | 1019 _assertCloneExpression('new C<D, E>()'); |
| 1609 "C", [AstFactory.typeName4("D"), AstFactory.typeName4("E")])); | |
| 1610 } | 1020 } |
| 1611 | 1021 |
| 1612 void test_visitTypeName_nestedArg() { | 1022 void test_visitTypeName_nestedArg() { |
| 1613 _assertClone(AstFactory.typeName4("C", [ | 1023 _assertCloneExpression('new C<D<E>>()'); |
| 1614 AstFactory.typeName4("D", [AstFactory.typeName4("E")]) | |
| 1615 ])); | |
| 1616 } | 1024 } |
| 1617 | 1025 |
| 1618 void test_visitTypeName_noArgs() { | 1026 void test_visitTypeName_noArgs() { |
| 1619 _assertClone(AstFactory.typeName4("C")); | 1027 _assertCloneExpression('new C()'); |
| 1620 } | 1028 } |
| 1621 | 1029 |
| 1622 void test_visitTypeName_singleArg() { | 1030 void test_visitTypeName_singleArg() { |
| 1623 _assertClone(AstFactory.typeName4("C", [AstFactory.typeName4("D")])); | 1031 _assertCloneExpression('new C<D>()'); |
| 1624 } | 1032 } |
| 1625 | 1033 |
| 1626 void test_visitTypeParameter_withExtends() { | 1034 void test_visitTypeParameter_withExtends() { |
| 1627 _assertClone(AstFactory.typeParameter2("E", AstFactory.typeName4("C"))); | 1035 _assertCloneUnitMember('class A<E extends C> {}'); |
| 1628 } | 1036 } |
| 1629 | 1037 |
| 1630 void test_visitTypeParameter_withMetadata() { | 1038 void test_visitTypeParameter_withMetadata() { |
| 1631 TypeParameter parameter = AstFactory.typeParameter("E"); | 1039 _assertCloneUnitMember('class A<@deprecated E> {}'); |
| 1632 parameter.metadata | |
| 1633 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 1634 _assertClone(parameter); | |
| 1635 } | 1040 } |
| 1636 | 1041 |
| 1637 void test_visitTypeParameter_withoutExtends() { | 1042 void test_visitTypeParameter_withoutExtends() { |
| 1638 _assertClone(AstFactory.typeParameter("E")); | 1043 _assertCloneUnitMember('class A<E> {}'); |
| 1639 } | 1044 } |
| 1640 | 1045 |
| 1641 void test_visitTypeParameterList_multiple() { | 1046 void test_visitTypeParameterList_multiple() { |
| 1642 _assertClone(AstFactory.typeParameterList(["E", "F"])); | 1047 _assertCloneUnitMember('class A<E, F> {}'); |
| 1643 } | 1048 } |
| 1644 | 1049 |
| 1645 void test_visitTypeParameterList_single() { | 1050 void test_visitTypeParameterList_single() { |
| 1646 _assertClone(AstFactory.typeParameterList(["E"])); | 1051 _assertCloneUnitMember('class A<E> {}'); |
| 1647 } | 1052 } |
| 1648 | 1053 |
| 1649 void test_visitVariableDeclaration_initialized() { | 1054 void test_visitVariableDeclaration_initialized() { |
| 1650 _assertClone( | 1055 _assertCloneStatement('var a = b;'); |
| 1651 AstFactory.variableDeclaration2("a", AstFactory.identifier3("b"))); | |
| 1652 } | 1056 } |
| 1653 | 1057 |
| 1654 void test_visitVariableDeclaration_uninitialized() { | 1058 void test_visitVariableDeclaration_uninitialized() { |
| 1655 _assertClone(AstFactory.variableDeclaration("a")); | 1059 _assertCloneStatement('var a;'); |
| 1656 } | 1060 } |
| 1657 | 1061 |
| 1658 void test_visitVariableDeclarationList_const_type() { | 1062 void test_visitVariableDeclarationList_const_type() { |
| 1659 _assertClone(AstFactory.variableDeclarationList( | 1063 _assertCloneStatement('const C a, b;'); |
| 1660 Keyword.CONST, AstFactory.typeName4("C"), [ | |
| 1661 AstFactory.variableDeclaration("a"), | |
| 1662 AstFactory.variableDeclaration("b") | |
| 1663 ])); | |
| 1664 } | 1064 } |
| 1665 | 1065 |
| 1666 void test_visitVariableDeclarationList_final_noType() { | 1066 void test_visitVariableDeclarationList_final_noType() { |
| 1667 _assertClone(AstFactory.variableDeclarationList2(Keyword.FINAL, [ | 1067 _assertCloneStatement('final a, b;'); |
| 1668 AstFactory.variableDeclaration("a"), | |
| 1669 AstFactory.variableDeclaration("b") | |
| 1670 ])); | |
| 1671 } | 1068 } |
| 1672 | 1069 |
| 1673 void test_visitVariableDeclarationList_final_withMetadata() { | 1070 void test_visitVariableDeclarationList_final_withMetadata() { |
| 1674 VariableDeclarationList declarationList = AstFactory | 1071 _assertCloneStatement('@deprecated final a, b;'); |
| 1675 .variableDeclarationList2(Keyword.FINAL, [ | |
| 1676 AstFactory.variableDeclaration("a"), | |
| 1677 AstFactory.variableDeclaration("b") | |
| 1678 ]); | |
| 1679 declarationList.metadata | |
| 1680 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); | |
| 1681 _assertClone(declarationList); | |
| 1682 } | 1072 } |
| 1683 | 1073 |
| 1684 void test_visitVariableDeclarationList_type() { | 1074 void test_visitVariableDeclarationList_type() { |
| 1685 _assertClone(AstFactory.variableDeclarationList( | 1075 _assertCloneStatement('C a, b;'); |
| 1686 null, AstFactory.typeName4("C"), [ | |
| 1687 AstFactory.variableDeclaration("a"), | |
| 1688 AstFactory.variableDeclaration("b") | |
| 1689 ])); | |
| 1690 } | 1076 } |
| 1691 | 1077 |
| 1692 void test_visitVariableDeclarationList_var() { | 1078 void test_visitVariableDeclarationList_var() { |
| 1693 _assertClone(AstFactory.variableDeclarationList2(Keyword.VAR, [ | 1079 _assertCloneStatement('var a, b;'); |
| 1694 AstFactory.variableDeclaration("a"), | |
| 1695 AstFactory.variableDeclaration("b") | |
| 1696 ])); | |
| 1697 } | 1080 } |
| 1698 | 1081 |
| 1699 void test_visitVariableDeclarationStatement() { | 1082 void test_visitVariableDeclarationStatement() { |
| 1700 _assertClone(AstFactory.variableDeclarationStatement(null, | 1083 _assertCloneStatement('C c;'); |
| 1701 AstFactory.typeName4("C"), [AstFactory.variableDeclaration("c")])); | |
| 1702 } | 1084 } |
| 1703 | 1085 |
| 1704 void test_visitWhileStatement() { | 1086 void test_visitWhileStatement() { |
| 1705 _assertClone(AstFactory.whileStatement( | 1087 _assertCloneStatement('while (c) {}'); |
| 1706 AstFactory.identifier3("c"), AstFactory.block())); | |
| 1707 } | 1088 } |
| 1708 | 1089 |
| 1709 void test_visitWithClause_multiple() { | 1090 void test_visitWithClause_multiple() { |
| 1710 _assertClone(AstFactory.withClause([ | 1091 _assertCloneUnitMember('class X extends Y with A, B, C {}'); |
| 1711 AstFactory.typeName4("A"), | |
| 1712 AstFactory.typeName4("B"), | |
| 1713 AstFactory.typeName4("C") | |
| 1714 ])); | |
| 1715 } | 1092 } |
| 1716 | 1093 |
| 1717 void test_visitWithClause_single() { | 1094 void test_visitWithClause_single() { |
| 1718 _assertClone(AstFactory.withClause([AstFactory.typeName4("A")])); | 1095 _assertCloneUnitMember('class X extends Y with A {}'); |
| 1719 } | 1096 } |
| 1720 | 1097 |
| 1721 void test_visitYieldStatement() { | 1098 void test_visitYieldStatement() { |
| 1722 _assertClone(AstFactory.yieldStatement(AstFactory.identifier3("A"))); | 1099 _assertCloneUnitMember('main() async* { yield 42; }'); |
| 1723 } | 1100 } |
| 1724 | 1101 |
| 1725 /** | 1102 /** |
| 1726 * Assert that an `AstCloner` will produce the expected AST structure when | 1103 * Assert that an `AstCloner` will produce the expected AST structure when |
| 1727 * visiting the given [node]. | 1104 * visiting the given [node]. |
| 1728 * | 1105 * |
| 1729 * @param node the AST node being visited to produce the cloned structure | 1106 * @param node the AST node being visited to produce the cloned structure |
| 1730 * @throws AFE if the visitor does not produce the expected source for the giv
en node | 1107 * @throws AFE if the visitor does not produce the expected source for the giv
en node |
| 1731 */ | 1108 */ |
| 1732 void _assertClone(AstNode node) { | 1109 void _assertClone(AstNode node) { |
| 1733 AstNode clone = node.accept(new AstCloner()); | 1110 { |
| 1734 AstCloneComparator comparitor = new AstCloneComparator(false); | 1111 AstNode clone = node.accept(new AstCloner()); |
| 1735 if (!comparitor.isEqualNodes(node, clone)) { | 1112 AstCloneComparator comparator = new AstCloneComparator(false); |
| 1736 fail("Failed to clone ${node.runtimeType.toString()}"); | 1113 if (!comparator.isEqualNodes(node, clone)) { |
| 1114 fail("Failed to clone ${node.runtimeType.toString()}"); |
| 1115 } |
| 1116 _assertEqualTokens(clone, node); |
| 1737 } | 1117 } |
| 1118 { |
| 1119 AstNode clone = node.accept(new AstCloner(true)); |
| 1120 AstCloneComparator comparator = new AstCloneComparator(true); |
| 1121 if (!comparator.isEqualNodes(node, clone)) { |
| 1122 fail("Failed to clone ${node.runtimeType.toString()}"); |
| 1123 } |
| 1124 _assertEqualTokens(clone, node); |
| 1125 } |
| 1126 } |
| 1738 | 1127 |
| 1739 clone = node.accept(new AstCloner(true)); | 1128 void _assertCloneExpression(String code) { |
| 1740 comparitor = new AstCloneComparator(true); | 1129 AstNode node = _parseExpression(code); |
| 1741 if (!comparitor.isEqualNodes(node, clone)) { | 1130 _assertClone(node); |
| 1742 fail("Failed to clone ${node.runtimeType.toString()}"); | 1131 } |
| 1132 |
| 1133 void _assertCloneStatement(String code) { |
| 1134 AstNode node = _parseStatement(code); |
| 1135 _assertClone(node); |
| 1136 } |
| 1137 |
| 1138 void _assertCloneUnit(String code) { |
| 1139 AstNode node = _parseUnit(code); |
| 1140 _assertClone(node); |
| 1141 } |
| 1142 |
| 1143 void _assertCloneUnitMember(String code) { |
| 1144 AstNode node = _parseUnitMember(code); |
| 1145 _assertClone(node); |
| 1146 } |
| 1147 |
| 1148 Expression _parseExpression(String code) { |
| 1149 CompilationUnit unit = _parseUnit('var v = $code;'); |
| 1150 TopLevelVariableDeclaration decl = unit.declarations.single; |
| 1151 return decl.variables.variables.single.initializer; |
| 1152 } |
| 1153 |
| 1154 Statement _parseStatement(String code) { |
| 1155 CompilationUnit unit = _parseUnit('main() { $code }'); |
| 1156 FunctionDeclaration main = unit.declarations.single; |
| 1157 BlockFunctionBody body = main.functionExpression.body; |
| 1158 return body.block.statements.single; |
| 1159 } |
| 1160 |
| 1161 CompilationUnit _parseUnit(String code) { |
| 1162 GatheringErrorListener listener = new GatheringErrorListener(); |
| 1163 CharSequenceReader reader = new CharSequenceReader(code); |
| 1164 Scanner scanner = new Scanner(null, reader, listener); |
| 1165 Token token = scanner.tokenize(); |
| 1166 Parser parser = new Parser(null, listener); |
| 1167 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 1168 expect(unit, isNotNull); |
| 1169 listener.assertNoErrors(); |
| 1170 return unit; |
| 1171 } |
| 1172 |
| 1173 CompilationUnitMember _parseUnitMember(String code) { |
| 1174 CompilationUnit unit = _parseUnit(code); |
| 1175 return unit.declarations.single; |
| 1176 } |
| 1177 |
| 1178 static void _assertEqualToken(Token clone, Token original) { |
| 1179 expect(clone.type, original.type); |
| 1180 expect(clone.offset, original.offset); |
| 1181 expect(clone.length, original.length); |
| 1182 expect(clone.lexeme, original.lexeme); |
| 1183 } |
| 1184 |
| 1185 static void _assertEqualTokens(AstNode cloneNode, AstNode originalNode) { |
| 1186 Token clone = cloneNode.beginToken; |
| 1187 Token original = originalNode.beginToken; |
| 1188 Token stopOriginalToken = originalNode.endToken.next; |
| 1189 Token skipCloneComment = null; |
| 1190 Token skipOriginalComment = null; |
| 1191 while (original != stopOriginalToken) { |
| 1192 expect(clone, isNotNull); |
| 1193 _assertEqualToken(clone, original); |
| 1194 // comments |
| 1195 { |
| 1196 Token cloneComment = clone.precedingComments; |
| 1197 Token originalComment = original.precedingComments; |
| 1198 if (cloneComment != skipCloneComment && |
| 1199 originalComment != skipOriginalComment) { |
| 1200 while (true) { |
| 1201 if (originalComment == null) { |
| 1202 expect(cloneComment, isNull); |
| 1203 break; |
| 1204 } |
| 1205 expect(cloneComment, isNotNull); |
| 1206 _assertEqualToken(cloneComment, originalComment); |
| 1207 cloneComment = cloneComment.next; |
| 1208 originalComment = originalComment.next; |
| 1209 } |
| 1210 } |
| 1211 } |
| 1212 // next tokens |
| 1213 if (original is CommentToken) { |
| 1214 expect(clone, new isInstanceOf<CommentToken>()); |
| 1215 skipOriginalComment = original; |
| 1216 skipCloneComment = clone; |
| 1217 original = (original as CommentToken).parent; |
| 1218 clone = (clone as CommentToken).parent; |
| 1219 } else { |
| 1220 clone = clone.next; |
| 1221 original = original.next; |
| 1222 } |
| 1743 } | 1223 } |
| 1744 } | 1224 } |
| 1745 } | 1225 } |
| 1746 | 1226 |
| 1747 @reflectiveTest | 1227 @reflectiveTest |
| 1748 class BooleanArrayTest { | 1228 class BooleanArrayTest { |
| 1749 void test_get_negative() { | 1229 void test_get_negative() { |
| 1750 try { | 1230 try { |
| 1751 BooleanArray.get(0, -1); | 1231 BooleanArray.get(0, -1); |
| 1752 fail("Expected "); | 1232 fail("Expected "); |
| (...skipping 3098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4851 } | 4331 } |
| 4852 | 4332 |
| 4853 void test_get_added() { | 4333 void test_get_added() { |
| 4854 TokenMap tokenMap = new TokenMap(); | 4334 TokenMap tokenMap = new TokenMap(); |
| 4855 Token key = TokenFactory.tokenFromType(TokenType.AT); | 4335 Token key = TokenFactory.tokenFromType(TokenType.AT); |
| 4856 Token value = TokenFactory.tokenFromType(TokenType.AT); | 4336 Token value = TokenFactory.tokenFromType(TokenType.AT); |
| 4857 tokenMap.put(key, value); | 4337 tokenMap.put(key, value); |
| 4858 expect(tokenMap.get(key), same(value)); | 4338 expect(tokenMap.get(key), same(value)); |
| 4859 } | 4339 } |
| 4860 } | 4340 } |
| OLD | NEW |