Chromium Code Reviews| Index: pkg/analyzer/test/src/summary/summary_test.dart |
| diff --git a/pkg/analyzer/test/src/summary/summary_test.dart b/pkg/analyzer/test/src/summary/summary_test.dart |
| index 416978a5b1f774c4be35ac044ff82b616d2e25a4..c514d844b0292345e0cbd6dab62a55dd51dde750 100644 |
| --- a/pkg/analyzer/test/src/summary/summary_test.dart |
| +++ b/pkg/analyzer/test/src/summary/summary_test.dart |
| @@ -82,6 +82,8 @@ UnlinkedPublicNamespace computePublicNamespaceFromText( |
| return namespace; |
| } |
| +typedef bool _UnlinkedTypeRefPredicate(UnlinkedTypeRef unlinkedTypeRef); |
| + |
| /** |
| * Override of [SummaryTest] which verifies the correctness of the prelinker by |
| * creating summaries from the element model, discarding their prelinked |
| @@ -112,9 +114,10 @@ class PrelinkerTest extends SummarizeElementsTest { |
| summarize_elements.serializeLibrary( |
| library, analysisContext.typeProvider); |
| for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) { |
| - uriToNamespace[ |
| - serializedLibrary.unitUris[i]] = new UnlinkedUnit.fromBuffer( |
| - serializedLibrary.unlinkedUnits[i].toBuffer()).publicNamespace; |
| + uriToNamespace[serializedLibrary.unitUris[i]] = |
| + new UnlinkedUnit.fromBuffer( |
| + serializedLibrary.unlinkedUnits[i].toBuffer()) |
| + .publicNamespace; |
| } |
| } |
| return uriToNamespace; |
| @@ -819,7 +822,8 @@ b.C c4;'''); |
| UnlinkedTypeRef serializeTypeText(String text, |
| {String otherDeclarations: '', bool allowErrors: false}) { |
| return serializeVariableText('$otherDeclarations\n$text v;', |
| - allowErrors: allowErrors).type; |
| + allowErrors: allowErrors) |
| + .type; |
| } |
| /** |
| @@ -1239,6 +1243,662 @@ class E {} |
| expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1); |
| } |
| + test_constExpr_binary_add() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 + 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.add |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_and() { |
| + UnlinkedVariable variable = |
| + serializeVariableText('const v = true && false;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushTrue, |
| + UnlinkedConstOperation.pushFalse, |
| + UnlinkedConstOperation.and |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_bitAnd() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 & 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.bitAnd |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_bitOr() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 | 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.bitOr |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_bitShiftLeft() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 << 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.bitShiftLeft |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_bitShiftRight() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 >> 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.bitShiftRight |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_bitXor() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 ^ 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.bitXor |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_divide() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 / 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.divide |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_equal() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 == 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.equal |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_equal_not() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 != 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.equal, |
| + UnlinkedConstOperation.not |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_floorDivide() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 ~/ 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.floorDivide |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_greater() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 > 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.greater |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_greaterEqual() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 >= 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.greaterEqual |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_less() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 < 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.less |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_lessEqual() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 <= 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.lessEqual |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_modulo() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 % 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.modulo |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_multiply() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 * 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.multiply |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_or() { |
| + UnlinkedVariable variable = |
| + serializeVariableText('const v = false || true;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushFalse, |
| + UnlinkedConstOperation.pushTrue, |
| + UnlinkedConstOperation.or |
| + ]); |
| + } |
| + |
| + test_constExpr_binary_subtract() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1 - 2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.subtract |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_conditional() { |
| + UnlinkedVariable variable = |
| + serializeVariableText('const v = true ? 1 : 2;', allowErrors: true); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushTrue, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.conditional |
| + ], ints: [ |
| + 1, |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_identical() { |
| + UnlinkedVariable variable = |
| + serializeVariableText('const v = identical(42, null);'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushNull, |
| + UnlinkedConstOperation.identical |
| + ], ints: [ |
| + 42 |
| + ]); |
| + } |
| + |
| + test_constExpr_invokeConstructor_named() { |
| + UnlinkedVariable variable = serializeVariableText(''' |
| +class C { |
| + const C.named(); |
| +} |
| +const v = const C.named(); |
| +'''); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.invokeConstructor, |
| + ], ints: [ |
| + 0 |
| + ], strings: [ |
| + 'named' |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C', |
| + expectedKind: ReferenceKind.classOrEnum) |
| + ]); |
| + } |
| + |
| + test_constExpr_invokeConstructor_named_imported() { |
| + addNamedSource( |
| + '/a.dart', |
| + ''' |
| +class C { |
| + const C.named(); |
| +} |
| +'''); |
| + UnlinkedVariable variable = serializeVariableText(''' |
| +import 'a.dart'; |
| +const v = const C.named(); |
| +'''); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.invokeConstructor, |
| + ], ints: [ |
| + 0 |
| + ], strings: [ |
| + 'named' |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C', |
| + expectedKind: ReferenceKind.classOrEnum) |
| + ]); |
| + } |
| + |
| + test_constExpr_invokeConstructor_named_imported_withPrefix() { |
| + addNamedSource( |
| + '/a.dart', |
| + ''' |
| +class C { |
| + const C.named(); |
| +} |
| +'''); |
| + UnlinkedVariable variable = serializeVariableText(''' |
| +import 'a.dart' as p; |
| +const v = const p.C.named(); |
| +'''); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.invokeConstructor, |
| + ], ints: [ |
| + 0 |
| + ], strings: [ |
| + 'named' |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C', |
| + expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'p') |
| + ]); |
| + } |
| + |
| + test_constExpr_invokeConstructor_unnamed() { |
| + UnlinkedVariable variable = serializeVariableText(''' |
| +class C { |
| + const C(int a, String b); |
| +} |
| +const v = const C(42, 'sss'); |
| +'''); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.invokeConstructor, |
| + ], ints: [ |
| + 42, |
| + 2 |
| + ], strings: [ |
| + 'sss', |
| + '' |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C', |
| + expectedKind: ReferenceKind.classOrEnum) |
| + ]); |
| + } |
| + |
| + test_constExpr_length() { |
| + UnlinkedVariable variable = |
| + serializeVariableText('const v = "abc".length;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.length |
| + ], strings: [ |
| + 'abc' |
| + ]); |
| + } |
| + |
| + test_constExpr_makeList_typed() { |
| + UnlinkedVariable variable = |
| + serializeVariableText('const v = const <int>[11, 22, 33];'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.makeList |
| + ], ints: [ |
| + 11, |
| + 22, |
| + 33, |
| + 3 |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int', |
| + expectedKind: ReferenceKind.classOrEnum) |
| + ]); |
| + } |
| + |
| + test_constExpr_makeList_untyped() { |
| + UnlinkedVariable variable = |
| + serializeVariableText('const v = const [11, 22, 33];'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.makeList |
| + ], ints: [ |
| + 11, |
| + 22, |
| + 33, |
| + 3 |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '', |
| + expectedKind: ReferenceKind.classOrEnum) |
| + ]); |
| + } |
| + |
| + test_constExpr_makeMap_typed() { |
| + UnlinkedVariable variable = serializeVariableText( |
| + 'const v = const <int, String>{11: "aaa", 22: "bbb", 33: "ccc"};'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.makeMap |
| + ], ints: [ |
| + 11, |
| + 22, |
| + 33, |
| + 3 |
| + ], strings: [ |
| + 'aaa', |
| + 'bbb', |
| + 'ccc' |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int', |
| + expectedKind: ReferenceKind.classOrEnum), |
| + (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'String', |
| + expectedKind: ReferenceKind.classOrEnum) |
| + ]); |
| + } |
| + |
| + test_constExpr_makeMap_untyped() { |
| + UnlinkedVariable variable = serializeVariableText( |
| + 'const v = const {11: "aaa", 22: "bbb", 33: "ccc"};'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.makeMap |
| + ], ints: [ |
| + 11, |
| + 22, |
| + 33, |
| + 3 |
| + ], strings: [ |
| + 'aaa', |
| + 'bbb', |
| + 'ccc' |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '', |
| + expectedKind: ReferenceKind.classOrEnum), |
| + (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '', |
| + expectedKind: ReferenceKind.classOrEnum) |
| + ]); |
| + } |
| + |
| + test_constExpr_makeSymbol() { |
| + UnlinkedVariable variable = serializeVariableText('const v = #a.bb.ccc;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.makeSymbol |
| + ], ints: [ |
| + 3 |
| + ], strings: [ |
| + 'a', |
| + 'bb', |
| + 'ccc' |
| + ]); |
| + } |
| + |
| + test_constExpr_parenthesized() { |
| + UnlinkedVariable variable = serializeVariableText('const v = (1 + 2) * 3;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.add, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.multiply, |
| + ], ints: [ |
| + 1, |
| + 2, |
| + 3 |
| + ]); |
| + } |
| + |
| + test_constExpr_prefix_complement() { |
| + UnlinkedVariable variable = serializeVariableText('const v = ~2;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.complement |
| + ], ints: [ |
| + 2 |
| + ]); |
| + } |
| + |
| + test_constExpr_prefix_not() { |
| + UnlinkedVariable variable = serializeVariableText('const v = !true;'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushTrue, |
| + UnlinkedConstOperation.not |
| + ]); |
| + } |
| + |
| + test_constExpr_pushDouble() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 123.4567;'); |
| + _assertUnlinkedConst(variable.constExpr, |
| + operators: [UnlinkedConstOperation.pushDouble], doubles: [123.4567]); |
| + } |
| + |
| + test_constExpr_pushFalse() { |
| + UnlinkedVariable variable = serializeVariableText('const v = false;'); |
| + _assertUnlinkedConst(variable.constExpr, |
| + operators: [UnlinkedConstOperation.pushFalse]); |
| + } |
| + |
| + test_constExpr_pushInt() { |
| + UnlinkedVariable variable = serializeVariableText('const v = 1;'); |
| + _assertUnlinkedConst(variable.constExpr, |
| + operators: [UnlinkedConstOperation.pushInt], ints: [1]); |
| + } |
| + |
| + test_constExpr_pushInt_shiftOr() { |
| + UnlinkedVariable variable = |
| + serializeVariableText('const v = 0x111222333444555666;'); |
| + // ^^!!!!^^^^!!!!^^^^ |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.shiftOr, |
| + UnlinkedConstOperation.shiftOr |
| + ], ints: [ |
| + 0x11, |
| + 0x12223334, |
| + 0x44555666 |
| + ]); |
| + } |
| + |
| + test_constExpr_pushNull() { |
| + UnlinkedVariable variable = serializeVariableText('const v = null;'); |
| + _assertUnlinkedConst(variable.constExpr, |
| + operators: [UnlinkedConstOperation.pushNull]); |
| + } |
| + |
| + test_constExpr_pushReference_class() { |
| + UnlinkedVariable variable = serializeVariableText(''' |
| +class C {} |
| +const v = C; |
| +'''); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushReference |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C', |
| + expectedKind: ReferenceKind.classOrEnum) |
| + ]); |
| + } |
| + |
| + test_constExpr_pushReference_class_field() { |
| + // TODO(scheglov) Not sure for to represent a field reference |
|
Paul Berry
2016/01/19 20:02:10
Yeah, I haven't figured out how to do this either.
|
| + // using UnlinkedTypeRef. |
| +// UnlinkedVariable variable = serializeVariableText(''' |
| +//class C { |
| +// static const int F = 1; |
| +//} |
| +//const v = C.F; |
| +//'''); |
| +// _assertUnlinkedConst(variable.constExpr, operators: [ |
| +// UnlinkedConstOperation.pushReference |
| +// ], references: [ |
| +// (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'F', |
| +// expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'C') |
| +// ]); |
| + } |
| + |
| + test_constExpr_pushReference_enum() { |
| + UnlinkedVariable variable = serializeVariableText(''' |
| +enum C {V1, V2, V3} |
| +const v = C; |
| +'''); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushReference |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C', |
| + expectedKind: ReferenceKind.classOrEnum) |
| + ]); |
| + } |
| + |
| + test_constExpr_pushReference_topLevelVariable_imported() { |
| + addNamedSource('/a.dart', 'const int a = 1;'); |
| + UnlinkedVariable variable = serializeVariableText(''' |
| +import 'a.dart'; |
| +const v = a; |
| +'''); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushReference |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', |
| + expectedKind: ReferenceKind.topLevelPropertyAccessor) |
| + ]); |
| + } |
| + |
| + test_constExpr_pushReference_topLevelVariable_imported_withPrefix() { |
| + addNamedSource('/a.dart', 'const int a = 1;'); |
| + UnlinkedVariable variable = serializeVariableText(''' |
| +import 'a.dart' as p; |
| +const v = p.a; |
| +'''); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushReference |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', |
| + expectedKind: ReferenceKind.topLevelPropertyAccessor, |
| + expectedPrefix: 'p') |
| + ]); |
| + } |
| + |
| + test_constExpr_pushReference_topLevelVariable_local() { |
| + // TODO(scheglov) use `a + b` |
| + UnlinkedVariable variable = serializeVariableText(''' |
| +const int a = 1; |
| +const v = a; |
| +'''); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushReference |
| + ], references: [ |
| + (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'a', |
| + expectedKind: ReferenceKind.topLevelPropertyAccessor) |
| + ]); |
| + } |
| + |
| + test_constExpr_pushString_adjacent() { |
| + UnlinkedVariable variable = |
| + serializeVariableText('const v = "aaa" "b" "ccc";'); |
| + _assertUnlinkedConst(variable.constExpr, |
| + operators: [UnlinkedConstOperation.pushString], strings: ['aaabccc']); |
| + } |
| + |
| + test_constExpr_pushString_interpolation() { |
| + UnlinkedVariable variable = |
| + serializeVariableText(r'const v = "aaa ${42} bbb";'); |
| + _assertUnlinkedConst(variable.constExpr, operators: [ |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.pushInt, |
| + UnlinkedConstOperation.pushString, |
| + UnlinkedConstOperation.concatenate |
| + ], ints: [ |
| + 42, |
| + 3 |
| + ], strings: [ |
| + 'aaa ', |
| + ' bbb' |
| + ]); |
| + } |
| + |
| + test_constExpr_pushString_simple() { |
| + UnlinkedVariable variable = serializeVariableText('const v = "abc";'); |
| + _assertUnlinkedConst(variable.constExpr, |
| + operators: [UnlinkedConstOperation.pushString], strings: ['abc']); |
| + } |
| + |
| + test_constExpr_pushTrue() { |
| + UnlinkedVariable variable = serializeVariableText('const v = true;'); |
| + _assertUnlinkedConst(variable.constExpr, |
| + operators: [UnlinkedConstOperation.pushTrue]); |
| + } |
| + |
| test_constructor() { |
| String text = 'class C { C(); }'; |
| UnlinkedExecutable executable = |
| @@ -1903,7 +2563,8 @@ enum E { v }'''; |
| test_executable_operator_index_set() { |
| UnlinkedExecutable executable = serializeClassText( |
| - 'class C { void operator[]=(int i, bool v) => null; }').executables[0]; |
| + 'class C { void operator[]=(int i, bool v) => null; }') |
| + .executables[0]; |
| expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); |
| expect(executable.name, '[]='); |
| expect(executable.hasImplicitReturnType, false); |
| @@ -2370,6 +3031,8 @@ enum E { v }'''; |
| UnlinkedVariable variable = |
| serializeClassText('class C { static const int i = 0; }').fields[0]; |
| expect(variable.isConst, isTrue); |
| + _assertUnlinkedConst(variable.constExpr, |
| + operators: [UnlinkedConstOperation.pushInt], ints: [0]); |
| } |
| test_field_documented() { |
| @@ -3164,4 +3827,21 @@ var v;'''; |
| serializeVariableText('int _i;', variableName: '_i'); |
| expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| } |
| + |
| + void _assertUnlinkedConst(UnlinkedConst constExpr, |
| + {List<UnlinkedConstOperation> operators, |
| + List<int> ints: const <int>[], |
| + List<double> doubles: const <double>[], |
| + List<String> strings: const <String>[], |
| + List<_UnlinkedTypeRefPredicate> references: |
| + const <_UnlinkedTypeRefPredicate>[]}) { |
| + expect(constExpr.operations, operators); |
| + expect(constExpr.ints, ints); |
| + expect(constExpr.doubles, doubles); |
| + expect(constExpr.strings, strings); |
| + expect(constExpr.references, hasLength(references.length)); |
| + for (int i = 0; i < references.length; i++) { |
| + references[i](constExpr.references[i]); |
|
Paul Berry
2016/01/19 20:02:10
I think you might mean:
expect(references[i](cons
scheglov
2016/01/19 20:59:28
Nesting `expect` invocations does not work well.
S
|
| + } |
| + } |
| } |