Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: pkg/analyzer/test/src/dart/constant/evaluation_test.dart

Issue 2524903002: Rename AstFactory -> AstTestFactory. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.constant_test; 5 library analyzer.test.constant_test;
6 6
7 import 'package:analyzer/context/declared_variables.dart'; 7 import 'package:analyzer/context/declared_variables.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/ast/token.dart'; 9 import 'package:analyzer/dart/ast/token.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/error/error.dart'; 11 import 'package:analyzer/error/error.dart';
12 import 'package:analyzer/error/listener.dart'; 12 import 'package:analyzer/error/listener.dart';
13 import 'package:analyzer/src/dart/element/element.dart'; 13 import 'package:analyzer/src/dart/element/element.dart';
14 import 'package:analyzer/src/error/codes.dart'; 14 import 'package:analyzer/src/error/codes.dart';
15 import 'package:analyzer/src/generated/constant.dart'; 15 import 'package:analyzer/src/generated/constant.dart';
16 import 'package:analyzer/src/generated/engine.dart'; 16 import 'package:analyzer/src/generated/engine.dart';
17 import 'package:analyzer/src/generated/resolver.dart'; 17 import 'package:analyzer/src/generated/resolver.dart';
18 import 'package:analyzer/src/generated/source.dart'; 18 import 'package:analyzer/src/generated/source.dart';
19 import 'package:analyzer/src/generated/source_io.dart'; 19 import 'package:analyzer/src/generated/source_io.dart';
20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 20 import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
21 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; 21 import 'package:analyzer/src/generated/testing/test_type_provider.dart';
22 import 'package:analyzer/src/task/dart.dart'; 22 import 'package:analyzer/src/task/dart.dart';
23 import 'package:path/path.dart'; 23 import 'package:path/path.dart';
24 import 'package:test/test.dart'; 24 import 'package:test/test.dart';
25 import 'package:test_reflective_loader/test_reflective_loader.dart'; 25 import 'package:test_reflective_loader/test_reflective_loader.dart';
26 26
27 import '../../../generated/resolver_test_case.dart'; 27 import '../../../generated/resolver_test_case.dart';
28 import '../../../generated/test_support.dart'; 28 import '../../../generated/test_support.dart';
29 29
30 main() { 30 main() {
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 } else { 1400 } else {
1401 expect(result.value, isNull); 1401 expect(result.value, isNull);
1402 } 1402 }
1403 } 1403 }
1404 } 1404 }
1405 } 1405 }
1406 1406
1407 @reflectiveTest 1407 @reflectiveTest
1408 class ConstantVisitorTest extends ResolverTestCase { 1408 class ConstantVisitorTest extends ResolverTestCase {
1409 void test_visitBinaryExpression_questionQuestion_notNull_notNull() { 1409 void test_visitBinaryExpression_questionQuestion_notNull_notNull() {
1410 Expression left = AstFactory.string2('a'); 1410 Expression left = AstTestFactory.string2('a');
1411 Expression right = AstFactory.string2('b'); 1411 Expression right = AstTestFactory.string2('b');
1412 Expression expression = 1412 Expression expression = AstTestFactory.binaryExpression(
1413 AstFactory.binaryExpression(left, TokenType.QUESTION_QUESTION, right); 1413 left, TokenType.QUESTION_QUESTION, right);
1414 1414
1415 GatheringErrorListener errorListener = new GatheringErrorListener(); 1415 GatheringErrorListener errorListener = new GatheringErrorListener();
1416 ErrorReporter errorReporter = 1416 ErrorReporter errorReporter =
1417 new ErrorReporter(errorListener, _dummySource()); 1417 new ErrorReporter(errorListener, _dummySource());
1418 DartObjectImpl result = _evaluate(expression, errorReporter); 1418 DartObjectImpl result = _evaluate(expression, errorReporter);
1419 expect(result, isNotNull); 1419 expect(result, isNotNull);
1420 expect(result.isNull, isFalse); 1420 expect(result.isNull, isFalse);
1421 expect(result.toStringValue(), 'a'); 1421 expect(result.toStringValue(), 'a');
1422 errorListener.assertNoErrors(); 1422 errorListener.assertNoErrors();
1423 } 1423 }
1424 1424
1425 void test_visitBinaryExpression_questionQuestion_null_notNull() { 1425 void test_visitBinaryExpression_questionQuestion_null_notNull() {
1426 Expression left = AstFactory.nullLiteral(); 1426 Expression left = AstTestFactory.nullLiteral();
1427 Expression right = AstFactory.string2('b'); 1427 Expression right = AstTestFactory.string2('b');
1428 Expression expression = 1428 Expression expression = AstTestFactory.binaryExpression(
1429 AstFactory.binaryExpression(left, TokenType.QUESTION_QUESTION, right); 1429 left, TokenType.QUESTION_QUESTION, right);
1430 1430
1431 GatheringErrorListener errorListener = new GatheringErrorListener(); 1431 GatheringErrorListener errorListener = new GatheringErrorListener();
1432 ErrorReporter errorReporter = 1432 ErrorReporter errorReporter =
1433 new ErrorReporter(errorListener, _dummySource()); 1433 new ErrorReporter(errorListener, _dummySource());
1434 DartObjectImpl result = _evaluate(expression, errorReporter); 1434 DartObjectImpl result = _evaluate(expression, errorReporter);
1435 expect(result, isNotNull); 1435 expect(result, isNotNull);
1436 expect(result.isNull, isFalse); 1436 expect(result.isNull, isFalse);
1437 expect(result.toStringValue(), 'b'); 1437 expect(result.toStringValue(), 'b');
1438 errorListener.assertNoErrors(); 1438 errorListener.assertNoErrors();
1439 } 1439 }
1440 1440
1441 void test_visitBinaryExpression_questionQuestion_null_null() { 1441 void test_visitBinaryExpression_questionQuestion_null_null() {
1442 Expression left = AstFactory.nullLiteral(); 1442 Expression left = AstTestFactory.nullLiteral();
1443 Expression right = AstFactory.nullLiteral(); 1443 Expression right = AstTestFactory.nullLiteral();
1444 Expression expression = 1444 Expression expression = AstTestFactory.binaryExpression(
1445 AstFactory.binaryExpression(left, TokenType.QUESTION_QUESTION, right); 1445 left, TokenType.QUESTION_QUESTION, right);
1446 1446
1447 GatheringErrorListener errorListener = new GatheringErrorListener(); 1447 GatheringErrorListener errorListener = new GatheringErrorListener();
1448 ErrorReporter errorReporter = 1448 ErrorReporter errorReporter =
1449 new ErrorReporter(errorListener, _dummySource()); 1449 new ErrorReporter(errorListener, _dummySource());
1450 DartObjectImpl result = _evaluate(expression, errorReporter); 1450 DartObjectImpl result = _evaluate(expression, errorReporter);
1451 expect(result, isNotNull); 1451 expect(result, isNotNull);
1452 expect(result.isNull, isTrue); 1452 expect(result.isNull, isTrue);
1453 errorListener.assertNoErrors(); 1453 errorListener.assertNoErrors();
1454 } 1454 }
1455 1455
1456 void test_visitConditionalExpression_false() { 1456 void test_visitConditionalExpression_false() {
1457 Expression thenExpression = AstFactory.integer(1); 1457 Expression thenExpression = AstTestFactory.integer(1);
1458 Expression elseExpression = AstFactory.integer(0); 1458 Expression elseExpression = AstTestFactory.integer(0);
1459 ConditionalExpression expression = AstFactory.conditionalExpression( 1459 ConditionalExpression expression = AstTestFactory.conditionalExpression(
1460 AstFactory.booleanLiteral(false), thenExpression, elseExpression); 1460 AstTestFactory.booleanLiteral(false), thenExpression, elseExpression);
1461 GatheringErrorListener errorListener = new GatheringErrorListener(); 1461 GatheringErrorListener errorListener = new GatheringErrorListener();
1462 ErrorReporter errorReporter = 1462 ErrorReporter errorReporter =
1463 new ErrorReporter(errorListener, _dummySource()); 1463 new ErrorReporter(errorListener, _dummySource());
1464 _assertValue(0, _evaluate(expression, errorReporter)); 1464 _assertValue(0, _evaluate(expression, errorReporter));
1465 errorListener.assertNoErrors(); 1465 errorListener.assertNoErrors();
1466 } 1466 }
1467 1467
1468 void test_visitConditionalExpression_nonBooleanCondition() { 1468 void test_visitConditionalExpression_nonBooleanCondition() {
1469 Expression thenExpression = AstFactory.integer(1); 1469 Expression thenExpression = AstTestFactory.integer(1);
1470 Expression elseExpression = AstFactory.integer(0); 1470 Expression elseExpression = AstTestFactory.integer(0);
1471 NullLiteral conditionExpression = AstFactory.nullLiteral(); 1471 NullLiteral conditionExpression = AstTestFactory.nullLiteral();
1472 ConditionalExpression expression = AstFactory.conditionalExpression( 1472 ConditionalExpression expression = AstTestFactory.conditionalExpression(
1473 conditionExpression, thenExpression, elseExpression); 1473 conditionExpression, thenExpression, elseExpression);
1474 GatheringErrorListener errorListener = new GatheringErrorListener(); 1474 GatheringErrorListener errorListener = new GatheringErrorListener();
1475 ErrorReporter errorReporter = 1475 ErrorReporter errorReporter =
1476 new ErrorReporter(errorListener, _dummySource()); 1476 new ErrorReporter(errorListener, _dummySource());
1477 DartObjectImpl result = _evaluate(expression, errorReporter); 1477 DartObjectImpl result = _evaluate(expression, errorReporter);
1478 expect(result, isNull); 1478 expect(result, isNull);
1479 errorListener 1479 errorListener
1480 .assertErrorsWithCodes([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL]); 1480 .assertErrorsWithCodes([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL]);
1481 } 1481 }
1482 1482
1483 void test_visitConditionalExpression_nonConstantElse() { 1483 void test_visitConditionalExpression_nonConstantElse() {
1484 Expression thenExpression = AstFactory.integer(1); 1484 Expression thenExpression = AstTestFactory.integer(1);
1485 Expression elseExpression = AstFactory.identifier3("x"); 1485 Expression elseExpression = AstTestFactory.identifier3("x");
1486 ConditionalExpression expression = AstFactory.conditionalExpression( 1486 ConditionalExpression expression = AstTestFactory.conditionalExpression(
1487 AstFactory.booleanLiteral(true), thenExpression, elseExpression); 1487 AstTestFactory.booleanLiteral(true), thenExpression, elseExpression);
1488 GatheringErrorListener errorListener = new GatheringErrorListener(); 1488 GatheringErrorListener errorListener = new GatheringErrorListener();
1489 ErrorReporter errorReporter = 1489 ErrorReporter errorReporter =
1490 new ErrorReporter(errorListener, _dummySource()); 1490 new ErrorReporter(errorListener, _dummySource());
1491 DartObjectImpl result = _evaluate(expression, errorReporter); 1491 DartObjectImpl result = _evaluate(expression, errorReporter);
1492 expect(result, isNull); 1492 expect(result, isNull);
1493 errorListener 1493 errorListener
1494 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); 1494 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]);
1495 } 1495 }
1496 1496
1497 void test_visitConditionalExpression_nonConstantThen() { 1497 void test_visitConditionalExpression_nonConstantThen() {
1498 Expression thenExpression = AstFactory.identifier3("x"); 1498 Expression thenExpression = AstTestFactory.identifier3("x");
1499 Expression elseExpression = AstFactory.integer(0); 1499 Expression elseExpression = AstTestFactory.integer(0);
1500 ConditionalExpression expression = AstFactory.conditionalExpression( 1500 ConditionalExpression expression = AstTestFactory.conditionalExpression(
1501 AstFactory.booleanLiteral(true), thenExpression, elseExpression); 1501 AstTestFactory.booleanLiteral(true), thenExpression, elseExpression);
1502 GatheringErrorListener errorListener = new GatheringErrorListener(); 1502 GatheringErrorListener errorListener = new GatheringErrorListener();
1503 ErrorReporter errorReporter = 1503 ErrorReporter errorReporter =
1504 new ErrorReporter(errorListener, _dummySource()); 1504 new ErrorReporter(errorListener, _dummySource());
1505 DartObjectImpl result = _evaluate(expression, errorReporter); 1505 DartObjectImpl result = _evaluate(expression, errorReporter);
1506 expect(result, isNull); 1506 expect(result, isNull);
1507 errorListener 1507 errorListener
1508 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); 1508 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]);
1509 } 1509 }
1510 1510
1511 void test_visitConditionalExpression_true() { 1511 void test_visitConditionalExpression_true() {
1512 Expression thenExpression = AstFactory.integer(1); 1512 Expression thenExpression = AstTestFactory.integer(1);
1513 Expression elseExpression = AstFactory.integer(0); 1513 Expression elseExpression = AstTestFactory.integer(0);
1514 ConditionalExpression expression = AstFactory.conditionalExpression( 1514 ConditionalExpression expression = AstTestFactory.conditionalExpression(
1515 AstFactory.booleanLiteral(true), thenExpression, elseExpression); 1515 AstTestFactory.booleanLiteral(true), thenExpression, elseExpression);
1516 GatheringErrorListener errorListener = new GatheringErrorListener(); 1516 GatheringErrorListener errorListener = new GatheringErrorListener();
1517 ErrorReporter errorReporter = 1517 ErrorReporter errorReporter =
1518 new ErrorReporter(errorListener, _dummySource()); 1518 new ErrorReporter(errorListener, _dummySource());
1519 _assertValue(1, _evaluate(expression, errorReporter)); 1519 _assertValue(1, _evaluate(expression, errorReporter));
1520 errorListener.assertNoErrors(); 1520 errorListener.assertNoErrors();
1521 } 1521 }
1522 1522
1523 void test_visitSimpleIdentifier_className() { 1523 void test_visitSimpleIdentifier_className() {
1524 CompilationUnit compilationUnit = resolveSource(''' 1524 CompilationUnit compilationUnit = resolveSource('''
1525 const a = C; 1525 const a = C;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 } 1604 }
1605 } 1605 }
1606 1606
1607 @reflectiveTest 1607 @reflectiveTest
1608 class StrongConstantValueComputerTest extends ConstantValueComputerTest { 1608 class StrongConstantValueComputerTest extends ConstantValueComputerTest {
1609 void setUp() { 1609 void setUp() {
1610 super.setUp(); 1610 super.setUp();
1611 resetWithOptions(new AnalysisOptionsImpl()..strongMode = true); 1611 resetWithOptions(new AnalysisOptionsImpl()..strongMode = true);
1612 } 1612 }
1613 } 1613 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/dart/ast/utilities_test.dart ('k') | pkg/analyzer/test/src/dart/constant/utilities_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698