-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
MiniscriptUnitTest.cs
54 lines (43 loc) · 1.48 KB
/
MiniscriptUnitTest.cs
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
/* MiniscriptUnitTest.cs
This file contains a number of unit tests for various parts of the MiniScript
architecture. It's used by the MiniScript developers to ensure we don't
break something when we make changes.
You can safely ignore this, but if you really want to run the tests yourself,
just call Miniscript.UnitTest.Run().
*/
using System;
namespace Miniscript {
public static class UnitTest {
public static void ReportError(string err) {
// Set a breakpoint here if you want to drop into the debugger
// on any unit test failure.
Console.WriteLine(err);
#if UNITY_EDITOR
UnityEngine.Debug.LogError("Miniscript unit test failed: " + err);
#endif
}
public static void ErrorIf(bool condition, string err) {
if (condition) ReportError(err);
}
public static void ErrorIfNull(object obj) {
if (obj == null) ReportError("Unexpected null");
}
public static void ErrorIfNotNull(object obj) {
if (obj != null) ReportError("Expected null, but got non-null");
}
public static void ErrorIfNotEqual(string actual, string expected,
string desc="Expected {1}, got {0}") {
if (actual == expected) return;
ReportError(string.Format(desc, actual, expected));
}
public static void ErrorIfNotEqual(float actual, float expected,
string desc="Expected {1}, got {0}") {
if (actual == expected) return;
ReportError(string.Format(desc, actual, expected));
}
public static void Run() {
Lexer.RunUnitTests();
Parser.RunUnitTests();
}
}
}