Browse Source

add some tests

Simon Krajewski 12 years ago
parent
commit
83a7e0f617
2 changed files with 45 additions and 0 deletions
  1. 1 0
      tests/unit/Test.hx
  2. 44 0
      tests/unit/TestGeneric.hx

+ 1 - 0
tests/unit/Test.hx

@@ -238,6 +238,7 @@ class Test #if swf_mark implements mt.Protect #end {
 			new TestType(),
 			new TestOrder(),
 			new TestGADT(),
+			new TestGeneric(),
 			#if !no_pattern_matching
 			new TestMatch(),
 			#end

+ 44 - 0
tests/unit/TestGeneric.hx

@@ -0,0 +1,44 @@
+package unit;
+
+@:generic
+class MyGeneric<T> {
+	public var t:T;
+	public function new(t:T) {
+		this.t = t;
+	}
+}
+
+@:generic
+class MyGeneric2<T> extends T {
+	//public function new() { } // not allowed
+}
+
+class MyRandomClass {
+	public var s:String;
+	public function new(s:String) {
+		this.s = s;
+	}
+}
+
+class TestGeneric extends Test {
+	function testBasic() {
+		var mg = new MyGeneric<Int>(12);
+		eq(mg.t, 12);
+		t(Std.is(mg.t, Int));
+		
+		var mg = new MyGeneric<String>("12");
+		eq(mg.t,"12");
+		t(Std.is(mg.t, String));
+	}
+	
+	function testExtends() {
+		t(unit.TestType.typeError(new MyGeneric2<String>()));
+		t(unit.TestType.typeError(new MyGeneric2<Int>()));
+		
+		var mg = new MyGeneric2<MyRandomClass>("foo");
+		eq("foo", mg.s);
+		
+		var mg = new MyGeneric2<MyGeneric<MyRandomClass>>(new MyRandomClass("foo"));
+		eq("foo", mg.t.s);
+	}
+}