1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/* <license>
* This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
* For full copyright and license information please refer to doc/license.txt.
* </license>
*/
/**
* To make up for a lack in haxe, this is a standard assertion
* class.
* It's behaviour is to trace that an assertion occured and then
* to through an exception -- hopefully something can display
* the exception (like Flash Debug player)
*
* TODO: somehow merge/unify with TestCaseX, since basically all the same
* tests might appear...
*/
class Assert
{
var msg : String;
public function new( msg : String )
{
this.msg = msg;
}
public function toString() : String
{
return msg;
}
static public function fail( reason : String, ?msg : String, ?pos:haxe.PosInfos )
{
if( msg == null )
msg = "";
else
msg = ":" + msg;
trace( "Assertion in "
+ pos.className
+ "::"
+pos.methodName
+ ": "
+ "<"
+ pos.fileName
+ ":"
+ pos.lineNumber
+ ">"
+ reason
+ msg, pos );
throw new Assert(msg); //something that nobody is likely catching...
}
inline static public function isTrue( cond : Bool, ?msg : String, ?pos:haxe.PosInfos )
{
if( !cond )
fail( "isTrue", msg, pos );
}
inline static public function isFalse( cond : Bool,?msg : String, ?pos:haxe.PosInfos )
{
if( cond )
fail( "isFalse", msg, pos );
}
inline static public function unreachable( ?pos:haxe.PosInfos) : Void
{
fail( "unreachable", pos);
}
inline static public function invalidParam( ?text : String, ?pos: haxe.PosInfos ) : Void
{
fail( "invalidParam", text, pos );
}
inline static public function is( obj : Dynamic, type : Dynamic, ?msg : String, ?pos:haxe.PosInfos )
{
if( !Std.is( obj, type ) )
fail( "is(" + obj + "," + type + ")", msg, pos );
}
inline static public function notNull( obj : Dynamic, ?msg : String, ?pos:haxe.PosInfos )
{
if( obj == null )
fail( "notNull", msg, pos );
}
inline static public function isNull( obj : Dynamic, ?msg : String, ?pos:haxe.PosInfos )
{
if( obj != null )
fail( "isNull", msg, pos );
}
/**
* Used to indicate the funciton is never meant to be called, it is rather
* a placeholder for a function to be defined in a derived class.
*/
inline static public function pureVirtual( ?pos:haxe.PosInfos )
{
fail( "pure virtual called", pos );
}
/**
* Used to indicate a function was called, typically as part of an interface,
* which has no definition, nor should it have a definition as it should
* not be called.
*/
inline static public function noVirtual( ?pos:haxe.PosInfos )
{
fail( "noVirtual", pos );
}
/**
* Used to indicate that something is unimplemented
*
* @param cond [in] if specified, states what is unimplemented, note, this
* is logically equivalent to isFalse (you specify which condition is unimplemented)
*/
inline static public function unimplemented( ?cond: Null<Bool>, ?msg : String, ?pos : haxe.PosInfos )
{
if( cond == null || cond )
fail( "unimplemented", msg, pos );
}
}
|