Bladeren bron

add some enum value propagation tests

Simon Krajewski 10 jaren geleden
bovenliggende
commit
2a310f5003
1 gewijzigde bestanden met toevoegingen van 33 en 0 verwijderingen
  1. 33 0
      tests/optimization/src/TestJs.hx

+ 33 - 0
tests/optimization/src/TestJs.hx

@@ -1,3 +1,14 @@
+private enum Tree<T> {
+	Node(l:Tree<T>, r:Tree<T>);
+	Leaf(v:T);
+}
+
+private enum Some {
+    one(s1:String);
+    pair(s1:String, s2:String);
+    triad(s1:String, s2:String, s3:String);
+}
+
 class TestJs {
 	//@:js('var x = 10;"" + x;var x1 = 10;"" + x1;var x2 = 10.0;"" + x2;var x3 = "10";x3;var x4 = true;"" + x4;')
 	//static function testStdString() {
@@ -72,4 +83,26 @@ class TestJs {
 			default: throw false;
 		}
 	}
+
+	@:js('console.log("1" + "2" + "3" + "4");')
+	static function testEnumValuePropagation1() {
+		var n = Node(Node(Leaf("1"), Node(Leaf("2"), Leaf("3"))), Leaf("4"));
+		switch (n) {
+			case Node(Node(Leaf(s1), Node(Leaf(s2), Leaf(s3))), Leaf(s4)):
+				trace(s1 + s2 + s3 + s4);
+			case _:
+		}
+	}
+
+	@:js('false;')
+	static function testEnumValuePropagation2() {
+		var v = pair("foo", "bar");
+		var x = switch (v) {
+			case one(s1): verify(s1);
+			case pair(s1, s2): verify(s1) && verify(s2);
+			case triad(s1, s2, s3): verify(s1) && verify(s2) && verify(s3);
+		}
+	}
+
+	static inline function verify(s1) return s1 == "foo";
 }