package ; import haxe.PosInfos; import haxe.unit.TestCase; import haxe.unit.TestResult; import haxe.unit.TestStatus; import tink.core.Either; abstract PhysicalType(Either, Enum>) { function new(v) this = v; public function toString() return switch this { case Left(c): Type.getClassName(c); case Right(e): Type.getEnumName(e); } public function check(v:T) return Std.is(v, this.getParameters()[0]); @:from static function ofClass(c:Class) return new PhysicalType(Left(c)); @:from static function ofEnum(e:Enum) return new PhysicalType(Right(e)); } //TODO: this helper should go somewhere class Base extends TestCase { function stringCompare(v1:A, v2:A, ?pos) assertEquals(Std.string(v1), Std.string(v2), pos); function fail(msg:String, ?c : PosInfos) { currentTest.done = true; currentTest.success = false; currentTest.error = msg; currentTest.posInfos = c; throw currentTest; } function throws(f:Void->Void, ?t:PhysicalType, ?check:A->Bool, ?pos:PosInfos):Void { try f() catch (e:Dynamic) { if (t != null && !t.check(e)) fail('Exception $e not of type $t', pos); if (check != null && !check(e)) fail('Exception $e does not satisfy condition', pos); assertTrue(true); return; } fail('no exception thrown', pos); } }