Przeglądaj źródła

add test (closes #4160)

Simon Krajewski 10 lat temu
rodzic
commit
df529996c4

+ 2 - 0
tests/misc/projects/Issue4160/compile.hxml

@@ -0,0 +1,2 @@
+-main test.Main
+--interp

+ 1 - 0
tests/misc/projects/Issue4160/compile.hxml.stderr

@@ -0,0 +1 @@
+foo

+ 51 - 0
tests/misc/projects/Issue4160/test/Main.hx

@@ -0,0 +1,51 @@
+package test;
+
+import haxe.macro.Context;
+import haxe.macro.Expr;
+
+private class Bar {
+	public function new() { }
+	public function getValue() {
+		return "foo";
+	}
+}
+
+class Main
+{
+    static function main()
+    {
+        defineFooExtendsBarInLocalModule();
+		#if !macro
+		var foo = new Foo();
+		Sys.stderr().writeString(foo.getValue());
+		#end
+    }
+
+    macro static function defineFooExtendsBarInLocalModule(?e)
+    {
+        var infos = Context.getPosInfos(Context.currentPos());
+        var position = Context.makePosition({min:0, max:0, file:infos.file});
+
+        var superTypePath:TypePath =
+        {
+            pack: [],
+            name: "Bar",
+            sub: null
+        }
+
+        var kind:TypeDefKind = TypeDefKind.TDClass(superTypePath);
+
+        var Foo:TypeDefinition =
+        {
+            name: "Foo",
+            pack: ["test"],
+            pos: position,
+            kind: kind,
+            fields: []
+        }
+
+        Context.defineModule(Context.getLocalModule(), [Foo]);
+
+        return e;
+    }
+}