Browse Source

unit test adjustments

Simon Krajewski 12 years ago
parent
commit
d1a061329b

+ 2 - 0
tests/unit/MyAbstract.hx

@@ -16,6 +16,7 @@ abstract MyAbstract(Int) {
 
 }
 
+#if !flash8
 abstract TemplateWrap(haxe.Template) {
 	public inline function new(x) {
 		this = new haxe.Template(x);
@@ -32,6 +33,7 @@ abstract TemplateWrap(haxe.Template) {
 		return this.execute( { t: "really works!"});
 	}
 }
+#end
 
 abstract Meter(Float) from Float to Float {
 	public inline function new(f)

+ 3 - 0
tests/unit/TestBasetypes.hx

@@ -284,6 +284,8 @@ class TestBasetypes extends Test {
 	}
 
 	function testAbstractCast() {
+		// flash 8 cannot handle Templates
+		#if !flash8
 		var s = "Abstract casting ::t::";
 		// var from
 		var tpl:unit.MyAbstract.TemplateWrap = s;
@@ -347,6 +349,7 @@ class TestBasetypes extends Test {
 		// array to
 		var arr:Array<String> = [tpl];
 		eq(arr[0], "Abstract casting really works!");
+		#end
 	}
 
 	function testAbstractToAbstractCast() {

+ 37 - 37
tests/unit/TestMatch.hx

@@ -25,7 +25,7 @@ class TestMatch extends Test {
 		} catch (e:Dynamic) Std.string(e.message);
 		return macro $v{result};
 	}
-	
+
 	static function switchNormal(e:Expr):String {
 		return switch(e.expr) {
 			case EConst(CString(s)): s;
@@ -42,7 +42,7 @@ class TestMatch extends Test {
 				"not_found";
 		}
 	}
-	
+
 	static function switchCapture(e:Expr) {
 		return switch(e) {
 			case { expr : EConst(const = (CString("foobar") | CInt("9"))) } :
@@ -51,7 +51,7 @@ class TestMatch extends Test {
 				null;
 		}
 	}
-	
+
 	static function switchArray(e:Expr):String {
 		return switch(e.expr) {
 			case EArrayDecl([]):
@@ -64,7 +64,7 @@ class TestMatch extends Test {
 				"_";
 		}
 	}
-	
+
 	static function switchArray2(a:Array<String>):String {
 		return switch(a) {
 			case ["a", "b"]: "0";
@@ -77,7 +77,7 @@ class TestMatch extends Test {
 			case _: "7";
 		}
 	}
-	
+
 	static function switchStructure(a: { foo:String, bar:String } ) {
 		return switch(a) {
 			case { foo: "val1", bar:"val2" } : "0";
@@ -86,7 +86,7 @@ class TestMatch extends Test {
 			case { bar: a } : a;
 		}
 	}
-	
+
 	static function switchCrazy(e:Expr) {
 		return switch(e.expr) {
 			case EUntyped( { expr : EParenthesis( { expr : EArray( { expr: a = EConst(CString(_)) }, { expr : EConst(CInt(b)) } ) } ) } ):
@@ -95,7 +95,7 @@ class TestMatch extends Test {
 				"_";
 		}
 	}
-	
+
 	static function switchGuard(e:Expr):String {
 		return switch(e.expr) {
 			case EConst(CString(s)) if (StringTools.startsWith(s, "foo")):
@@ -110,15 +110,15 @@ class TestMatch extends Test {
 				"5";
 		}
 	}
-	
+
 	static function switchClass<T>(cl:Class<T>) {
 		return switch(cl) {
 			case String: "String";
-			case haxe.Template: "haxe.Template";
+			case MyClass: "unit.MyClass";
 			case a: "other: " +Type.getClassName(a);
 		}
 	}
-	
+
 	function testBasic() {
 		eq("bar", switchNormal(macro "bar"));
 		eq("bar", switchNormal(macro ("bar")));
@@ -128,18 +128,18 @@ class TestMatch extends Test {
 		eq("22.5", switchNormal(macro null[22.5]));
 		eq("EConst(CInt(0))", switchNormal(macro 1 in 0));
 		eq("not_found", switchNormal(macro null["22"]));
-		
+
 		t(null != switchCapture(macro "foobar"));
 		t(null == switchCapture(macro "fooba"));
 		t(null != switchCapture(macro 9));
 		t(null == switchCapture(macro 10));
-		
+
 		eq("[]", switchArray(macro []));
 		eq("_", switchArray(macro 2));
 		eq("[EConst(CInt(22))]", switchArray(macro [22]));
 		eq("[EConst(CInt(22)),EConst(CString(foo))]", switchArray(macro [22,"foo"]));
 		eq("_", switchArray(macro [22, "foo", "bar"]));
-		
+
 		eq("0", switchArray2(["a", "b"]));
 		eq("1", switchArray2(["a"]));
 		eq("2", switchArray2(["b"]));
@@ -149,46 +149,46 @@ class TestMatch extends Test {
 		eq("5:3", switchArray2(["a","a","a"]));
 		eq("6", switchArray2([]));
 		eq("7", switchArray2(["a", "a", "a", "b"]));
-		
+
 		eq("EConst(CString(foobar)):12", switchCrazy(macro untyped ("foobar"[12])));
-		
+
 		eq("1", switchGuard(macro "foobar"));
 		eq("2", switchGuard(macro "barfoo"));
 		eq("3", switchGuard(macro 2));
 		eq("4", switchGuard(macro 5));
 		eq("4", switchGuard(macro "bazfoo"));
 		eq("5", switchGuard(macro []));
-		
+
 		eq("0", switch ([true, 1, "foo"]) {
 			case [true, 1, "foo"]: "0";
 			case [true, 1, _]: "1";
 			case _: "_";
 		});
-		
+
 		eq("0", switch [true, 1, "foo"] {
 			case [true, 1, "foo"]: "0";
 			case [true, 1, _]: "1";
 			case _: "_";
 		});
-		
+
 		eq("1", switch [true, 1, "bar"] {
 			case [true, 1, "foo"]: "0";
 			case [true, 1, _]: "1";
 			case _: "_";
 		});
-		
+
 		eq("_", switch [false, 1, "foo"] {
 			case [true, 1, "foo"]: "0";
 			case [true, 1, _]: "1";
 			case _: "_";
 		});
-		
+
 		eq("1", switch [1, 2] {
 			case [0, 0] | [1, 2]: "1";
 			case [1, 1]: "2";
 			case _: "_";
 		});
-		
+
 		var t = TA("foo");
 		eq("0", switch(t) {
 			case TA("foo"): "0";
@@ -196,7 +196,7 @@ class TestMatch extends Test {
 			case TC(_): "2";
 		});
 	}
-	
+
 	function testTuple() {
 		function test(a:Int, b:Int, c:Int) return switch [a, b, c] {
 			case [x, 1, 2] | [1, 2, x] | [1, x, 2]: '0|x:$x';
@@ -214,7 +214,7 @@ class TestMatch extends Test {
 		eq("2|y:9,z:8", test(2, 8, 9));
 		eq("_:x:9,y:8,z:7", test(9, 8, 7));
 	}
-	
+
 	function testGrouping() {
 		function test(v) return switch(v) {
 			case 1, 2, 3: "0";
@@ -228,7 +228,7 @@ class TestMatch extends Test {
 			eq(results[i], test(i));
 		}
 	}
-	
+
 	function testSubtyping() {
 		var c = new MyClass.InitBase();
 		var r = switch(c) {
@@ -238,13 +238,13 @@ class TestMatch extends Test {
 				"_";
 		}
 		eq("s = foo", r);
-		
+
 		eq("0", switchStructure( { foo:"val1", bar:"val2" } ));
 		eq("1", switchStructure( { foo:"val1", bar:"val1" } ));
 		eq("2", switchStructure( { foo:"val2", bar:"val2" } ));
 		eq("val1", switchStructure( { foo:"val2", bar:"val1" } ));
 	}
-	
+
 	public static function toStringX<Z>(x1:X<Z>) {
 		return switch (x1) {
 			case U1(x) if (x > 1): ">1";
@@ -253,19 +253,19 @@ class TestMatch extends Test {
 			case U2: "U2";
 		}
 	}
-	
+
 	function testGadt() {
 		eq("<=1", toStringX(U1(1)));
 		eq(">1", toStringX(U1(2)));
 		eq("U2", toStringX(U2));
 	}
-	
+
 	function testClassSwitch() {
 		eq("String", switchClass(String));
-		eq("haxe.Template", switchClass(haxe.Template));
+		eq("unit.MyClass", switchClass(MyClass));
 		eq("other: unit.TestMatch", switchClass(TestMatch));
 	}
-		
+
 	function testNonExhaustiveness() {
 		eq("Unmatched patterns: false", getErrorMessage(switch(true) {
 			case true:
@@ -291,7 +291,7 @@ class TestMatch extends Test {
 			case [_, true, _]:
 		}));
 	}
-	
+
 	function testInvalidBinding() {
 		eq("Variable y must appear exactly once in each sub-pattern", getErrorMessage(switch(Leaf("foo")) {
 			case Leaf(x) | Leaf(y):
@@ -312,7 +312,7 @@ class TestMatch extends Test {
 			case Node(l = Leaf(_), _) | Leaf(l):
 		}));
 	}
-	
+
 	#if false
 	 //all lines marked as // unused should give an error
 	function testRedundance() {
@@ -321,32 +321,32 @@ class TestMatch extends Test {
 			case true:
 			case false: // unused
 		}
-		
+
 		switch(true) {
 			case false | true:
 			case true: // unused
 			case false: // unused
 		}
-		
+
 		switch(true) {
 			case false
 			| false: // unused
 			case true:
 		}
-		
+
 		switch(Leaf(true)) {
 			case Leaf(true):
 			case Leaf(false):
 			case Leaf(x): // unused
 			case Node(_):
 		}
-		
+
 		switch({s:"foo"}) {
 			case { s : "foo" } :
 			case { s : a } : // Warning : This variable is unused
 			case _: // unused
 		}
-		
+
 		switch( { s:"foo", t:"bar" } ) {
 			case { s : "foo" }:
 			case { t : "bar" }:

+ 2 - 0
tests/unit/TestType.hx

@@ -665,7 +665,9 @@ class TestType extends Test {
 		exc(function() { throw null; return 1; } );
 		exc(function() { throw null; return "foo"; } );
 		exc(function() { throw null; return MyEnum.A; } );
+		#if !flash8
 		exc(function() { throw null; return new haxe.Template("foo"); } );
+		#end
 		exc(function() { throw null; return null; } );
 		exc(function() { throw null; return { foo: 1}; } );
 	}

+ 3 - 3
tests/unit/unitstd/Type.unit.hx

@@ -1,6 +1,6 @@
 // getClass
 Type.getClass("foo") == String;
-Type.getClass(new haxe.Template("")) == haxe.Template;
+Type.getClass(new C()) == C;
 Type.getClass([]) == Array;
 Type.getClass(Float) == null;
 Type.getClass(null) == null;
@@ -20,7 +20,7 @@ Type.getSuperClass(ClassWithToStringChild) == ClassWithToString;
 
 // getClassName
 Type.getClassName(String) == "String";
-Type.getClassName(haxe.Template) == "haxe.Template";
+Type.getClassName(C) == "unit.C";
 //Type.getClassName(null) == null;
 Type.getClassName(Type.getClass([])) == "Array";
 
@@ -30,7 +30,7 @@ Type.getEnumName(haxe.macro.Expr.ExprDef) == "haxe.macro.ExprDef";
 
 // resolveClass
 Type.resolveClass("String") == String;
-Type.resolveClass("haxe.Template") == haxe.Template;
+Type.resolveClass("unit.C") == C;
 //Type.resolveClass("Float") == null;
 //Type.resolveClass(null) == null;
 Type.resolveClass("MyNonExistingClass") == null;

+ 5 - 2
tests/unit/unitstd/haxe/ds/Vector.unit.hx

@@ -20,10 +20,13 @@ vec.get(1) == vNullFloat;
 vec.get(2) == vNullFloat;
 
 // bool init
+// Adobe's compilers seem to have a bug here that gives null instead of false
+#if !as3
 var vec = new haxe.ds.Vector<Bool>(3);
 vec.get(0) == vNullBool;
 vec.get(1) == vNullBool;
 vec.get(2) == vNullBool;
+#end
 
 // fromArray
 var arr = ["1", "2", "3"];
@@ -37,8 +40,8 @@ vec.get(1) == "2";
 vec.get(2) == "3";
 
 // objects
-var tpl = new haxe.Template("foo");
-var vec:haxe.ds.Vector<haxe.Template> = haxe.ds.Vector.fromArrayCopy([tpl]);
+var tpl = new C();
+var vec:haxe.ds.Vector<C> = haxe.ds.Vector.fromArrayCopy([tpl]);
 tpl == vec.get(0);
 
 // toData + fromData