OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.test.src.dart.ast.utilities_test; | 5 library analyzer.test.src.dart.ast.utilities_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
(...skipping 11 matching lines...) Expand all Loading... |
22 import '../../../generated/parser_test.dart' show ParserTestCase; | 22 import '../../../generated/parser_test.dart' show ParserTestCase; |
23 import '../../../generated/test_support.dart'; | 23 import '../../../generated/test_support.dart'; |
24 | 24 |
25 main() { | 25 main() { |
26 defineReflectiveSuite(() { | 26 defineReflectiveSuite(() { |
27 defineReflectiveTests(ConstantEvaluatorTest); | 27 defineReflectiveTests(ConstantEvaluatorTest); |
28 defineReflectiveTests(NodeLocatorTest); | 28 defineReflectiveTests(NodeLocatorTest); |
29 defineReflectiveTests(NodeLocator2Test); | 29 defineReflectiveTests(NodeLocator2Test); |
30 defineReflectiveTests(ResolutionCopierTest); | 30 defineReflectiveTests(ResolutionCopierTest); |
31 defineReflectiveTests(ToSourceVisitorTest); | 31 defineReflectiveTests(ToSourceVisitorTest); |
| 32 defineReflectiveTests(ToSourceVisitor2Test); |
32 }); | 33 }); |
33 } | 34 } |
34 | 35 |
35 @reflectiveTest | 36 @reflectiveTest |
36 class ConstantEvaluatorTest extends ParserTestCase { | 37 class ConstantEvaluatorTest extends ParserTestCase { |
37 void fail_constructor() { | 38 void fail_constructor() { |
38 Object value = _getConstantValue("?"); | 39 Object value = _getConstantValue("?"); |
39 expect(value, null); | 40 expect(value, null); |
40 } | 41 } |
41 | 42 |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 for (int i = 0; i < fromTypeArguments.length; i++) { | 1103 for (int i = 0; i < fromTypeArguments.length; i++) { |
1103 TypeName toArgument = fromTypeArguments[i]; | 1104 TypeName toArgument = fromTypeArguments[i]; |
1104 TypeName fromArgument = toTypeArguments[i]; | 1105 TypeName fromArgument = toTypeArguments[i]; |
1105 expect(toArgument.type, same(fromArgument.type)); | 1106 expect(toArgument.type, same(fromArgument.type)); |
1106 } | 1107 } |
1107 } | 1108 } |
1108 } | 1109 } |
1109 } | 1110 } |
1110 | 1111 |
1111 @reflectiveTest | 1112 @reflectiveTest |
| 1113 class ToSourceVisitor2Test extends EngineTestCase { |
| 1114 void test_visitAdjacentStrings() { |
| 1115 _assertSource( |
| 1116 "'a' 'b'", |
| 1117 AstFactory.adjacentStrings( |
| 1118 [AstFactory.string2("a"), AstFactory.string2("b")])); |
| 1119 } |
| 1120 |
| 1121 void test_visitAnnotation_constant() { |
| 1122 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A"))); |
| 1123 } |
| 1124 |
| 1125 void test_visitAnnotation_constructor() { |
| 1126 _assertSource( |
| 1127 "@A.c()", |
| 1128 AstFactory.annotation2(AstFactory.identifier3("A"), |
| 1129 AstFactory.identifier3("c"), AstFactory.argumentList())); |
| 1130 } |
| 1131 |
| 1132 void test_visitArgumentList() { |
| 1133 _assertSource( |
| 1134 "(a, b)", |
| 1135 AstFactory.argumentList( |
| 1136 [AstFactory.identifier3("a"), AstFactory.identifier3("b")])); |
| 1137 } |
| 1138 |
| 1139 void test_visitAsExpression() { |
| 1140 _assertSource( |
| 1141 "e as T", |
| 1142 AstFactory.asExpression( |
| 1143 AstFactory.identifier3("e"), AstFactory.typeName4("T"))); |
| 1144 } |
| 1145 |
| 1146 void test_visitAssertStatement() { |
| 1147 _assertSource( |
| 1148 "assert (a);", AstFactory.assertStatement(AstFactory.identifier3("a"))); |
| 1149 } |
| 1150 |
| 1151 void test_visitAssertStatement_withMessage() { |
| 1152 _assertSource( |
| 1153 "assert (a, b);", |
| 1154 AstFactory.assertStatement( |
| 1155 AstFactory.identifier3("a"), AstFactory.identifier3('b'))); |
| 1156 } |
| 1157 |
| 1158 void test_visitAssignmentExpression() { |
| 1159 _assertSource( |
| 1160 "a = b", |
| 1161 AstFactory.assignmentExpression(AstFactory.identifier3("a"), |
| 1162 TokenType.EQ, AstFactory.identifier3("b"))); |
| 1163 } |
| 1164 |
| 1165 void test_visitAwaitExpression() { |
| 1166 _assertSource( |
| 1167 "await e", AstFactory.awaitExpression(AstFactory.identifier3("e"))); |
| 1168 } |
| 1169 |
| 1170 void test_visitBinaryExpression() { |
| 1171 _assertSource( |
| 1172 "a + b", |
| 1173 AstFactory.binaryExpression(AstFactory.identifier3("a"), TokenType.PLUS, |
| 1174 AstFactory.identifier3("b"))); |
| 1175 } |
| 1176 |
| 1177 void test_visitBlock_empty() { |
| 1178 _assertSource("{}", AstFactory.block()); |
| 1179 } |
| 1180 |
| 1181 void test_visitBlock_nonEmpty() { |
| 1182 _assertSource( |
| 1183 "{break; break;}", |
| 1184 AstFactory |
| 1185 .block([AstFactory.breakStatement(), AstFactory.breakStatement()])); |
| 1186 } |
| 1187 |
| 1188 void test_visitBlockFunctionBody_async() { |
| 1189 _assertSource("async {}", AstFactory.asyncBlockFunctionBody()); |
| 1190 } |
| 1191 |
| 1192 void test_visitBlockFunctionBody_async_star() { |
| 1193 _assertSource("async* {}", AstFactory.asyncGeneratorBlockFunctionBody()); |
| 1194 } |
| 1195 |
| 1196 void test_visitBlockFunctionBody_simple() { |
| 1197 _assertSource("{}", AstFactory.blockFunctionBody2()); |
| 1198 } |
| 1199 |
| 1200 void test_visitBlockFunctionBody_sync() { |
| 1201 _assertSource("sync {}", AstFactory.syncBlockFunctionBody()); |
| 1202 } |
| 1203 |
| 1204 void test_visitBlockFunctionBody_sync_star() { |
| 1205 _assertSource("sync* {}", AstFactory.syncGeneratorBlockFunctionBody()); |
| 1206 } |
| 1207 |
| 1208 void test_visitBooleanLiteral_false() { |
| 1209 _assertSource("false", AstFactory.booleanLiteral(false)); |
| 1210 } |
| 1211 |
| 1212 void test_visitBooleanLiteral_true() { |
| 1213 _assertSource("true", AstFactory.booleanLiteral(true)); |
| 1214 } |
| 1215 |
| 1216 void test_visitBreakStatement_label() { |
| 1217 _assertSource("break l;", AstFactory.breakStatement2("l")); |
| 1218 } |
| 1219 |
| 1220 void test_visitBreakStatement_noLabel() { |
| 1221 _assertSource("break;", AstFactory.breakStatement()); |
| 1222 } |
| 1223 |
| 1224 void test_visitCascadeExpression_field() { |
| 1225 _assertSource( |
| 1226 "a..b..c", |
| 1227 AstFactory.cascadeExpression(AstFactory.identifier3("a"), [ |
| 1228 AstFactory.cascadedPropertyAccess("b"), |
| 1229 AstFactory.cascadedPropertyAccess("c") |
| 1230 ])); |
| 1231 } |
| 1232 |
| 1233 void test_visitCascadeExpression_index() { |
| 1234 _assertSource( |
| 1235 "a..[0]..[1]", |
| 1236 AstFactory.cascadeExpression(AstFactory.identifier3("a"), [ |
| 1237 AstFactory.cascadedIndexExpression(AstFactory.integer(0)), |
| 1238 AstFactory.cascadedIndexExpression(AstFactory.integer(1)) |
| 1239 ])); |
| 1240 } |
| 1241 |
| 1242 void test_visitCascadeExpression_method() { |
| 1243 _assertSource( |
| 1244 "a..b()..c()", |
| 1245 AstFactory.cascadeExpression(AstFactory.identifier3("a"), [ |
| 1246 AstFactory.cascadedMethodInvocation("b"), |
| 1247 AstFactory.cascadedMethodInvocation("c") |
| 1248 ])); |
| 1249 } |
| 1250 |
| 1251 void test_visitCatchClause_catch_noStack() { |
| 1252 _assertSource("catch (e) {}", AstFactory.catchClause("e")); |
| 1253 } |
| 1254 |
| 1255 void test_visitCatchClause_catch_stack() { |
| 1256 _assertSource("catch (e, s) {}", AstFactory.catchClause2("e", "s")); |
| 1257 } |
| 1258 |
| 1259 void test_visitCatchClause_on() { |
| 1260 _assertSource( |
| 1261 "on E {}", AstFactory.catchClause3(AstFactory.typeName4("E"))); |
| 1262 } |
| 1263 |
| 1264 void test_visitCatchClause_on_catch() { |
| 1265 _assertSource("on E catch (e) {}", |
| 1266 AstFactory.catchClause4(AstFactory.typeName4("E"), "e")); |
| 1267 } |
| 1268 |
| 1269 void test_visitClassDeclaration_abstract() { |
| 1270 _assertSource( |
| 1271 "abstract class C {}", |
| 1272 AstFactory.classDeclaration( |
| 1273 Keyword.ABSTRACT, "C", null, null, null, null)); |
| 1274 } |
| 1275 |
| 1276 void test_visitClassDeclaration_empty() { |
| 1277 _assertSource("class C {}", |
| 1278 AstFactory.classDeclaration(null, "C", null, null, null, null)); |
| 1279 } |
| 1280 |
| 1281 void test_visitClassDeclaration_extends() { |
| 1282 _assertSource( |
| 1283 "class C extends A {}", |
| 1284 AstFactory.classDeclaration(null, "C", null, |
| 1285 AstFactory.extendsClause(AstFactory.typeName4("A")), null, null)); |
| 1286 } |
| 1287 |
| 1288 void test_visitClassDeclaration_extends_implements() { |
| 1289 _assertSource( |
| 1290 "class C extends A implements B {}", |
| 1291 AstFactory.classDeclaration( |
| 1292 null, |
| 1293 "C", |
| 1294 null, |
| 1295 AstFactory.extendsClause(AstFactory.typeName4("A")), |
| 1296 null, |
| 1297 AstFactory.implementsClause([AstFactory.typeName4("B")]))); |
| 1298 } |
| 1299 |
| 1300 void test_visitClassDeclaration_extends_with() { |
| 1301 _assertSource( |
| 1302 "class C extends A with M {}", |
| 1303 AstFactory.classDeclaration( |
| 1304 null, |
| 1305 "C", |
| 1306 null, |
| 1307 AstFactory.extendsClause(AstFactory.typeName4("A")), |
| 1308 AstFactory.withClause([AstFactory.typeName4("M")]), |
| 1309 null)); |
| 1310 } |
| 1311 |
| 1312 void test_visitClassDeclaration_extends_with_implements() { |
| 1313 _assertSource( |
| 1314 "class C extends A with M implements B {}", |
| 1315 AstFactory.classDeclaration( |
| 1316 null, |
| 1317 "C", |
| 1318 null, |
| 1319 AstFactory.extendsClause(AstFactory.typeName4("A")), |
| 1320 AstFactory.withClause([AstFactory.typeName4("M")]), |
| 1321 AstFactory.implementsClause([AstFactory.typeName4("B")]))); |
| 1322 } |
| 1323 |
| 1324 void test_visitClassDeclaration_implements() { |
| 1325 _assertSource( |
| 1326 "class C implements B {}", |
| 1327 AstFactory.classDeclaration(null, "C", null, null, null, |
| 1328 AstFactory.implementsClause([AstFactory.typeName4("B")]))); |
| 1329 } |
| 1330 |
| 1331 void test_visitClassDeclaration_multipleMember() { |
| 1332 _assertSource( |
| 1333 "class C {var a; var b;}", |
| 1334 AstFactory.classDeclaration(null, "C", null, null, null, null, [ |
| 1335 AstFactory.fieldDeclaration2( |
| 1336 false, Keyword.VAR, [AstFactory.variableDeclaration("a")]), |
| 1337 AstFactory.fieldDeclaration2( |
| 1338 false, Keyword.VAR, [AstFactory.variableDeclaration("b")]) |
| 1339 ])); |
| 1340 } |
| 1341 |
| 1342 void test_visitClassDeclaration_parameters() { |
| 1343 _assertSource( |
| 1344 "class C<E> {}", |
| 1345 AstFactory.classDeclaration( |
| 1346 null, "C", AstFactory.typeParameterList(["E"]), null, null, null)); |
| 1347 } |
| 1348 |
| 1349 void test_visitClassDeclaration_parameters_extends() { |
| 1350 _assertSource( |
| 1351 "class C<E> extends A {}", |
| 1352 AstFactory.classDeclaration( |
| 1353 null, |
| 1354 "C", |
| 1355 AstFactory.typeParameterList(["E"]), |
| 1356 AstFactory.extendsClause(AstFactory.typeName4("A")), |
| 1357 null, |
| 1358 null)); |
| 1359 } |
| 1360 |
| 1361 void test_visitClassDeclaration_parameters_extends_implements() { |
| 1362 _assertSource( |
| 1363 "class C<E> extends A implements B {}", |
| 1364 AstFactory.classDeclaration( |
| 1365 null, |
| 1366 "C", |
| 1367 AstFactory.typeParameterList(["E"]), |
| 1368 AstFactory.extendsClause(AstFactory.typeName4("A")), |
| 1369 null, |
| 1370 AstFactory.implementsClause([AstFactory.typeName4("B")]))); |
| 1371 } |
| 1372 |
| 1373 void test_visitClassDeclaration_parameters_extends_with() { |
| 1374 _assertSource( |
| 1375 "class C<E> extends A with M {}", |
| 1376 AstFactory.classDeclaration( |
| 1377 null, |
| 1378 "C", |
| 1379 AstFactory.typeParameterList(["E"]), |
| 1380 AstFactory.extendsClause(AstFactory.typeName4("A")), |
| 1381 AstFactory.withClause([AstFactory.typeName4("M")]), |
| 1382 null)); |
| 1383 } |
| 1384 |
| 1385 void test_visitClassDeclaration_parameters_extends_with_implements() { |
| 1386 _assertSource( |
| 1387 "class C<E> extends A with M implements B {}", |
| 1388 AstFactory.classDeclaration( |
| 1389 null, |
| 1390 "C", |
| 1391 AstFactory.typeParameterList(["E"]), |
| 1392 AstFactory.extendsClause(AstFactory.typeName4("A")), |
| 1393 AstFactory.withClause([AstFactory.typeName4("M")]), |
| 1394 AstFactory.implementsClause([AstFactory.typeName4("B")]))); |
| 1395 } |
| 1396 |
| 1397 void test_visitClassDeclaration_parameters_implements() { |
| 1398 _assertSource( |
| 1399 "class C<E> implements B {}", |
| 1400 AstFactory.classDeclaration( |
| 1401 null, |
| 1402 "C", |
| 1403 AstFactory.typeParameterList(["E"]), |
| 1404 null, |
| 1405 null, |
| 1406 AstFactory.implementsClause([AstFactory.typeName4("B")]))); |
| 1407 } |
| 1408 |
| 1409 void test_visitClassDeclaration_singleMember() { |
| 1410 _assertSource( |
| 1411 "class C {var a;}", |
| 1412 AstFactory.classDeclaration(null, "C", null, null, null, null, [ |
| 1413 AstFactory.fieldDeclaration2( |
| 1414 false, Keyword.VAR, [AstFactory.variableDeclaration("a")]) |
| 1415 ])); |
| 1416 } |
| 1417 |
| 1418 void test_visitClassDeclaration_withMetadata() { |
| 1419 ClassDeclaration declaration = |
| 1420 AstFactory.classDeclaration(null, "C", null, null, null, null); |
| 1421 declaration.metadata |
| 1422 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 1423 _assertSource("@deprecated class C {}", declaration); |
| 1424 } |
| 1425 |
| 1426 void test_visitClassTypeAlias_abstract() { |
| 1427 _assertSource( |
| 1428 "abstract class C = S with M1;", |
| 1429 AstFactory.classTypeAlias( |
| 1430 "C", |
| 1431 null, |
| 1432 Keyword.ABSTRACT, |
| 1433 AstFactory.typeName4("S"), |
| 1434 AstFactory.withClause([AstFactory.typeName4("M1")]), |
| 1435 null)); |
| 1436 } |
| 1437 |
| 1438 void test_visitClassTypeAlias_abstract_implements() { |
| 1439 _assertSource( |
| 1440 "abstract class C = S with M1 implements I;", |
| 1441 AstFactory.classTypeAlias( |
| 1442 "C", |
| 1443 null, |
| 1444 Keyword.ABSTRACT, |
| 1445 AstFactory.typeName4("S"), |
| 1446 AstFactory.withClause([AstFactory.typeName4("M1")]), |
| 1447 AstFactory.implementsClause([AstFactory.typeName4("I")]))); |
| 1448 } |
| 1449 |
| 1450 void test_visitClassTypeAlias_generic() { |
| 1451 _assertSource( |
| 1452 "class C<E> = S<E> with M1<E>;", |
| 1453 AstFactory.classTypeAlias( |
| 1454 "C", |
| 1455 AstFactory.typeParameterList(["E"]), |
| 1456 null, |
| 1457 AstFactory.typeName4("S", [AstFactory.typeName4("E")]), |
| 1458 AstFactory.withClause([ |
| 1459 AstFactory.typeName4("M1", [AstFactory.typeName4("E")]) |
| 1460 ]), |
| 1461 null)); |
| 1462 } |
| 1463 |
| 1464 void test_visitClassTypeAlias_implements() { |
| 1465 _assertSource( |
| 1466 "class C = S with M1 implements I;", |
| 1467 AstFactory.classTypeAlias( |
| 1468 "C", |
| 1469 null, |
| 1470 null, |
| 1471 AstFactory.typeName4("S"), |
| 1472 AstFactory.withClause([AstFactory.typeName4("M1")]), |
| 1473 AstFactory.implementsClause([AstFactory.typeName4("I")]))); |
| 1474 } |
| 1475 |
| 1476 void test_visitClassTypeAlias_minimal() { |
| 1477 _assertSource( |
| 1478 "class C = S with M1;", |
| 1479 AstFactory.classTypeAlias("C", null, null, AstFactory.typeName4("S"), |
| 1480 AstFactory.withClause([AstFactory.typeName4("M1")]), null)); |
| 1481 } |
| 1482 |
| 1483 void test_visitClassTypeAlias_parameters_abstract() { |
| 1484 _assertSource( |
| 1485 "abstract class C<E> = S with M1;", |
| 1486 AstFactory.classTypeAlias( |
| 1487 "C", |
| 1488 AstFactory.typeParameterList(["E"]), |
| 1489 Keyword.ABSTRACT, |
| 1490 AstFactory.typeName4("S"), |
| 1491 AstFactory.withClause([AstFactory.typeName4("M1")]), |
| 1492 null)); |
| 1493 } |
| 1494 |
| 1495 void test_visitClassTypeAlias_parameters_abstract_implements() { |
| 1496 _assertSource( |
| 1497 "abstract class C<E> = S with M1 implements I;", |
| 1498 AstFactory.classTypeAlias( |
| 1499 "C", |
| 1500 AstFactory.typeParameterList(["E"]), |
| 1501 Keyword.ABSTRACT, |
| 1502 AstFactory.typeName4("S"), |
| 1503 AstFactory.withClause([AstFactory.typeName4("M1")]), |
| 1504 AstFactory.implementsClause([AstFactory.typeName4("I")]))); |
| 1505 } |
| 1506 |
| 1507 void test_visitClassTypeAlias_parameters_implements() { |
| 1508 _assertSource( |
| 1509 "class C<E> = S with M1 implements I;", |
| 1510 AstFactory.classTypeAlias( |
| 1511 "C", |
| 1512 AstFactory.typeParameterList(["E"]), |
| 1513 null, |
| 1514 AstFactory.typeName4("S"), |
| 1515 AstFactory.withClause([AstFactory.typeName4("M1")]), |
| 1516 AstFactory.implementsClause([AstFactory.typeName4("I")]))); |
| 1517 } |
| 1518 |
| 1519 void test_visitClassTypeAlias_withMetadata() { |
| 1520 ClassTypeAlias declaration = AstFactory.classTypeAlias( |
| 1521 "C", |
| 1522 null, |
| 1523 null, |
| 1524 AstFactory.typeName4("S"), |
| 1525 AstFactory.withClause([AstFactory.typeName4("M1")]), |
| 1526 null); |
| 1527 declaration.metadata |
| 1528 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 1529 _assertSource("@deprecated class C = S with M1;", declaration); |
| 1530 } |
| 1531 |
| 1532 void test_visitComment() { |
| 1533 _assertSource( |
| 1534 "", |
| 1535 Comment.createBlockComment( |
| 1536 <Token>[TokenFactory.tokenFromString("/* comment */")])); |
| 1537 } |
| 1538 |
| 1539 void test_visitCommentReference() { |
| 1540 _assertSource("", new CommentReference(null, AstFactory.identifier3("a"))); |
| 1541 } |
| 1542 |
| 1543 void test_visitCompilationUnit_declaration() { |
| 1544 _assertSource( |
| 1545 "var a;", |
| 1546 AstFactory.compilationUnit2([ |
| 1547 AstFactory.topLevelVariableDeclaration2( |
| 1548 Keyword.VAR, [AstFactory.variableDeclaration("a")]) |
| 1549 ])); |
| 1550 } |
| 1551 |
| 1552 void test_visitCompilationUnit_directive() { |
| 1553 _assertSource("library l;", |
| 1554 AstFactory.compilationUnit3([AstFactory.libraryDirective2("l")])); |
| 1555 } |
| 1556 |
| 1557 void test_visitCompilationUnit_directive_declaration() { |
| 1558 _assertSource( |
| 1559 "library l; var a;", |
| 1560 AstFactory.compilationUnit4([ |
| 1561 AstFactory.libraryDirective2("l") |
| 1562 ], [ |
| 1563 AstFactory.topLevelVariableDeclaration2( |
| 1564 Keyword.VAR, [AstFactory.variableDeclaration("a")]) |
| 1565 ])); |
| 1566 } |
| 1567 |
| 1568 void test_visitCompilationUnit_empty() { |
| 1569 _assertSource("", AstFactory.compilationUnit()); |
| 1570 } |
| 1571 |
| 1572 void test_visitCompilationUnit_script() { |
| 1573 _assertSource( |
| 1574 "!#/bin/dartvm", AstFactory.compilationUnit5("!#/bin/dartvm")); |
| 1575 } |
| 1576 |
| 1577 void test_visitCompilationUnit_script_declaration() { |
| 1578 _assertSource( |
| 1579 "!#/bin/dartvm var a;", |
| 1580 AstFactory.compilationUnit6("!#/bin/dartvm", [ |
| 1581 AstFactory.topLevelVariableDeclaration2( |
| 1582 Keyword.VAR, [AstFactory.variableDeclaration("a")]) |
| 1583 ])); |
| 1584 } |
| 1585 |
| 1586 void test_visitCompilationUnit_script_directive() { |
| 1587 _assertSource( |
| 1588 "!#/bin/dartvm library l;", |
| 1589 AstFactory.compilationUnit7( |
| 1590 "!#/bin/dartvm", [AstFactory.libraryDirective2("l")])); |
| 1591 } |
| 1592 |
| 1593 void test_visitCompilationUnit_script_directives_declarations() { |
| 1594 _assertSource( |
| 1595 "!#/bin/dartvm library l; var a;", |
| 1596 AstFactory.compilationUnit8("!#/bin/dartvm", [ |
| 1597 AstFactory.libraryDirective2("l") |
| 1598 ], [ |
| 1599 AstFactory.topLevelVariableDeclaration2( |
| 1600 Keyword.VAR, [AstFactory.variableDeclaration("a")]) |
| 1601 ])); |
| 1602 } |
| 1603 |
| 1604 void test_visitConditionalExpression() { |
| 1605 _assertSource( |
| 1606 "a ? b : c", |
| 1607 AstFactory.conditionalExpression(AstFactory.identifier3("a"), |
| 1608 AstFactory.identifier3("b"), AstFactory.identifier3("c"))); |
| 1609 } |
| 1610 |
| 1611 void test_visitConstructorDeclaration_const() { |
| 1612 _assertSource( |
| 1613 "const C() {}", |
| 1614 AstFactory.constructorDeclaration2( |
| 1615 Keyword.CONST, |
| 1616 null, |
| 1617 AstFactory.identifier3("C"), |
| 1618 null, |
| 1619 AstFactory.formalParameterList(), |
| 1620 null, |
| 1621 AstFactory.blockFunctionBody2())); |
| 1622 } |
| 1623 |
| 1624 void test_visitConstructorDeclaration_external() { |
| 1625 _assertSource( |
| 1626 "external C();", |
| 1627 AstFactory.constructorDeclaration(AstFactory.identifier3("C"), null, |
| 1628 AstFactory.formalParameterList(), null)); |
| 1629 } |
| 1630 |
| 1631 void test_visitConstructorDeclaration_minimal() { |
| 1632 _assertSource( |
| 1633 "C() {}", |
| 1634 AstFactory.constructorDeclaration2( |
| 1635 null, |
| 1636 null, |
| 1637 AstFactory.identifier3("C"), |
| 1638 null, |
| 1639 AstFactory.formalParameterList(), |
| 1640 null, |
| 1641 AstFactory.blockFunctionBody2())); |
| 1642 } |
| 1643 |
| 1644 void test_visitConstructorDeclaration_multipleInitializers() { |
| 1645 _assertSource( |
| 1646 "C() : a = b, c = d {}", |
| 1647 AstFactory.constructorDeclaration2( |
| 1648 null, |
| 1649 null, |
| 1650 AstFactory.identifier3("C"), |
| 1651 null, |
| 1652 AstFactory.formalParameterList(), |
| 1653 [ |
| 1654 AstFactory.constructorFieldInitializer( |
| 1655 false, "a", AstFactory.identifier3("b")), |
| 1656 AstFactory.constructorFieldInitializer( |
| 1657 false, "c", AstFactory.identifier3("d")) |
| 1658 ], |
| 1659 AstFactory.blockFunctionBody2())); |
| 1660 } |
| 1661 |
| 1662 void test_visitConstructorDeclaration_multipleParameters() { |
| 1663 _assertSource( |
| 1664 "C(var a, var b) {}", |
| 1665 AstFactory.constructorDeclaration2( |
| 1666 null, |
| 1667 null, |
| 1668 AstFactory.identifier3("C"), |
| 1669 null, |
| 1670 AstFactory.formalParameterList([ |
| 1671 AstFactory.simpleFormalParameter(Keyword.VAR, "a"), |
| 1672 AstFactory.simpleFormalParameter(Keyword.VAR, "b") |
| 1673 ]), |
| 1674 null, |
| 1675 AstFactory.blockFunctionBody2())); |
| 1676 } |
| 1677 |
| 1678 void test_visitConstructorDeclaration_named() { |
| 1679 _assertSource( |
| 1680 "C.m() {}", |
| 1681 AstFactory.constructorDeclaration2( |
| 1682 null, |
| 1683 null, |
| 1684 AstFactory.identifier3("C"), |
| 1685 "m", |
| 1686 AstFactory.formalParameterList(), |
| 1687 null, |
| 1688 AstFactory.blockFunctionBody2())); |
| 1689 } |
| 1690 |
| 1691 void test_visitConstructorDeclaration_singleInitializer() { |
| 1692 _assertSource( |
| 1693 "C() : a = b {}", |
| 1694 AstFactory.constructorDeclaration2( |
| 1695 null, |
| 1696 null, |
| 1697 AstFactory.identifier3("C"), |
| 1698 null, |
| 1699 AstFactory.formalParameterList(), |
| 1700 [ |
| 1701 AstFactory.constructorFieldInitializer( |
| 1702 false, "a", AstFactory.identifier3("b")) |
| 1703 ], |
| 1704 AstFactory.blockFunctionBody2())); |
| 1705 } |
| 1706 |
| 1707 void test_visitConstructorDeclaration_withMetadata() { |
| 1708 ConstructorDeclaration declaration = AstFactory.constructorDeclaration2( |
| 1709 null, |
| 1710 null, |
| 1711 AstFactory.identifier3("C"), |
| 1712 null, |
| 1713 AstFactory.formalParameterList(), |
| 1714 null, |
| 1715 AstFactory.blockFunctionBody2()); |
| 1716 declaration.metadata |
| 1717 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 1718 _assertSource("@deprecated C() {}", declaration); |
| 1719 } |
| 1720 |
| 1721 void test_visitConstructorFieldInitializer_withoutThis() { |
| 1722 _assertSource( |
| 1723 "a = b", |
| 1724 AstFactory.constructorFieldInitializer( |
| 1725 false, "a", AstFactory.identifier3("b"))); |
| 1726 } |
| 1727 |
| 1728 void test_visitConstructorFieldInitializer_withThis() { |
| 1729 _assertSource( |
| 1730 "this.a = b", |
| 1731 AstFactory.constructorFieldInitializer( |
| 1732 true, "a", AstFactory.identifier3("b"))); |
| 1733 } |
| 1734 |
| 1735 void test_visitConstructorName_named_prefix() { |
| 1736 _assertSource("p.C.n", |
| 1737 AstFactory.constructorName(AstFactory.typeName4("p.C.n"), null)); |
| 1738 } |
| 1739 |
| 1740 void test_visitConstructorName_unnamed_noPrefix() { |
| 1741 _assertSource( |
| 1742 "C", AstFactory.constructorName(AstFactory.typeName4("C"), null)); |
| 1743 } |
| 1744 |
| 1745 void test_visitConstructorName_unnamed_prefix() { |
| 1746 _assertSource( |
| 1747 "p.C", |
| 1748 AstFactory.constructorName( |
| 1749 AstFactory.typeName3(AstFactory.identifier5("p", "C")), null)); |
| 1750 } |
| 1751 |
| 1752 void test_visitContinueStatement_label() { |
| 1753 _assertSource("continue l;", AstFactory.continueStatement("l")); |
| 1754 } |
| 1755 |
| 1756 void test_visitContinueStatement_noLabel() { |
| 1757 _assertSource("continue;", AstFactory.continueStatement()); |
| 1758 } |
| 1759 |
| 1760 void test_visitDefaultFormalParameter_annotation() { |
| 1761 DefaultFormalParameter parameter = AstFactory.positionalFormalParameter( |
| 1762 AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0)); |
| 1763 parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A"))); |
| 1764 _assertSource('@A p = 0', parameter); |
| 1765 } |
| 1766 |
| 1767 void test_visitDefaultFormalParameter_named_noValue() { |
| 1768 _assertSource( |
| 1769 "p", |
| 1770 AstFactory.namedFormalParameter( |
| 1771 AstFactory.simpleFormalParameter3("p"), null)); |
| 1772 } |
| 1773 |
| 1774 void test_visitDefaultFormalParameter_named_value() { |
| 1775 _assertSource( |
| 1776 "p : 0", |
| 1777 AstFactory.namedFormalParameter( |
| 1778 AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0))); |
| 1779 } |
| 1780 |
| 1781 void test_visitDefaultFormalParameter_positional_noValue() { |
| 1782 _assertSource( |
| 1783 "p", |
| 1784 AstFactory.positionalFormalParameter( |
| 1785 AstFactory.simpleFormalParameter3("p"), null)); |
| 1786 } |
| 1787 |
| 1788 void test_visitDefaultFormalParameter_positional_value() { |
| 1789 _assertSource( |
| 1790 "p = 0", |
| 1791 AstFactory.positionalFormalParameter( |
| 1792 AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0))); |
| 1793 } |
| 1794 |
| 1795 void test_visitDoStatement() { |
| 1796 _assertSource( |
| 1797 "do {} while (c);", |
| 1798 AstFactory.doStatement( |
| 1799 AstFactory.block(), AstFactory.identifier3("c"))); |
| 1800 } |
| 1801 |
| 1802 void test_visitDoubleLiteral() { |
| 1803 _assertSource("4.2", AstFactory.doubleLiteral(4.2)); |
| 1804 } |
| 1805 |
| 1806 void test_visitEmptyFunctionBody() { |
| 1807 _assertSource(";", AstFactory.emptyFunctionBody()); |
| 1808 } |
| 1809 |
| 1810 void test_visitEmptyStatement() { |
| 1811 _assertSource(";", AstFactory.emptyStatement()); |
| 1812 } |
| 1813 |
| 1814 void test_visitEnumDeclaration_multiple() { |
| 1815 _assertSource( |
| 1816 "enum E {ONE, TWO}", AstFactory.enumDeclaration2("E", ["ONE", "TWO"])); |
| 1817 } |
| 1818 |
| 1819 void test_visitEnumDeclaration_single() { |
| 1820 _assertSource("enum E {ONE}", AstFactory.enumDeclaration2("E", ["ONE"])); |
| 1821 } |
| 1822 |
| 1823 void test_visitExportDirective_combinator() { |
| 1824 _assertSource( |
| 1825 "export 'a.dart' show A;", |
| 1826 AstFactory.exportDirective2("a.dart", [ |
| 1827 AstFactory.showCombinator([AstFactory.identifier3("A")]) |
| 1828 ])); |
| 1829 } |
| 1830 |
| 1831 void test_visitExportDirective_combinators() { |
| 1832 _assertSource( |
| 1833 "export 'a.dart' show A hide B;", |
| 1834 AstFactory.exportDirective2("a.dart", [ |
| 1835 AstFactory.showCombinator([AstFactory.identifier3("A")]), |
| 1836 AstFactory.hideCombinator([AstFactory.identifier3("B")]) |
| 1837 ])); |
| 1838 } |
| 1839 |
| 1840 void test_visitExportDirective_minimal() { |
| 1841 _assertSource("export 'a.dart';", AstFactory.exportDirective2("a.dart")); |
| 1842 } |
| 1843 |
| 1844 void test_visitExportDirective_withMetadata() { |
| 1845 ExportDirective directive = AstFactory.exportDirective2("a.dart"); |
| 1846 directive.metadata |
| 1847 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 1848 _assertSource("@deprecated export 'a.dart';", directive); |
| 1849 } |
| 1850 |
| 1851 void test_visitExpressionFunctionBody_async() { |
| 1852 _assertSource("async => a;", |
| 1853 AstFactory.asyncExpressionFunctionBody(AstFactory.identifier3("a"))); |
| 1854 } |
| 1855 |
| 1856 void test_visitExpressionFunctionBody_simple() { |
| 1857 _assertSource("=> a;", |
| 1858 AstFactory.expressionFunctionBody(AstFactory.identifier3("a"))); |
| 1859 } |
| 1860 |
| 1861 void test_visitExpressionStatement() { |
| 1862 _assertSource( |
| 1863 "a;", AstFactory.expressionStatement(AstFactory.identifier3("a"))); |
| 1864 } |
| 1865 |
| 1866 void test_visitExtendsClause() { |
| 1867 _assertSource( |
| 1868 "extends C", AstFactory.extendsClause(AstFactory.typeName4("C"))); |
| 1869 } |
| 1870 |
| 1871 void test_visitFieldDeclaration_instance() { |
| 1872 _assertSource( |
| 1873 "var a;", |
| 1874 AstFactory.fieldDeclaration2( |
| 1875 false, Keyword.VAR, [AstFactory.variableDeclaration("a")])); |
| 1876 } |
| 1877 |
| 1878 void test_visitFieldDeclaration_static() { |
| 1879 _assertSource( |
| 1880 "static var a;", |
| 1881 AstFactory.fieldDeclaration2( |
| 1882 true, Keyword.VAR, [AstFactory.variableDeclaration("a")])); |
| 1883 } |
| 1884 |
| 1885 void test_visitFieldDeclaration_withMetadata() { |
| 1886 FieldDeclaration declaration = AstFactory.fieldDeclaration2( |
| 1887 false, Keyword.VAR, [AstFactory.variableDeclaration("a")]); |
| 1888 declaration.metadata |
| 1889 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 1890 _assertSource("@deprecated var a;", declaration); |
| 1891 } |
| 1892 |
| 1893 void test_visitFieldFormalParameter_annotation() { |
| 1894 FieldFormalParameter parameter = AstFactory.fieldFormalParameter2('f'); |
| 1895 parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A"))); |
| 1896 _assertSource('@A this.f', parameter); |
| 1897 } |
| 1898 |
| 1899 void test_visitFieldFormalParameter_functionTyped() { |
| 1900 _assertSource( |
| 1901 "A this.a(b)", |
| 1902 AstFactory.fieldFormalParameter( |
| 1903 null, |
| 1904 AstFactory.typeName4("A"), |
| 1905 "a", |
| 1906 AstFactory.formalParameterList( |
| 1907 [AstFactory.simpleFormalParameter3("b")]))); |
| 1908 } |
| 1909 |
| 1910 void test_visitFieldFormalParameter_functionTyped_typeParameters() { |
| 1911 _assertSource( |
| 1912 "A this.a<E, F>(b)", |
| 1913 new FieldFormalParameter( |
| 1914 null, |
| 1915 null, |
| 1916 null, |
| 1917 AstFactory.typeName4('A'), |
| 1918 TokenFactory.tokenFromKeyword(Keyword.THIS), |
| 1919 TokenFactory.tokenFromType(TokenType.PERIOD), |
| 1920 AstFactory.identifier3('a'), |
| 1921 AstFactory.typeParameterList(['E', 'F']), |
| 1922 AstFactory.formalParameterList( |
| 1923 [AstFactory.simpleFormalParameter3("b")]))); |
| 1924 } |
| 1925 |
| 1926 void test_visitFieldFormalParameter_keyword() { |
| 1927 _assertSource( |
| 1928 "var this.a", AstFactory.fieldFormalParameter(Keyword.VAR, null, "a")); |
| 1929 } |
| 1930 |
| 1931 void test_visitFieldFormalParameter_keywordAndType() { |
| 1932 _assertSource( |
| 1933 "final A this.a", |
| 1934 AstFactory.fieldFormalParameter( |
| 1935 Keyword.FINAL, AstFactory.typeName4("A"), "a")); |
| 1936 } |
| 1937 |
| 1938 void test_visitFieldFormalParameter_type() { |
| 1939 _assertSource("A this.a", |
| 1940 AstFactory.fieldFormalParameter(null, AstFactory.typeName4("A"), "a")); |
| 1941 } |
| 1942 |
| 1943 void test_visitForEachStatement_declared() { |
| 1944 _assertSource( |
| 1945 "for (var a in b) {}", |
| 1946 AstFactory.forEachStatement(AstFactory.declaredIdentifier3("a"), |
| 1947 AstFactory.identifier3("b"), AstFactory.block())); |
| 1948 } |
| 1949 |
| 1950 void test_visitForEachStatement_variable() { |
| 1951 _assertSource( |
| 1952 "for (a in b) {}", |
| 1953 new ForEachStatement.withReference( |
| 1954 null, |
| 1955 TokenFactory.tokenFromKeyword(Keyword.FOR), |
| 1956 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), |
| 1957 AstFactory.identifier3("a"), |
| 1958 TokenFactory.tokenFromKeyword(Keyword.IN), |
| 1959 AstFactory.identifier3("b"), |
| 1960 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), |
| 1961 AstFactory.block())); |
| 1962 } |
| 1963 |
| 1964 void test_visitForEachStatement_variable_await() { |
| 1965 _assertSource( |
| 1966 "await for (a in b) {}", |
| 1967 new ForEachStatement.withReference( |
| 1968 TokenFactory.tokenFromString("await"), |
| 1969 TokenFactory.tokenFromKeyword(Keyword.FOR), |
| 1970 TokenFactory.tokenFromType(TokenType.OPEN_PAREN), |
| 1971 AstFactory.identifier3("a"), |
| 1972 TokenFactory.tokenFromKeyword(Keyword.IN), |
| 1973 AstFactory.identifier3("b"), |
| 1974 TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), |
| 1975 AstFactory.block())); |
| 1976 } |
| 1977 |
| 1978 void test_visitFormalParameterList_empty() { |
| 1979 _assertSource("()", AstFactory.formalParameterList()); |
| 1980 } |
| 1981 |
| 1982 void test_visitFormalParameterList_n() { |
| 1983 _assertSource( |
| 1984 "({a : 0})", |
| 1985 AstFactory.formalParameterList([ |
| 1986 AstFactory.namedFormalParameter( |
| 1987 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)) |
| 1988 ])); |
| 1989 } |
| 1990 |
| 1991 void test_visitFormalParameterList_nn() { |
| 1992 _assertSource( |
| 1993 "({a : 0, b : 1})", |
| 1994 AstFactory.formalParameterList([ |
| 1995 AstFactory.namedFormalParameter( |
| 1996 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)), |
| 1997 AstFactory.namedFormalParameter( |
| 1998 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)) |
| 1999 ])); |
| 2000 } |
| 2001 |
| 2002 void test_visitFormalParameterList_p() { |
| 2003 _assertSource( |
| 2004 "([a = 0])", |
| 2005 AstFactory.formalParameterList([ |
| 2006 AstFactory.positionalFormalParameter( |
| 2007 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)) |
| 2008 ])); |
| 2009 } |
| 2010 |
| 2011 void test_visitFormalParameterList_pp() { |
| 2012 _assertSource( |
| 2013 "([a = 0, b = 1])", |
| 2014 AstFactory.formalParameterList([ |
| 2015 AstFactory.positionalFormalParameter( |
| 2016 AstFactory.simpleFormalParameter3("a"), AstFactory.integer(0)), |
| 2017 AstFactory.positionalFormalParameter( |
| 2018 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)) |
| 2019 ])); |
| 2020 } |
| 2021 |
| 2022 void test_visitFormalParameterList_r() { |
| 2023 _assertSource( |
| 2024 "(a)", |
| 2025 AstFactory |
| 2026 .formalParameterList([AstFactory.simpleFormalParameter3("a")])); |
| 2027 } |
| 2028 |
| 2029 void test_visitFormalParameterList_rn() { |
| 2030 _assertSource( |
| 2031 "(a, {b : 1})", |
| 2032 AstFactory.formalParameterList([ |
| 2033 AstFactory.simpleFormalParameter3("a"), |
| 2034 AstFactory.namedFormalParameter( |
| 2035 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)) |
| 2036 ])); |
| 2037 } |
| 2038 |
| 2039 void test_visitFormalParameterList_rnn() { |
| 2040 _assertSource( |
| 2041 "(a, {b : 1, c : 2})", |
| 2042 AstFactory.formalParameterList([ |
| 2043 AstFactory.simpleFormalParameter3("a"), |
| 2044 AstFactory.namedFormalParameter( |
| 2045 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)), |
| 2046 AstFactory.namedFormalParameter( |
| 2047 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(2)) |
| 2048 ])); |
| 2049 } |
| 2050 |
| 2051 void test_visitFormalParameterList_rp() { |
| 2052 _assertSource( |
| 2053 "(a, [b = 1])", |
| 2054 AstFactory.formalParameterList([ |
| 2055 AstFactory.simpleFormalParameter3("a"), |
| 2056 AstFactory.positionalFormalParameter( |
| 2057 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)) |
| 2058 ])); |
| 2059 } |
| 2060 |
| 2061 void test_visitFormalParameterList_rpp() { |
| 2062 _assertSource( |
| 2063 "(a, [b = 1, c = 2])", |
| 2064 AstFactory.formalParameterList([ |
| 2065 AstFactory.simpleFormalParameter3("a"), |
| 2066 AstFactory.positionalFormalParameter( |
| 2067 AstFactory.simpleFormalParameter3("b"), AstFactory.integer(1)), |
| 2068 AstFactory.positionalFormalParameter( |
| 2069 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(2)) |
| 2070 ])); |
| 2071 } |
| 2072 |
| 2073 void test_visitFormalParameterList_rr() { |
| 2074 _assertSource( |
| 2075 "(a, b)", |
| 2076 AstFactory.formalParameterList([ |
| 2077 AstFactory.simpleFormalParameter3("a"), |
| 2078 AstFactory.simpleFormalParameter3("b") |
| 2079 ])); |
| 2080 } |
| 2081 |
| 2082 void test_visitFormalParameterList_rrn() { |
| 2083 _assertSource( |
| 2084 "(a, b, {c : 3})", |
| 2085 AstFactory.formalParameterList([ |
| 2086 AstFactory.simpleFormalParameter3("a"), |
| 2087 AstFactory.simpleFormalParameter3("b"), |
| 2088 AstFactory.namedFormalParameter( |
| 2089 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)) |
| 2090 ])); |
| 2091 } |
| 2092 |
| 2093 void test_visitFormalParameterList_rrnn() { |
| 2094 _assertSource( |
| 2095 "(a, b, {c : 3, d : 4})", |
| 2096 AstFactory.formalParameterList([ |
| 2097 AstFactory.simpleFormalParameter3("a"), |
| 2098 AstFactory.simpleFormalParameter3("b"), |
| 2099 AstFactory.namedFormalParameter( |
| 2100 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)), |
| 2101 AstFactory.namedFormalParameter( |
| 2102 AstFactory.simpleFormalParameter3("d"), AstFactory.integer(4)) |
| 2103 ])); |
| 2104 } |
| 2105 |
| 2106 void test_visitFormalParameterList_rrp() { |
| 2107 _assertSource( |
| 2108 "(a, b, [c = 3])", |
| 2109 AstFactory.formalParameterList([ |
| 2110 AstFactory.simpleFormalParameter3("a"), |
| 2111 AstFactory.simpleFormalParameter3("b"), |
| 2112 AstFactory.positionalFormalParameter( |
| 2113 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)) |
| 2114 ])); |
| 2115 } |
| 2116 |
| 2117 void test_visitFormalParameterList_rrpp() { |
| 2118 _assertSource( |
| 2119 "(a, b, [c = 3, d = 4])", |
| 2120 AstFactory.formalParameterList([ |
| 2121 AstFactory.simpleFormalParameter3("a"), |
| 2122 AstFactory.simpleFormalParameter3("b"), |
| 2123 AstFactory.positionalFormalParameter( |
| 2124 AstFactory.simpleFormalParameter3("c"), AstFactory.integer(3)), |
| 2125 AstFactory.positionalFormalParameter( |
| 2126 AstFactory.simpleFormalParameter3("d"), AstFactory.integer(4)) |
| 2127 ])); |
| 2128 } |
| 2129 |
| 2130 void test_visitForStatement_c() { |
| 2131 _assertSource( |
| 2132 "for (; c;) {}", |
| 2133 AstFactory.forStatement( |
| 2134 null, AstFactory.identifier3("c"), null, AstFactory.block())); |
| 2135 } |
| 2136 |
| 2137 void test_visitForStatement_cu() { |
| 2138 _assertSource( |
| 2139 "for (; c; u) {}", |
| 2140 AstFactory.forStatement(null, AstFactory.identifier3("c"), |
| 2141 [AstFactory.identifier3("u")], AstFactory.block())); |
| 2142 } |
| 2143 |
| 2144 void test_visitForStatement_e() { |
| 2145 _assertSource( |
| 2146 "for (e;;) {}", |
| 2147 AstFactory.forStatement( |
| 2148 AstFactory.identifier3("e"), null, null, AstFactory.block())); |
| 2149 } |
| 2150 |
| 2151 void test_visitForStatement_ec() { |
| 2152 _assertSource( |
| 2153 "for (e; c;) {}", |
| 2154 AstFactory.forStatement(AstFactory.identifier3("e"), |
| 2155 AstFactory.identifier3("c"), null, AstFactory.block())); |
| 2156 } |
| 2157 |
| 2158 void test_visitForStatement_ecu() { |
| 2159 _assertSource( |
| 2160 "for (e; c; u) {}", |
| 2161 AstFactory.forStatement( |
| 2162 AstFactory.identifier3("e"), |
| 2163 AstFactory.identifier3("c"), |
| 2164 [AstFactory.identifier3("u")], |
| 2165 AstFactory.block())); |
| 2166 } |
| 2167 |
| 2168 void test_visitForStatement_eu() { |
| 2169 _assertSource( |
| 2170 "for (e;; u) {}", |
| 2171 AstFactory.forStatement(AstFactory.identifier3("e"), null, |
| 2172 [AstFactory.identifier3("u")], AstFactory.block())); |
| 2173 } |
| 2174 |
| 2175 void test_visitForStatement_i() { |
| 2176 _assertSource( |
| 2177 "for (var i;;) {}", |
| 2178 AstFactory.forStatement2( |
| 2179 AstFactory.variableDeclarationList2( |
| 2180 Keyword.VAR, [AstFactory.variableDeclaration("i")]), |
| 2181 null, |
| 2182 null, |
| 2183 AstFactory.block())); |
| 2184 } |
| 2185 |
| 2186 void test_visitForStatement_ic() { |
| 2187 _assertSource( |
| 2188 "for (var i; c;) {}", |
| 2189 AstFactory.forStatement2( |
| 2190 AstFactory.variableDeclarationList2( |
| 2191 Keyword.VAR, [AstFactory.variableDeclaration("i")]), |
| 2192 AstFactory.identifier3("c"), |
| 2193 null, |
| 2194 AstFactory.block())); |
| 2195 } |
| 2196 |
| 2197 void test_visitForStatement_icu() { |
| 2198 _assertSource( |
| 2199 "for (var i; c; u) {}", |
| 2200 AstFactory.forStatement2( |
| 2201 AstFactory.variableDeclarationList2( |
| 2202 Keyword.VAR, [AstFactory.variableDeclaration("i")]), |
| 2203 AstFactory.identifier3("c"), |
| 2204 [AstFactory.identifier3("u")], |
| 2205 AstFactory.block())); |
| 2206 } |
| 2207 |
| 2208 void test_visitForStatement_iu() { |
| 2209 _assertSource( |
| 2210 "for (var i;; u) {}", |
| 2211 AstFactory.forStatement2( |
| 2212 AstFactory.variableDeclarationList2( |
| 2213 Keyword.VAR, [AstFactory.variableDeclaration("i")]), |
| 2214 null, |
| 2215 [AstFactory.identifier3("u")], |
| 2216 AstFactory.block())); |
| 2217 } |
| 2218 |
| 2219 void test_visitForStatement_u() { |
| 2220 _assertSource( |
| 2221 "for (;; u) {}", |
| 2222 AstFactory.forStatement( |
| 2223 null, null, [AstFactory.identifier3("u")], AstFactory.block())); |
| 2224 } |
| 2225 |
| 2226 void test_visitFunctionDeclaration_external() { |
| 2227 FunctionDeclaration functionDeclaration = AstFactory.functionDeclaration( |
| 2228 null, |
| 2229 null, |
| 2230 "f", |
| 2231 AstFactory.functionExpression2( |
| 2232 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody())); |
| 2233 functionDeclaration.externalKeyword = |
| 2234 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
| 2235 _assertSource("external f();", functionDeclaration); |
| 2236 } |
| 2237 |
| 2238 void test_visitFunctionDeclaration_getter() { |
| 2239 _assertSource( |
| 2240 "get f() {}", |
| 2241 AstFactory.functionDeclaration( |
| 2242 null, Keyword.GET, "f", AstFactory.functionExpression())); |
| 2243 } |
| 2244 |
| 2245 void test_visitFunctionDeclaration_local_blockBody() { |
| 2246 FunctionDeclaration f = AstFactory.functionDeclaration( |
| 2247 null, null, "f", AstFactory.functionExpression()); |
| 2248 FunctionDeclarationStatement fStatement = |
| 2249 new FunctionDeclarationStatement(f); |
| 2250 _assertSource( |
| 2251 "main() {f() {} 42;}", |
| 2252 AstFactory.functionDeclaration( |
| 2253 null, |
| 2254 null, |
| 2255 "main", |
| 2256 AstFactory.functionExpression2( |
| 2257 AstFactory.formalParameterList(), |
| 2258 AstFactory.blockFunctionBody2([ |
| 2259 fStatement, |
| 2260 AstFactory.expressionStatement(AstFactory.integer(42)) |
| 2261 ])))); |
| 2262 } |
| 2263 |
| 2264 void test_visitFunctionDeclaration_local_expressionBody() { |
| 2265 FunctionDeclaration f = AstFactory.functionDeclaration( |
| 2266 null, |
| 2267 null, |
| 2268 "f", |
| 2269 AstFactory.functionExpression2(AstFactory.formalParameterList(), |
| 2270 AstFactory.expressionFunctionBody(AstFactory.integer(1)))); |
| 2271 FunctionDeclarationStatement fStatement = |
| 2272 new FunctionDeclarationStatement(f); |
| 2273 _assertSource( |
| 2274 "main() {f() => 1; 2;}", |
| 2275 AstFactory.functionDeclaration( |
| 2276 null, |
| 2277 null, |
| 2278 "main", |
| 2279 AstFactory.functionExpression2( |
| 2280 AstFactory.formalParameterList(), |
| 2281 AstFactory.blockFunctionBody2([ |
| 2282 fStatement, |
| 2283 AstFactory.expressionStatement(AstFactory.integer(2)) |
| 2284 ])))); |
| 2285 } |
| 2286 |
| 2287 void test_visitFunctionDeclaration_normal() { |
| 2288 _assertSource( |
| 2289 "f() {}", |
| 2290 AstFactory.functionDeclaration( |
| 2291 null, null, "f", AstFactory.functionExpression())); |
| 2292 } |
| 2293 |
| 2294 void test_visitFunctionDeclaration_setter() { |
| 2295 _assertSource( |
| 2296 "set f() {}", |
| 2297 AstFactory.functionDeclaration( |
| 2298 null, Keyword.SET, "f", AstFactory.functionExpression())); |
| 2299 } |
| 2300 |
| 2301 void test_visitFunctionDeclaration_typeParameters() { |
| 2302 _assertSource( |
| 2303 "f<E>() {}", |
| 2304 AstFactory.functionDeclaration( |
| 2305 null, |
| 2306 null, |
| 2307 "f", |
| 2308 AstFactory.functionExpression3( |
| 2309 AstFactory.typeParameterList(['E']), |
| 2310 AstFactory.formalParameterList(), |
| 2311 AstFactory.blockFunctionBody2()))); |
| 2312 } |
| 2313 |
| 2314 void test_visitFunctionDeclaration_withMetadata() { |
| 2315 FunctionDeclaration declaration = AstFactory.functionDeclaration( |
| 2316 null, null, "f", AstFactory.functionExpression()); |
| 2317 declaration.metadata |
| 2318 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 2319 _assertSource("@deprecated f() {}", declaration); |
| 2320 } |
| 2321 |
| 2322 void test_visitFunctionDeclarationStatement() { |
| 2323 _assertSource( |
| 2324 "f() {}", |
| 2325 AstFactory.functionDeclarationStatement( |
| 2326 null, null, "f", AstFactory.functionExpression())); |
| 2327 } |
| 2328 |
| 2329 void test_visitFunctionExpression() { |
| 2330 _assertSource("() {}", AstFactory.functionExpression()); |
| 2331 } |
| 2332 |
| 2333 void test_visitFunctionExpression_typeParameters() { |
| 2334 _assertSource( |
| 2335 "<E>() {}", |
| 2336 AstFactory.functionExpression3(AstFactory.typeParameterList(['E']), |
| 2337 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); |
| 2338 } |
| 2339 |
| 2340 void test_visitFunctionExpressionInvocation_minimal() { |
| 2341 _assertSource("f()", |
| 2342 AstFactory.functionExpressionInvocation(AstFactory.identifier3("f"))); |
| 2343 } |
| 2344 |
| 2345 void test_visitFunctionExpressionInvocation_typeArguments() { |
| 2346 _assertSource( |
| 2347 "f<A>()", |
| 2348 AstFactory.functionExpressionInvocation2(AstFactory.identifier3("f"), |
| 2349 AstFactory.typeArgumentList([AstFactory.typeName4('A')]))); |
| 2350 } |
| 2351 |
| 2352 void test_visitFunctionTypeAlias_generic() { |
| 2353 _assertSource( |
| 2354 "typedef A F<B>();", |
| 2355 AstFactory.typeAlias( |
| 2356 AstFactory.typeName4("A"), |
| 2357 "F", |
| 2358 AstFactory.typeParameterList(["B"]), |
| 2359 AstFactory.formalParameterList())); |
| 2360 } |
| 2361 |
| 2362 void test_visitFunctionTypeAlias_nonGeneric() { |
| 2363 _assertSource( |
| 2364 "typedef A F();", |
| 2365 AstFactory.typeAlias(AstFactory.typeName4("A"), "F", null, |
| 2366 AstFactory.formalParameterList())); |
| 2367 } |
| 2368 |
| 2369 void test_visitFunctionTypeAlias_withMetadata() { |
| 2370 FunctionTypeAlias declaration = AstFactory.typeAlias( |
| 2371 AstFactory.typeName4("A"), "F", null, AstFactory.formalParameterList()); |
| 2372 declaration.metadata |
| 2373 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 2374 _assertSource("@deprecated typedef A F();", declaration); |
| 2375 } |
| 2376 |
| 2377 void test_visitFunctionTypedFormalParameter_annotation() { |
| 2378 FunctionTypedFormalParameter parameter = |
| 2379 AstFactory.functionTypedFormalParameter(null, "f"); |
| 2380 parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A"))); |
| 2381 _assertSource('@A f()', parameter); |
| 2382 } |
| 2383 |
| 2384 void test_visitFunctionTypedFormalParameter_noType() { |
| 2385 _assertSource("f()", AstFactory.functionTypedFormalParameter(null, "f")); |
| 2386 } |
| 2387 |
| 2388 void test_visitFunctionTypedFormalParameter_type() { |
| 2389 _assertSource( |
| 2390 "T f()", |
| 2391 AstFactory.functionTypedFormalParameter( |
| 2392 AstFactory.typeName4("T"), "f")); |
| 2393 } |
| 2394 |
| 2395 void test_visitFunctionTypedFormalParameter_typeParameters() { |
| 2396 _assertSource( |
| 2397 "T f<E>()", |
| 2398 new FunctionTypedFormalParameter( |
| 2399 null, |
| 2400 null, |
| 2401 AstFactory.typeName4("T"), |
| 2402 AstFactory.identifier3('f'), |
| 2403 AstFactory.typeParameterList(['E']), |
| 2404 AstFactory.formalParameterList([]))); |
| 2405 } |
| 2406 |
| 2407 void test_visitIfStatement_withElse() { |
| 2408 _assertSource( |
| 2409 "if (c) {} else {}", |
| 2410 AstFactory.ifStatement2(AstFactory.identifier3("c"), AstFactory.block(), |
| 2411 AstFactory.block())); |
| 2412 } |
| 2413 |
| 2414 void test_visitIfStatement_withoutElse() { |
| 2415 _assertSource( |
| 2416 "if (c) {}", |
| 2417 AstFactory.ifStatement( |
| 2418 AstFactory.identifier3("c"), AstFactory.block())); |
| 2419 } |
| 2420 |
| 2421 void test_visitImplementsClause_multiple() { |
| 2422 _assertSource( |
| 2423 "implements A, B", |
| 2424 AstFactory.implementsClause( |
| 2425 [AstFactory.typeName4("A"), AstFactory.typeName4("B")])); |
| 2426 } |
| 2427 |
| 2428 void test_visitImplementsClause_single() { |
| 2429 _assertSource("implements A", |
| 2430 AstFactory.implementsClause([AstFactory.typeName4("A")])); |
| 2431 } |
| 2432 |
| 2433 void test_visitImportDirective_combinator() { |
| 2434 _assertSource( |
| 2435 "import 'a.dart' show A;", |
| 2436 AstFactory.importDirective3("a.dart", null, [ |
| 2437 AstFactory.showCombinator([AstFactory.identifier3("A")]) |
| 2438 ])); |
| 2439 } |
| 2440 |
| 2441 void test_visitImportDirective_combinators() { |
| 2442 _assertSource( |
| 2443 "import 'a.dart' show A hide B;", |
| 2444 AstFactory.importDirective3("a.dart", null, [ |
| 2445 AstFactory.showCombinator([AstFactory.identifier3("A")]), |
| 2446 AstFactory.hideCombinator([AstFactory.identifier3("B")]) |
| 2447 ])); |
| 2448 } |
| 2449 |
| 2450 void test_visitImportDirective_deferred() { |
| 2451 _assertSource("import 'a.dart' deferred as p;", |
| 2452 AstFactory.importDirective2("a.dart", true, "p")); |
| 2453 } |
| 2454 |
| 2455 void test_visitImportDirective_minimal() { |
| 2456 _assertSource( |
| 2457 "import 'a.dart';", AstFactory.importDirective3("a.dart", null)); |
| 2458 } |
| 2459 |
| 2460 void test_visitImportDirective_prefix() { |
| 2461 _assertSource( |
| 2462 "import 'a.dart' as p;", AstFactory.importDirective3("a.dart", "p")); |
| 2463 } |
| 2464 |
| 2465 void test_visitImportDirective_prefix_combinator() { |
| 2466 _assertSource( |
| 2467 "import 'a.dart' as p show A;", |
| 2468 AstFactory.importDirective3("a.dart", "p", [ |
| 2469 AstFactory.showCombinator([AstFactory.identifier3("A")]) |
| 2470 ])); |
| 2471 } |
| 2472 |
| 2473 void test_visitImportDirective_prefix_combinators() { |
| 2474 _assertSource( |
| 2475 "import 'a.dart' as p show A hide B;", |
| 2476 AstFactory.importDirective3("a.dart", "p", [ |
| 2477 AstFactory.showCombinator([AstFactory.identifier3("A")]), |
| 2478 AstFactory.hideCombinator([AstFactory.identifier3("B")]) |
| 2479 ])); |
| 2480 } |
| 2481 |
| 2482 void test_visitImportDirective_withMetadata() { |
| 2483 ImportDirective directive = AstFactory.importDirective3("a.dart", null); |
| 2484 directive.metadata |
| 2485 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 2486 _assertSource("@deprecated import 'a.dart';", directive); |
| 2487 } |
| 2488 |
| 2489 void test_visitImportHideCombinator_multiple() { |
| 2490 _assertSource( |
| 2491 "hide a, b", |
| 2492 AstFactory.hideCombinator( |
| 2493 [AstFactory.identifier3("a"), AstFactory.identifier3("b")])); |
| 2494 } |
| 2495 |
| 2496 void test_visitImportHideCombinator_single() { |
| 2497 _assertSource( |
| 2498 "hide a", AstFactory.hideCombinator([AstFactory.identifier3("a")])); |
| 2499 } |
| 2500 |
| 2501 void test_visitImportShowCombinator_multiple() { |
| 2502 _assertSource( |
| 2503 "show a, b", |
| 2504 AstFactory.showCombinator( |
| 2505 [AstFactory.identifier3("a"), AstFactory.identifier3("b")])); |
| 2506 } |
| 2507 |
| 2508 void test_visitImportShowCombinator_single() { |
| 2509 _assertSource( |
| 2510 "show a", AstFactory.showCombinator([AstFactory.identifier3("a")])); |
| 2511 } |
| 2512 |
| 2513 void test_visitIndexExpression() { |
| 2514 _assertSource( |
| 2515 "a[i]", |
| 2516 AstFactory.indexExpression( |
| 2517 AstFactory.identifier3("a"), AstFactory.identifier3("i"))); |
| 2518 } |
| 2519 |
| 2520 void test_visitInstanceCreationExpression_const() { |
| 2521 _assertSource( |
| 2522 "const C()", |
| 2523 AstFactory.instanceCreationExpression2( |
| 2524 Keyword.CONST, AstFactory.typeName4("C"))); |
| 2525 } |
| 2526 |
| 2527 void test_visitInstanceCreationExpression_named() { |
| 2528 _assertSource( |
| 2529 "new C.c()", |
| 2530 AstFactory.instanceCreationExpression3( |
| 2531 Keyword.NEW, AstFactory.typeName4("C"), "c")); |
| 2532 } |
| 2533 |
| 2534 void test_visitInstanceCreationExpression_unnamed() { |
| 2535 _assertSource( |
| 2536 "new C()", |
| 2537 AstFactory.instanceCreationExpression2( |
| 2538 Keyword.NEW, AstFactory.typeName4("C"))); |
| 2539 } |
| 2540 |
| 2541 void test_visitIntegerLiteral() { |
| 2542 _assertSource("42", AstFactory.integer(42)); |
| 2543 } |
| 2544 |
| 2545 void test_visitInterpolationExpression_expression() { |
| 2546 _assertSource("\${a}", |
| 2547 AstFactory.interpolationExpression(AstFactory.identifier3("a"))); |
| 2548 } |
| 2549 |
| 2550 void test_visitInterpolationExpression_identifier() { |
| 2551 _assertSource("\$a", AstFactory.interpolationExpression2("a")); |
| 2552 } |
| 2553 |
| 2554 void test_visitInterpolationString() { |
| 2555 _assertSource("'x", AstFactory.interpolationString("'x", "x")); |
| 2556 } |
| 2557 |
| 2558 void test_visitIsExpression_negated() { |
| 2559 _assertSource( |
| 2560 "a is! C", |
| 2561 AstFactory.isExpression( |
| 2562 AstFactory.identifier3("a"), true, AstFactory.typeName4("C"))); |
| 2563 } |
| 2564 |
| 2565 void test_visitIsExpression_normal() { |
| 2566 _assertSource( |
| 2567 "a is C", |
| 2568 AstFactory.isExpression( |
| 2569 AstFactory.identifier3("a"), false, AstFactory.typeName4("C"))); |
| 2570 } |
| 2571 |
| 2572 void test_visitLabel() { |
| 2573 _assertSource("a:", AstFactory.label2("a")); |
| 2574 } |
| 2575 |
| 2576 void test_visitLabeledStatement_multiple() { |
| 2577 _assertSource( |
| 2578 "a: b: return;", |
| 2579 AstFactory.labeledStatement( |
| 2580 [AstFactory.label2("a"), AstFactory.label2("b")], |
| 2581 AstFactory.returnStatement())); |
| 2582 } |
| 2583 |
| 2584 void test_visitLabeledStatement_single() { |
| 2585 _assertSource( |
| 2586 "a: return;", |
| 2587 AstFactory.labeledStatement( |
| 2588 [AstFactory.label2("a")], AstFactory.returnStatement())); |
| 2589 } |
| 2590 |
| 2591 void test_visitLibraryDirective() { |
| 2592 _assertSource("library l;", AstFactory.libraryDirective2("l")); |
| 2593 } |
| 2594 |
| 2595 void test_visitLibraryDirective_withMetadata() { |
| 2596 LibraryDirective directive = AstFactory.libraryDirective2("l"); |
| 2597 directive.metadata |
| 2598 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 2599 _assertSource("@deprecated library l;", directive); |
| 2600 } |
| 2601 |
| 2602 void test_visitLibraryIdentifier_multiple() { |
| 2603 _assertSource( |
| 2604 "a.b.c", |
| 2605 AstFactory.libraryIdentifier([ |
| 2606 AstFactory.identifier3("a"), |
| 2607 AstFactory.identifier3("b"), |
| 2608 AstFactory.identifier3("c") |
| 2609 ])); |
| 2610 } |
| 2611 |
| 2612 void test_visitLibraryIdentifier_single() { |
| 2613 _assertSource( |
| 2614 "a", AstFactory.libraryIdentifier([AstFactory.identifier3("a")])); |
| 2615 } |
| 2616 |
| 2617 void test_visitListLiteral_const() { |
| 2618 _assertSource("const []", AstFactory.listLiteral2(Keyword.CONST, null)); |
| 2619 } |
| 2620 |
| 2621 void test_visitListLiteral_empty() { |
| 2622 _assertSource("[]", AstFactory.listLiteral()); |
| 2623 } |
| 2624 |
| 2625 void test_visitListLiteral_nonEmpty() { |
| 2626 _assertSource( |
| 2627 "[a, b, c]", |
| 2628 AstFactory.listLiteral([ |
| 2629 AstFactory.identifier3("a"), |
| 2630 AstFactory.identifier3("b"), |
| 2631 AstFactory.identifier3("c") |
| 2632 ])); |
| 2633 } |
| 2634 |
| 2635 void test_visitMapLiteral_const() { |
| 2636 _assertSource("const {}", AstFactory.mapLiteral(Keyword.CONST, null)); |
| 2637 } |
| 2638 |
| 2639 void test_visitMapLiteral_empty() { |
| 2640 _assertSource("{}", AstFactory.mapLiteral2()); |
| 2641 } |
| 2642 |
| 2643 void test_visitMapLiteral_nonEmpty() { |
| 2644 _assertSource( |
| 2645 "{'a' : a, 'b' : b, 'c' : c}", |
| 2646 AstFactory.mapLiteral2([ |
| 2647 AstFactory.mapLiteralEntry("a", AstFactory.identifier3("a")), |
| 2648 AstFactory.mapLiteralEntry("b", AstFactory.identifier3("b")), |
| 2649 AstFactory.mapLiteralEntry("c", AstFactory.identifier3("c")) |
| 2650 ])); |
| 2651 } |
| 2652 |
| 2653 void test_visitMapLiteralEntry() { |
| 2654 _assertSource("'a' : b", |
| 2655 AstFactory.mapLiteralEntry("a", AstFactory.identifier3("b"))); |
| 2656 } |
| 2657 |
| 2658 void test_visitMethodDeclaration_external() { |
| 2659 _assertSource( |
| 2660 "external m();", |
| 2661 AstFactory.methodDeclaration(null, null, null, null, |
| 2662 AstFactory.identifier3("m"), AstFactory.formalParameterList())); |
| 2663 } |
| 2664 |
| 2665 void test_visitMethodDeclaration_external_returnType() { |
| 2666 _assertSource( |
| 2667 "external T m();", |
| 2668 AstFactory.methodDeclaration( |
| 2669 null, |
| 2670 AstFactory.typeName4("T"), |
| 2671 null, |
| 2672 null, |
| 2673 AstFactory.identifier3("m"), |
| 2674 AstFactory.formalParameterList())); |
| 2675 } |
| 2676 |
| 2677 void test_visitMethodDeclaration_getter() { |
| 2678 _assertSource( |
| 2679 "get m {}", |
| 2680 AstFactory.methodDeclaration2( |
| 2681 null, |
| 2682 null, |
| 2683 Keyword.GET, |
| 2684 null, |
| 2685 AstFactory.identifier3("m"), |
| 2686 null, |
| 2687 AstFactory.blockFunctionBody2())); |
| 2688 } |
| 2689 |
| 2690 void test_visitMethodDeclaration_getter_returnType() { |
| 2691 _assertSource( |
| 2692 "T get m {}", |
| 2693 AstFactory.methodDeclaration2( |
| 2694 null, |
| 2695 AstFactory.typeName4("T"), |
| 2696 Keyword.GET, |
| 2697 null, |
| 2698 AstFactory.identifier3("m"), |
| 2699 null, |
| 2700 AstFactory.blockFunctionBody2())); |
| 2701 } |
| 2702 |
| 2703 void test_visitMethodDeclaration_getter_seturnType() { |
| 2704 _assertSource( |
| 2705 "T set m(var v) {}", |
| 2706 AstFactory.methodDeclaration2( |
| 2707 null, |
| 2708 AstFactory.typeName4("T"), |
| 2709 Keyword.SET, |
| 2710 null, |
| 2711 AstFactory.identifier3("m"), |
| 2712 AstFactory.formalParameterList( |
| 2713 [AstFactory.simpleFormalParameter(Keyword.VAR, "v")]), |
| 2714 AstFactory.blockFunctionBody2())); |
| 2715 } |
| 2716 |
| 2717 void test_visitMethodDeclaration_minimal() { |
| 2718 _assertSource( |
| 2719 "m() {}", |
| 2720 AstFactory.methodDeclaration2( |
| 2721 null, |
| 2722 null, |
| 2723 null, |
| 2724 null, |
| 2725 AstFactory.identifier3("m"), |
| 2726 AstFactory.formalParameterList(), |
| 2727 AstFactory.blockFunctionBody2())); |
| 2728 } |
| 2729 |
| 2730 void test_visitMethodDeclaration_multipleParameters() { |
| 2731 _assertSource( |
| 2732 "m(var a, var b) {}", |
| 2733 AstFactory.methodDeclaration2( |
| 2734 null, |
| 2735 null, |
| 2736 null, |
| 2737 null, |
| 2738 AstFactory.identifier3("m"), |
| 2739 AstFactory.formalParameterList([ |
| 2740 AstFactory.simpleFormalParameter(Keyword.VAR, "a"), |
| 2741 AstFactory.simpleFormalParameter(Keyword.VAR, "b") |
| 2742 ]), |
| 2743 AstFactory.blockFunctionBody2())); |
| 2744 } |
| 2745 |
| 2746 void test_visitMethodDeclaration_operator() { |
| 2747 _assertSource( |
| 2748 "operator +() {}", |
| 2749 AstFactory.methodDeclaration2( |
| 2750 null, |
| 2751 null, |
| 2752 null, |
| 2753 Keyword.OPERATOR, |
| 2754 AstFactory.identifier3("+"), |
| 2755 AstFactory.formalParameterList(), |
| 2756 AstFactory.blockFunctionBody2())); |
| 2757 } |
| 2758 |
| 2759 void test_visitMethodDeclaration_operator_returnType() { |
| 2760 _assertSource( |
| 2761 "T operator +() {}", |
| 2762 AstFactory.methodDeclaration2( |
| 2763 null, |
| 2764 AstFactory.typeName4("T"), |
| 2765 null, |
| 2766 Keyword.OPERATOR, |
| 2767 AstFactory.identifier3("+"), |
| 2768 AstFactory.formalParameterList(), |
| 2769 AstFactory.blockFunctionBody2())); |
| 2770 } |
| 2771 |
| 2772 void test_visitMethodDeclaration_returnType() { |
| 2773 _assertSource( |
| 2774 "T m() {}", |
| 2775 AstFactory.methodDeclaration2( |
| 2776 null, |
| 2777 AstFactory.typeName4("T"), |
| 2778 null, |
| 2779 null, |
| 2780 AstFactory.identifier3("m"), |
| 2781 AstFactory.formalParameterList(), |
| 2782 AstFactory.blockFunctionBody2())); |
| 2783 } |
| 2784 |
| 2785 void test_visitMethodDeclaration_setter() { |
| 2786 _assertSource( |
| 2787 "set m(var v) {}", |
| 2788 AstFactory.methodDeclaration2( |
| 2789 null, |
| 2790 null, |
| 2791 Keyword.SET, |
| 2792 null, |
| 2793 AstFactory.identifier3("m"), |
| 2794 AstFactory.formalParameterList( |
| 2795 [AstFactory.simpleFormalParameter(Keyword.VAR, "v")]), |
| 2796 AstFactory.blockFunctionBody2())); |
| 2797 } |
| 2798 |
| 2799 void test_visitMethodDeclaration_static() { |
| 2800 _assertSource( |
| 2801 "static m() {}", |
| 2802 AstFactory.methodDeclaration2( |
| 2803 Keyword.STATIC, |
| 2804 null, |
| 2805 null, |
| 2806 null, |
| 2807 AstFactory.identifier3("m"), |
| 2808 AstFactory.formalParameterList(), |
| 2809 AstFactory.blockFunctionBody2())); |
| 2810 } |
| 2811 |
| 2812 void test_visitMethodDeclaration_static_returnType() { |
| 2813 _assertSource( |
| 2814 "static T m() {}", |
| 2815 AstFactory.methodDeclaration2( |
| 2816 Keyword.STATIC, |
| 2817 AstFactory.typeName4("T"), |
| 2818 null, |
| 2819 null, |
| 2820 AstFactory.identifier3("m"), |
| 2821 AstFactory.formalParameterList(), |
| 2822 AstFactory.blockFunctionBody2())); |
| 2823 } |
| 2824 |
| 2825 void test_visitMethodDeclaration_typeParameters() { |
| 2826 _assertSource( |
| 2827 "m<E>() {}", |
| 2828 AstFactory.methodDeclaration3( |
| 2829 null, |
| 2830 null, |
| 2831 null, |
| 2832 null, |
| 2833 AstFactory.identifier3("m"), |
| 2834 AstFactory.typeParameterList(['E']), |
| 2835 AstFactory.formalParameterList(), |
| 2836 AstFactory.blockFunctionBody2())); |
| 2837 } |
| 2838 |
| 2839 void test_visitMethodDeclaration_withMetadata() { |
| 2840 MethodDeclaration declaration = AstFactory.methodDeclaration2( |
| 2841 null, |
| 2842 null, |
| 2843 null, |
| 2844 null, |
| 2845 AstFactory.identifier3("m"), |
| 2846 AstFactory.formalParameterList(), |
| 2847 AstFactory.blockFunctionBody2()); |
| 2848 declaration.metadata |
| 2849 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 2850 _assertSource("@deprecated m() {}", declaration); |
| 2851 } |
| 2852 |
| 2853 void test_visitMethodInvocation_conditional() { |
| 2854 _assertSource( |
| 2855 "t?.m()", |
| 2856 AstFactory.methodInvocation( |
| 2857 AstFactory.identifier3("t"), "m", null, TokenType.QUESTION_PERIOD)); |
| 2858 } |
| 2859 |
| 2860 void test_visitMethodInvocation_noTarget() { |
| 2861 _assertSource("m()", AstFactory.methodInvocation2("m")); |
| 2862 } |
| 2863 |
| 2864 void test_visitMethodInvocation_target() { |
| 2865 _assertSource( |
| 2866 "t.m()", AstFactory.methodInvocation(AstFactory.identifier3("t"), "m")); |
| 2867 } |
| 2868 |
| 2869 void test_visitMethodInvocation_typeArguments() { |
| 2870 _assertSource( |
| 2871 "m<A>()", |
| 2872 AstFactory.methodInvocation3(null, "m", |
| 2873 AstFactory.typeArgumentList([AstFactory.typeName4('A')]))); |
| 2874 } |
| 2875 |
| 2876 void test_visitNamedExpression() { |
| 2877 _assertSource( |
| 2878 "a: b", AstFactory.namedExpression2("a", AstFactory.identifier3("b"))); |
| 2879 } |
| 2880 |
| 2881 void test_visitNamedFormalParameter() { |
| 2882 _assertSource( |
| 2883 "var a : 0", |
| 2884 AstFactory.namedFormalParameter( |
| 2885 AstFactory.simpleFormalParameter(Keyword.VAR, "a"), |
| 2886 AstFactory.integer(0))); |
| 2887 } |
| 2888 |
| 2889 void test_visitNativeClause() { |
| 2890 _assertSource("native 'code'", AstFactory.nativeClause("code")); |
| 2891 } |
| 2892 |
| 2893 void test_visitNativeFunctionBody() { |
| 2894 _assertSource("native 'str';", AstFactory.nativeFunctionBody("str")); |
| 2895 } |
| 2896 |
| 2897 void test_visitNullLiteral() { |
| 2898 _assertSource("null", AstFactory.nullLiteral()); |
| 2899 } |
| 2900 |
| 2901 void test_visitParenthesizedExpression() { |
| 2902 _assertSource( |
| 2903 "(a)", AstFactory.parenthesizedExpression(AstFactory.identifier3("a"))); |
| 2904 } |
| 2905 |
| 2906 void test_visitPartDirective() { |
| 2907 _assertSource("part 'a.dart';", AstFactory.partDirective2("a.dart")); |
| 2908 } |
| 2909 |
| 2910 void test_visitPartDirective_withMetadata() { |
| 2911 PartDirective directive = AstFactory.partDirective2("a.dart"); |
| 2912 directive.metadata |
| 2913 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 2914 _assertSource("@deprecated part 'a.dart';", directive); |
| 2915 } |
| 2916 |
| 2917 void test_visitPartOfDirective() { |
| 2918 _assertSource("part of l;", |
| 2919 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["l"]))); |
| 2920 } |
| 2921 |
| 2922 void test_visitPartOfDirective_withMetadata() { |
| 2923 PartOfDirective directive = |
| 2924 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["l"])); |
| 2925 directive.metadata |
| 2926 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 2927 _assertSource("@deprecated part of l;", directive); |
| 2928 } |
| 2929 |
| 2930 void test_visitPositionalFormalParameter() { |
| 2931 _assertSource( |
| 2932 "var a = 0", |
| 2933 AstFactory.positionalFormalParameter( |
| 2934 AstFactory.simpleFormalParameter(Keyword.VAR, "a"), |
| 2935 AstFactory.integer(0))); |
| 2936 } |
| 2937 |
| 2938 void test_visitPostfixExpression() { |
| 2939 _assertSource( |
| 2940 "a++", |
| 2941 AstFactory.postfixExpression( |
| 2942 AstFactory.identifier3("a"), TokenType.PLUS_PLUS)); |
| 2943 } |
| 2944 |
| 2945 void test_visitPrefixedIdentifier() { |
| 2946 _assertSource("a.b", AstFactory.identifier5("a", "b")); |
| 2947 } |
| 2948 |
| 2949 void test_visitPrefixExpression() { |
| 2950 _assertSource( |
| 2951 "-a", |
| 2952 AstFactory.prefixExpression( |
| 2953 TokenType.MINUS, AstFactory.identifier3("a"))); |
| 2954 } |
| 2955 |
| 2956 void test_visitPropertyAccess() { |
| 2957 _assertSource( |
| 2958 "a.b", AstFactory.propertyAccess2(AstFactory.identifier3("a"), "b")); |
| 2959 } |
| 2960 |
| 2961 void test_visitPropertyAccess_conditional() { |
| 2962 _assertSource( |
| 2963 "a?.b", |
| 2964 AstFactory.propertyAccess2( |
| 2965 AstFactory.identifier3("a"), "b", TokenType.QUESTION_PERIOD)); |
| 2966 } |
| 2967 |
| 2968 void test_visitRedirectingConstructorInvocation_named() { |
| 2969 _assertSource( |
| 2970 "this.c()", AstFactory.redirectingConstructorInvocation2("c")); |
| 2971 } |
| 2972 |
| 2973 void test_visitRedirectingConstructorInvocation_unnamed() { |
| 2974 _assertSource("this()", AstFactory.redirectingConstructorInvocation()); |
| 2975 } |
| 2976 |
| 2977 void test_visitRethrowExpression() { |
| 2978 _assertSource("rethrow", AstFactory.rethrowExpression()); |
| 2979 } |
| 2980 |
| 2981 void test_visitReturnStatement_expression() { |
| 2982 _assertSource( |
| 2983 "return a;", AstFactory.returnStatement2(AstFactory.identifier3("a"))); |
| 2984 } |
| 2985 |
| 2986 void test_visitReturnStatement_noExpression() { |
| 2987 _assertSource("return;", AstFactory.returnStatement()); |
| 2988 } |
| 2989 |
| 2990 void test_visitScriptTag() { |
| 2991 String scriptTag = "!#/bin/dart.exe"; |
| 2992 _assertSource(scriptTag, AstFactory.scriptTag(scriptTag)); |
| 2993 } |
| 2994 |
| 2995 void test_visitSimpleFormalParameter_annotation() { |
| 2996 SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3('x'); |
| 2997 parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A"))); |
| 2998 _assertSource('@A x', parameter); |
| 2999 } |
| 3000 |
| 3001 void test_visitSimpleFormalParameter_keyword() { |
| 3002 _assertSource("var a", AstFactory.simpleFormalParameter(Keyword.VAR, "a")); |
| 3003 } |
| 3004 |
| 3005 void test_visitSimpleFormalParameter_keyword_type() { |
| 3006 _assertSource( |
| 3007 "final A a", |
| 3008 AstFactory.simpleFormalParameter2( |
| 3009 Keyword.FINAL, AstFactory.typeName4("A"), "a")); |
| 3010 } |
| 3011 |
| 3012 void test_visitSimpleFormalParameter_type() { |
| 3013 _assertSource("A a", |
| 3014 AstFactory.simpleFormalParameter4(AstFactory.typeName4("A"), "a")); |
| 3015 } |
| 3016 |
| 3017 void test_visitSimpleIdentifier() { |
| 3018 _assertSource("a", AstFactory.identifier3("a")); |
| 3019 } |
| 3020 |
| 3021 void test_visitSimpleStringLiteral() { |
| 3022 _assertSource("'a'", AstFactory.string2("a")); |
| 3023 } |
| 3024 |
| 3025 void test_visitStringInterpolation() { |
| 3026 _assertSource( |
| 3027 "'a\${e}b'", |
| 3028 AstFactory.string([ |
| 3029 AstFactory.interpolationString("'a", "a"), |
| 3030 AstFactory.interpolationExpression(AstFactory.identifier3("e")), |
| 3031 AstFactory.interpolationString("b'", "b") |
| 3032 ])); |
| 3033 } |
| 3034 |
| 3035 void test_visitSuperConstructorInvocation() { |
| 3036 _assertSource("super()", AstFactory.superConstructorInvocation()); |
| 3037 } |
| 3038 |
| 3039 void test_visitSuperConstructorInvocation_named() { |
| 3040 _assertSource("super.c()", AstFactory.superConstructorInvocation2("c")); |
| 3041 } |
| 3042 |
| 3043 void test_visitSuperExpression() { |
| 3044 _assertSource("super", AstFactory.superExpression()); |
| 3045 } |
| 3046 |
| 3047 void test_visitSwitchCase_multipleLabels() { |
| 3048 _assertSource( |
| 3049 "l1: l2: case a: {}", |
| 3050 AstFactory.switchCase2( |
| 3051 [AstFactory.label2("l1"), AstFactory.label2("l2")], |
| 3052 AstFactory.identifier3("a"), |
| 3053 [AstFactory.block()])); |
| 3054 } |
| 3055 |
| 3056 void test_visitSwitchCase_multipleStatements() { |
| 3057 _assertSource( |
| 3058 "case a: {} {}", |
| 3059 AstFactory.switchCase(AstFactory.identifier3("a"), |
| 3060 [AstFactory.block(), AstFactory.block()])); |
| 3061 } |
| 3062 |
| 3063 void test_visitSwitchCase_noLabels() { |
| 3064 _assertSource( |
| 3065 "case a: {}", |
| 3066 AstFactory |
| 3067 .switchCase(AstFactory.identifier3("a"), [AstFactory.block()])); |
| 3068 } |
| 3069 |
| 3070 void test_visitSwitchCase_singleLabel() { |
| 3071 _assertSource( |
| 3072 "l1: case a: {}", |
| 3073 AstFactory.switchCase2([AstFactory.label2("l1")], |
| 3074 AstFactory.identifier3("a"), [AstFactory.block()])); |
| 3075 } |
| 3076 |
| 3077 void test_visitSwitchDefault_multipleLabels() { |
| 3078 _assertSource( |
| 3079 "l1: l2: default: {}", |
| 3080 AstFactory.switchDefault( |
| 3081 [AstFactory.label2("l1"), AstFactory.label2("l2")], |
| 3082 [AstFactory.block()])); |
| 3083 } |
| 3084 |
| 3085 void test_visitSwitchDefault_multipleStatements() { |
| 3086 _assertSource("default: {} {}", |
| 3087 AstFactory.switchDefault2([AstFactory.block(), AstFactory.block()])); |
| 3088 } |
| 3089 |
| 3090 void test_visitSwitchDefault_noLabels() { |
| 3091 _assertSource( |
| 3092 "default: {}", AstFactory.switchDefault2([AstFactory.block()])); |
| 3093 } |
| 3094 |
| 3095 void test_visitSwitchDefault_singleLabel() { |
| 3096 _assertSource( |
| 3097 "l1: default: {}", |
| 3098 AstFactory |
| 3099 .switchDefault([AstFactory.label2("l1")], [AstFactory.block()])); |
| 3100 } |
| 3101 |
| 3102 void test_visitSwitchStatement() { |
| 3103 _assertSource( |
| 3104 "switch (a) {case 'b': {} default: {}}", |
| 3105 AstFactory.switchStatement(AstFactory.identifier3("a"), [ |
| 3106 AstFactory.switchCase(AstFactory.string2("b"), [AstFactory.block()]), |
| 3107 AstFactory.switchDefault2([AstFactory.block()]) |
| 3108 ])); |
| 3109 } |
| 3110 |
| 3111 void test_visitSymbolLiteral_multiple() { |
| 3112 _assertSource("#a.b.c", AstFactory.symbolLiteral(["a", "b", "c"])); |
| 3113 } |
| 3114 |
| 3115 void test_visitSymbolLiteral_single() { |
| 3116 _assertSource("#a", AstFactory.symbolLiteral(["a"])); |
| 3117 } |
| 3118 |
| 3119 void test_visitThisExpression() { |
| 3120 _assertSource("this", AstFactory.thisExpression()); |
| 3121 } |
| 3122 |
| 3123 void test_visitThrowStatement() { |
| 3124 _assertSource( |
| 3125 "throw e", AstFactory.throwExpression2(AstFactory.identifier3("e"))); |
| 3126 } |
| 3127 |
| 3128 void test_visitTopLevelVariableDeclaration_multiple() { |
| 3129 _assertSource( |
| 3130 "var a;", |
| 3131 AstFactory.topLevelVariableDeclaration2( |
| 3132 Keyword.VAR, [AstFactory.variableDeclaration("a")])); |
| 3133 } |
| 3134 |
| 3135 void test_visitTopLevelVariableDeclaration_single() { |
| 3136 _assertSource( |
| 3137 "var a, b;", |
| 3138 AstFactory.topLevelVariableDeclaration2(Keyword.VAR, [ |
| 3139 AstFactory.variableDeclaration("a"), |
| 3140 AstFactory.variableDeclaration("b") |
| 3141 ])); |
| 3142 } |
| 3143 |
| 3144 void test_visitTryStatement_catch() { |
| 3145 _assertSource( |
| 3146 "try {} on E {}", |
| 3147 AstFactory.tryStatement2(AstFactory.block(), |
| 3148 [AstFactory.catchClause3(AstFactory.typeName4("E"))])); |
| 3149 } |
| 3150 |
| 3151 void test_visitTryStatement_catches() { |
| 3152 _assertSource( |
| 3153 "try {} on E {} on F {}", |
| 3154 AstFactory.tryStatement2(AstFactory.block(), [ |
| 3155 AstFactory.catchClause3(AstFactory.typeName4("E")), |
| 3156 AstFactory.catchClause3(AstFactory.typeName4("F")) |
| 3157 ])); |
| 3158 } |
| 3159 |
| 3160 void test_visitTryStatement_catchFinally() { |
| 3161 _assertSource( |
| 3162 "try {} on E {} finally {}", |
| 3163 AstFactory.tryStatement3( |
| 3164 AstFactory.block(), |
| 3165 [AstFactory.catchClause3(AstFactory.typeName4("E"))], |
| 3166 AstFactory.block())); |
| 3167 } |
| 3168 |
| 3169 void test_visitTryStatement_finally() { |
| 3170 _assertSource("try {} finally {}", |
| 3171 AstFactory.tryStatement(AstFactory.block(), AstFactory.block())); |
| 3172 } |
| 3173 |
| 3174 void test_visitTypeArgumentList_multiple() { |
| 3175 _assertSource( |
| 3176 "<E, F>", |
| 3177 AstFactory.typeArgumentList( |
| 3178 [AstFactory.typeName4("E"), AstFactory.typeName4("F")])); |
| 3179 } |
| 3180 |
| 3181 void test_visitTypeArgumentList_single() { |
| 3182 _assertSource( |
| 3183 "<E>", AstFactory.typeArgumentList([AstFactory.typeName4("E")])); |
| 3184 } |
| 3185 |
| 3186 void test_visitTypeName_multipleArgs() { |
| 3187 _assertSource( |
| 3188 "C<D, E>", |
| 3189 AstFactory.typeName4( |
| 3190 "C", [AstFactory.typeName4("D"), AstFactory.typeName4("E")])); |
| 3191 } |
| 3192 |
| 3193 void test_visitTypeName_nestedArg() { |
| 3194 _assertSource( |
| 3195 "C<D<E>>", |
| 3196 AstFactory.typeName4("C", [ |
| 3197 AstFactory.typeName4("D", [AstFactory.typeName4("E")]) |
| 3198 ])); |
| 3199 } |
| 3200 |
| 3201 void test_visitTypeName_noArgs() { |
| 3202 _assertSource("C", AstFactory.typeName4("C")); |
| 3203 } |
| 3204 |
| 3205 void test_visitTypeName_singleArg() { |
| 3206 _assertSource( |
| 3207 "C<D>", AstFactory.typeName4("C", [AstFactory.typeName4("D")])); |
| 3208 } |
| 3209 |
| 3210 void test_visitTypeParameter_withExtends() { |
| 3211 _assertSource("E extends C", |
| 3212 AstFactory.typeParameter2("E", AstFactory.typeName4("C"))); |
| 3213 } |
| 3214 |
| 3215 void test_visitTypeParameter_withMetadata() { |
| 3216 TypeParameter parameter = AstFactory.typeParameter("E"); |
| 3217 parameter.metadata |
| 3218 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 3219 _assertSource("@deprecated E", parameter); |
| 3220 } |
| 3221 |
| 3222 void test_visitTypeParameter_withoutExtends() { |
| 3223 _assertSource("E", AstFactory.typeParameter("E")); |
| 3224 } |
| 3225 |
| 3226 void test_visitTypeParameterList_multiple() { |
| 3227 _assertSource("<E, F>", AstFactory.typeParameterList(["E", "F"])); |
| 3228 } |
| 3229 |
| 3230 void test_visitTypeParameterList_single() { |
| 3231 _assertSource("<E>", AstFactory.typeParameterList(["E"])); |
| 3232 } |
| 3233 |
| 3234 void test_visitVariableDeclaration_initialized() { |
| 3235 _assertSource("a = b", |
| 3236 AstFactory.variableDeclaration2("a", AstFactory.identifier3("b"))); |
| 3237 } |
| 3238 |
| 3239 void test_visitVariableDeclaration_uninitialized() { |
| 3240 _assertSource("a", AstFactory.variableDeclaration("a")); |
| 3241 } |
| 3242 |
| 3243 void test_visitVariableDeclaration_withMetadata() { |
| 3244 VariableDeclaration declaration = AstFactory.variableDeclaration("a"); |
| 3245 declaration.metadata |
| 3246 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 3247 _assertSource("@deprecated a", declaration); |
| 3248 } |
| 3249 |
| 3250 void test_visitVariableDeclarationList_const_type() { |
| 3251 _assertSource( |
| 3252 "const C a, b", |
| 3253 AstFactory.variableDeclarationList( |
| 3254 Keyword.CONST, AstFactory.typeName4("C"), [ |
| 3255 AstFactory.variableDeclaration("a"), |
| 3256 AstFactory.variableDeclaration("b") |
| 3257 ])); |
| 3258 } |
| 3259 |
| 3260 void test_visitVariableDeclarationList_final_noType() { |
| 3261 _assertSource( |
| 3262 "final a, b", |
| 3263 AstFactory.variableDeclarationList2(Keyword.FINAL, [ |
| 3264 AstFactory.variableDeclaration("a"), |
| 3265 AstFactory.variableDeclaration("b") |
| 3266 ])); |
| 3267 } |
| 3268 |
| 3269 void test_visitVariableDeclarationList_final_withMetadata() { |
| 3270 VariableDeclarationList declarationList = AstFactory |
| 3271 .variableDeclarationList2(Keyword.FINAL, [ |
| 3272 AstFactory.variableDeclaration("a"), |
| 3273 AstFactory.variableDeclaration("b") |
| 3274 ]); |
| 3275 declarationList.metadata |
| 3276 .add(AstFactory.annotation(AstFactory.identifier3("deprecated"))); |
| 3277 _assertSource("@deprecated final a, b", declarationList); |
| 3278 } |
| 3279 |
| 3280 void test_visitVariableDeclarationList_type() { |
| 3281 _assertSource( |
| 3282 "C a, b", |
| 3283 AstFactory.variableDeclarationList(null, AstFactory.typeName4("C"), [ |
| 3284 AstFactory.variableDeclaration("a"), |
| 3285 AstFactory.variableDeclaration("b") |
| 3286 ])); |
| 3287 } |
| 3288 |
| 3289 void test_visitVariableDeclarationList_var() { |
| 3290 _assertSource( |
| 3291 "var a, b", |
| 3292 AstFactory.variableDeclarationList2(Keyword.VAR, [ |
| 3293 AstFactory.variableDeclaration("a"), |
| 3294 AstFactory.variableDeclaration("b") |
| 3295 ])); |
| 3296 } |
| 3297 |
| 3298 void test_visitVariableDeclarationStatement() { |
| 3299 _assertSource( |
| 3300 "C c;", |
| 3301 AstFactory.variableDeclarationStatement(null, AstFactory.typeName4("C"), |
| 3302 [AstFactory.variableDeclaration("c")])); |
| 3303 } |
| 3304 |
| 3305 void test_visitWhileStatement() { |
| 3306 _assertSource( |
| 3307 "while (c) {}", |
| 3308 AstFactory.whileStatement( |
| 3309 AstFactory.identifier3("c"), AstFactory.block())); |
| 3310 } |
| 3311 |
| 3312 void test_visitWithClause_multiple() { |
| 3313 _assertSource( |
| 3314 "with A, B, C", |
| 3315 AstFactory.withClause([ |
| 3316 AstFactory.typeName4("A"), |
| 3317 AstFactory.typeName4("B"), |
| 3318 AstFactory.typeName4("C") |
| 3319 ])); |
| 3320 } |
| 3321 |
| 3322 void test_visitWithClause_single() { |
| 3323 _assertSource("with A", AstFactory.withClause([AstFactory.typeName4("A")])); |
| 3324 } |
| 3325 |
| 3326 void test_visitYieldStatement() { |
| 3327 _assertSource( |
| 3328 "yield e;", AstFactory.yieldStatement(AstFactory.identifier3("e"))); |
| 3329 } |
| 3330 |
| 3331 void test_visitYieldStatement_each() { |
| 3332 _assertSource("yield* e;", |
| 3333 AstFactory.yieldEachStatement(AstFactory.identifier3("e"))); |
| 3334 } |
| 3335 |
| 3336 /** |
| 3337 * Assert that a `ToSourceVisitor2` will produce the [expectedSource] when |
| 3338 * visiting the given [node]. |
| 3339 */ |
| 3340 void _assertSource(String expectedSource, AstNode node) { |
| 3341 StringBuffer buffer = new StringBuffer(); |
| 3342 node.accept(new ToSourceVisitor2(buffer)); |
| 3343 expect(buffer.toString(), expectedSource); |
| 3344 } |
| 3345 } |
| 3346 |
| 3347 @reflectiveTest |
1112 class ToSourceVisitorTest extends EngineTestCase { | 3348 class ToSourceVisitorTest extends EngineTestCase { |
1113 void test_visitAdjacentStrings() { | 3349 void test_visitAdjacentStrings() { |
1114 _assertSource( | 3350 _assertSource( |
1115 "'a' 'b'", | 3351 "'a' 'b'", |
1116 AstFactory.adjacentStrings( | 3352 AstFactory.adjacentStrings( |
1117 [AstFactory.string2("a"), AstFactory.string2("b")])); | 3353 [AstFactory.string2("a"), AstFactory.string2("b")])); |
1118 } | 3354 } |
1119 | 3355 |
1120 void test_visitAnnotation_constant() { | 3356 void test_visitAnnotation_constant() { |
1121 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A"))); | 3357 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A"))); |
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3326 _assertSource( | 5562 _assertSource( |
3327 "yield e;", AstFactory.yieldStatement(AstFactory.identifier3("e"))); | 5563 "yield e;", AstFactory.yieldStatement(AstFactory.identifier3("e"))); |
3328 } | 5564 } |
3329 | 5565 |
3330 void test_visitYieldStatement_each() { | 5566 void test_visitYieldStatement_each() { |
3331 _assertSource("yield* e;", | 5567 _assertSource("yield* e;", |
3332 AstFactory.yieldEachStatement(AstFactory.identifier3("e"))); | 5568 AstFactory.yieldEachStatement(AstFactory.identifier3("e"))); |
3333 } | 5569 } |
3334 | 5570 |
3335 /** | 5571 /** |
3336 * Assert that a `ToSourceVisitor` will produce the expected source when visit
ing the given | 5572 * Assert that a `ToSourceVisitor` will produce the [expectedSource] when |
3337 * node. | 5573 * visiting the given [node]. |
3338 * | |
3339 * @param expectedSource the source string that the visitor is expected to pro
duce | |
3340 * @param node the AST node being visited to produce the actual source | |
3341 * @throws AFE if the visitor does not produce the expected source for the giv
en node | |
3342 */ | 5574 */ |
3343 void _assertSource(String expectedSource, AstNode node) { | 5575 void _assertSource(String expectedSource, AstNode node) { |
3344 PrintStringWriter writer = new PrintStringWriter(); | 5576 PrintStringWriter writer = new PrintStringWriter(); |
3345 node.accept(new ToSourceVisitor(writer)); | 5577 node.accept(new ToSourceVisitor(writer)); |
3346 expect(writer.toString(), expectedSource); | 5578 expect(writer.toString(), expectedSource); |
3347 } | 5579 } |
3348 } | 5580 } |
OLD | NEW |