浏览代码

Add unit tests for several cpp regressions (#5032)

* Add tests for #4310, #4343, #4985, #4986, #4987 and #4988

* Add tests for #5023, #5025, #5030, #5043 and #5044

closes #5025
closes #5030

* Disable #4988 test on PHP for now

* Add a test for #5028

* Add tests for #5078 and #5108

* Consistent tab indent

* Avoid redefinition error

* Fix some stuff

* More test exclusions, remove the tests for #5023 / #5043

misc/projects is only for --macro unfortunately

* Try to get php and lua under control

* Ok, Lua should be ok now..

* Behave PHP!

* Just remove #4985 for now...

* Add a test for #5543

* Fix a cpp runtime crash in Issue5025.hx

* Add a (slightly modified) version of 4985 again

* Revert "Add a (slightly modified) version of 4985 again"

This reverts commit 9f7c56d053acfc765fa376ca3681bd6ce7c2010a.
Gama11 9 年之前
父节点
当前提交
ea1162cfd3

+ 14 - 0
tests/unit/src/unit/issues/Issue4310.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+
+class BaseClass {
+	public function new() {}
+}
+
+class Child1 extends BaseClass {}
+
+class Issue4310 extends Test {
+	function test() {
+		var child1:BaseClass = new Child1();
+		cast(child1, BaseClass);
+	}
+}

+ 22 - 0
tests/unit/src/unit/issues/Issue4343.hx

@@ -0,0 +1,22 @@
+package unit.issues;
+
+class Issue4343 extends Test {
+	function test() {
+		(new SomeObject() : ISomeObject).call();
+	}
+}
+
+class SomeObject implements ISomeObject {
+	public function new() {}
+	public function call():Void {}
+}
+
+interface ISomeObject extends IEmtpyExtendsCallable extends IEmpty {}
+
+interface IEmpty {}
+
+interface IEmtpyExtendsCallable extends ICallable {}
+
+interface ICallable {
+	public function call():Void;
+}

+ 12 - 0
tests/unit/src/unit/issues/Issue4986.hx

@@ -0,0 +1,12 @@
+package unit.issues;
+
+class Issue4986 extends Test {
+	function test() {
+		try {
+			var v = new haxe.ds.Vector<Array<Float>>(1);
+			foo(v[0].length);
+		} catch (e:Dynamic) {}
+	}
+
+	function foo(_) {}
+}

+ 18 - 0
tests/unit/src/unit/issues/Issue4987.hx

@@ -0,0 +1,18 @@
+package unit.issues;
+
+class Issue4987 extends Test implements ISetter implements ISetter2 {
+	public var property(default, set):Int;
+	function set_property(i) return 0;
+
+	function test() {
+		property = 0;
+	}
+}
+
+interface ISetter {
+	var property(default, set):Int;
+}
+
+interface ISetter2 {
+	var property(default, set):Int;
+}

+ 14 - 0
tests/unit/src/unit/issues/Issue4988.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+
+class Issue4988 extends Test {
+	function test() {
+		#if !(php || lua)
+		try {
+			var d:{i:Null<Int>} = null;
+			foo(d.i > 0);
+		} catch (e:Dynamic) {}
+		#end
+	}
+
+	function foo(_) {}
+}

+ 22 - 0
tests/unit/src/unit/issues/Issue5025.hx

@@ -0,0 +1,22 @@
+package unit.issues;
+
+class Issue5025 extends Test {
+	function test() {
+		// nothing to do here, we just want to see if the switch (null) compiles
+	}
+
+	function shouldCompile() {
+		#if !(java || cs || as3 || lua)
+		try {
+			switch (null) {
+				case Value(i):
+					trace(i);
+			}
+		} catch (e:Dynamic) {}
+		#end
+	}
+}
+
+enum SomeEnum {
+	Value(i:Int);
+}

+ 13 - 0
tests/unit/src/unit/issues/Issue5028.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue5028 extends Test {
+	var data:Data = { f: -1 };
+
+	function test() {
+		t(Math.random() > data.f);
+	}
+}
+
+typedef Data = {
+    ?f:Float
+}

+ 23 - 0
tests/unit/src/unit/issues/Issue5030.hx

@@ -0,0 +1,23 @@
+package unit.issues;
+
+class Issue5030 extends Test {
+	function test() {
+		t(isX());
+	}
+
+	@:analyzer(no_const_propagation)
+	function isX() {
+		var input:Input = { axis: X };
+		var b:Bool = true;
+		return (input.axis == X) ? b: false;
+	}
+}
+
+enum XY {
+	X;
+	Y;
+}
+
+typedef Input = {
+	var axis:XY;
+}

+ 14 - 0
tests/unit/src/unit/issues/Issue5044.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+
+class Issue5044 extends Test {
+	function test() {
+		var i = Int(5);
+		eq(5, switch (i) {
+			case Int(v): v;
+		});
+	}
+}
+
+enum TokenDef {
+	Int(v:Int);
+}

+ 13 - 0
tests/unit/src/unit/issues/Issue5078.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue5078 extends Test {
+	#if !(js || php || lua)
+	static function getToLower() return "ABC".toLowerCase;
+	#end
+
+	function test() {
+		#if !(js || php || lua)
+		eq(getToLower()(), "abc");
+		#end
+	}
+}

+ 20 - 0
tests/unit/src/unit/issues/Issue5108.hx

@@ -0,0 +1,20 @@
+package unit.issues;
+
+class Issue5108 extends Test {
+	function test() {
+		// nothing to do here
+	}
+}
+
+class Signal implements ISignal {   
+	public function add(listener:Void->Void):Void {}
+	public function destroy():Void {}
+}
+
+interface ISignal extends IDestroyable2 {
+	public function add(listener:Void->Void):Void;
+}
+
+interface IDestroyable2 {
+	public function destroy():Void;
+}

+ 17 - 0
tests/unit/src/unit/issues/Issue5543.hx

@@ -0,0 +1,17 @@
+package unit.issues;
+
+class Issue5543 extends Test {
+	function test() {
+		f1({ i: 5 });
+	}
+
+	static function f1(n:NullableInt) {
+		f2(n.i);
+	}
+
+	static function f2(i:Int = 0) {}
+}
+
+typedef NullableInt = {
+	?i:Int
+}