-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionTests.hx
More file actions
125 lines (113 loc) · 2.48 KB
/
ExceptionTests.hx
File metadata and controls
125 lines (113 loc) · 2.48 KB
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
121
122
123
124
125
package;
class ExceptionTests {
var t:Main;
public function new(main:Main) {
t = main;
}
public function run() {
t.section("ExceptionBasic");
checkBasic();
t.section("ExceptionMessage");
checkMessage();
t.section("ExceptionToString");
checkToString();
t.section("ExceptionDetails");
checkDetails();
t.section("ExceptionCatchTyped");
checkCatchTyped();
t.section("ExceptionCatchString");
checkCatchString();
t.section("ExceptionCatchInt");
checkCatchInt();
t.section("ExceptionRethrow");
checkRethrow();
t.section("ExceptionDynamic");
checkDynamic();
}
function checkBasic() {
var caught = false;
try {
throw new haxe.Exception("test error");
} catch (e:Dynamic) {
caught = true;
}
t.isTrue(caught, "Exception thrown and caught");
}
function checkMessage() {
var msg = "";
try {
throw new haxe.Exception("hello world");
} catch (error:haxe.Exception) {
msg = error.message;
}
t.stringEquals("hello world", msg, "Exception.message");
}
function checkToString() {
var str = "";
try {
throw new haxe.Exception("test msg");
} catch (e:haxe.Exception) {
str = e.toString();
}
t.stringEquals("test msg", str, "Exception.toString()");
}
function checkDetails() {
var det = "";
try {
throw new haxe.Exception("detail test");
} catch (e:haxe.Exception) {
det = e.details();
}
t.stringEquals("detail test", det, "Exception.details() without previous");
}
function checkCatchTyped() {
var msg = "";
try {
throw new haxe.Exception("typed catch");
} catch (e:haxe.Exception) {
msg = e.message;
}
t.stringEquals("typed catch", msg, "catch (e:haxe.Exception)");
}
function checkCatchString() {
var caught = false;
try {
throw "string error";
} catch (e:Dynamic) {
caught = true;
}
t.isTrue(caught, "catch string as Dynamic");
}
function checkCatchInt() {
var caught = false;
try {
throw 42;
} catch (e:Dynamic) {
caught = true;
}
t.isTrue(caught, "catch int as Dynamic");
}
function checkRethrow() {
var msg = "";
try {
try {
throw new haxe.Exception("rethrown");
} catch (e:haxe.Exception) {
throw e;
}
} catch (e2:haxe.Exception) {
msg = e2.message;
}
t.stringEquals("rethrown", msg, "rethrown exception message");
}
function checkDynamic() {
var msg = "";
try {
throw "dynamic error";
} catch (e:Dynamic) {
msg = Std.string(e);
}
var hasContent = msg.length > 0;
t.isTrue(hasContent, "dynamic catch has content");
}
}