Browse Source

[tests] add tests

closes #5207
closes #8984
closes #9123
Simon Krajewski 5 năm trước cách đây
mục cha
commit
d331c2c29d

+ 8 - 0
tests/unit/src/unit/issues/Issue5207.hx

@@ -0,0 +1,8 @@
+package unit.issues;
+
+class Issue5207 extends unit.Test {
+
+	function test() {
+		unit.issues.misc.Issue5207Macro.test();
+	}
+}

+ 11 - 0
tests/unit/src/unit/issues/Issue8984.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue8984 extends Test {
+	function test() {
+		var m = [1 => 'hello'];
+		iter(m);
+		utest.Assert.pass();
+	}
+
+	static function iter<T:Iterable<String>>(m:T) {}
+}

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

@@ -0,0 +1,20 @@
+package unit.issues;
+private typedef MyWrapper<T, C> = {val1:T, val2:C, name:String};
+
+@:forward
+private abstract MyType<T, C:Iterable<T>>(MyWrapper<T, C>) from MyWrapper<T, C> {
+    @:op(a < b)
+    static public inline function test<U, D:Iterable<U>>(a:MyType<U, D>, b:MyType<U, D>) : Bool {
+        return a.name.charCodeAt(0) < b.name.charCodeAt(0);
+    }
+}
+
+class Issue9123 extends Test {
+	function test() {
+		var c:MyType<Int, Array<Int>> = { val1:0, val2:[0], name:"a" },
+		d:MyType<Int, Array<Int>> = { val1:1, val2:[1], name:"b" };
+
+		t(c < d);
+		t(MyType.test(c, d));
+	}
+}

+ 34 - 0
tests/unit/src/unit/issues/misc/Issue5207Macro.hx

@@ -0,0 +1,34 @@
+package unit.issues.misc;
+
+import haxe.macro.Context;
+import haxe.macro.Type;
+import haxe.macro.Expr;
+using haxe.macro.Tools;
+
+class Issue5207Macro {
+	macro static public function test(){
+		var ret = [];
+        // build a static function with a constrained type parameter
+        var td = macro class C {
+            public static function func<T:{a:Int}>(v:T) return v;
+        }
+        Context.defineType(td);
+        var t = Context.getType("C");
+        var expr = macro { var r = C.func({b:""}); };
+        var success = try {Context.typeExpr(expr);true;} catch (e:Dynamic) false;
+        ret.push(macro f($v{success}));
+
+        // build a generic abstract with a constrained type parameter + from T conversion
+        var td2 = macro class A<T:{a:Int}> {
+            public static function func<T:{a:Int}>(v:T) return v;
+        }
+        td2.kind = TDAbstract(macro : {},[macro : T],[]);
+        Context.defineType(td2);
+        var t2 = Context.getType("A");
+        var expr2 = macro {b:""};
+        var etype = Context.typeof(expr2);
+        var success = Context.unify(etype,t2);
+        ret.push(macro f($v{success}));
+        return macro $b{ret};
+	}
+}