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

Unified Diff: tests/compiler/dart2js/cpa_inference_test.dart

Issue 11093078: - Add support for binary operators (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: sync to head Created 8 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: tests/compiler/dart2js/cpa_inference_test.dart
diff --git a/tests/compiler/dart2js/cpa_inference_test.dart b/tests/compiler/dart2js/cpa_inference_test.dart
index a9b3c2b3a1ca4f32c0ea20d77bacdf19a862041e..c1fe32c79dee74083625b8b68ed41faf1a278f09 100644
--- a/tests/compiler/dart2js/cpa_inference_test.dart
+++ b/tests/compiler/dart2js/cpa_inference_test.dart
@@ -41,6 +41,7 @@ class AnalysisResult {
BaseType int;
BaseType double;
+ BaseType num;
BaseType bool;
BaseType string;
BaseType list;
@@ -51,6 +52,7 @@ class AnalysisResult {
inferrer = compiler.typesTask.concreteTypesInferrer;
int = inferrer.baseTypes.intBaseType;
double = inferrer.baseTypes.doubleBaseType;
+ num = inferrer.baseTypes.numBaseType;
bool = inferrer.baseTypes.boolBaseType;
string = inferrer.baseTypes.stringBaseType;
list = inferrer.baseTypes.listBaseType;
@@ -370,6 +372,51 @@ testNoReturn() {
result.checkNodeHasType('y', [result.nullType]);
}
+testArith() {
karlklose 2012/10/23 10:58:15 testArith -> testArithmethicOperators.
polux 2012/10/25 12:02:01 Done.
+ String source(op) {
+ return """
+ main() {
+ var a = 1 $op 2;
+ var b = 1 $op 2.0;
+ var c = 1.0 $op 2;
+ var d = 1.0 $op 2.0;
+ var e = (1 $op 2.0) $op 1;
+ var f = 1 $op (1 $op 2.0);
+ var g = (1 $op 2.0) $op 1.0;
+ var h = 1.0 $op (1 $op 2);
+ a; b; c; d; e; f; g; h;
karlklose 2012/10/23 10:58:15 Can you add positive nesting tests, like (1 op 2)
polux 2012/10/25 12:02:01 Done.
+ }""";
+ }
+ for (String op in ['+', '*', '-']) {
+ AnalysisResult result = analyze(source(op));
+ result.checkNodeHasType('a', [result.int]);
+ result.checkNodeHasType('b', [result.num]);
+ result.checkNodeHasType('c', [result.num]);
+ result.checkNodeHasType('d', [result.double]);
+ result.checkNodeHasType('e', [result.num]);
+ result.checkNodeHasType('f', [result.num]);
+ result.checkNodeHasType('g', [result.num]);
+ result.checkNodeHasType('h', [result.num]);
+ }
+}
+
+testOperators() {
+ final String source = r"""
+ class A {
+ operator <(x) => 42;
+ operator <<(x) => "a";
+ }
+ main() {
+ var x = new A() < "foo";
+ var y = new A() << "foo";
+ x; y;
+ }
+ """;
+ AnalysisResult result = analyze(source);
+ result.checkNodeHasType('x', [result.int]);
+ result.checkNodeHasType('y', [result.string]);
+}
+
void main() {
testLiterals();
testRedefinition();
@@ -387,4 +434,6 @@ void main() {
testMapLiterals();
testReturn();
// testNoReturn(); // right now we infer the empty type instead of null
+ testArith();
+ testOperators();
}

Powered by Google App Engine
This is Rietveld 408576698