Browse Source

added TestType.typeError (can be used to check if an expression rightfully causes typing errors)

Simon Krajewski 13 years ago
parent
commit
69d7d8b60a
1 changed files with 9 additions and 2 deletions
  1. 9 2
      tests/unit/TestType.hx

+ 9 - 2
tests/unit/TestType.hx

@@ -16,7 +16,15 @@ class TestType extends Test {
 		var tExpected = haxe.macro.Context.typeof(expected);
 		var tActual = haxe.macro.Context.typeof(actual);
 		return haxe.macro.Context.parse("{Test.count++; eq('" +Std.string(tActual) + "', '" +Std.string(tExpected) + "');}", haxe.macro.Context.currentPos());
-	}	
+	}
+	
+	@:macro static function typeError(e:haxe.macro.Expr) {
+		var result = try {
+			haxe.macro.Context.typeof(e);
+			"false";
+		} catch (e:Dynamic) "true";
+		return { pos: haxe.macro.Context.currentPos(), expr: haxe.macro.Expr.ExprDef.EConst(haxe.macro.Expr.Constant.CIdent(result)) };
+	}
 
 	public function testType() {
 		var name = u("unit")+"."+u("MyClass");
@@ -181,7 +189,6 @@ class TestType extends Test {
 
 	function testCallback()
 	{
-		
 		var func = function(a:Int, b:String, c:Float) return a;
 
 		#if !macro