mirror of
https://github.com/wiremod/wire.git
synced 2025-03-04 03:03:04 -05:00
Add some tests for E2
Currently the tests are quite minimal: a test for the E2 parser, and a regression test for #1975. Soon there will be a test harness command that runs all the test E2s and watches for errors.
This commit is contained in:
parent
e8237d91f9
commit
2678c4c3ff
88
data/expression2/tests/parsing.txt
Normal file
88
data/expression2/tests/parsing.txt
Normal file
@ -0,0 +1,88 @@
|
||||
@inputs In
|
||||
@outputs Out
|
||||
|
||||
local A = 0
|
||||
|
||||
if (A) { A = 0 }
|
||||
if (A) { A = 0 } else { A = 0 }
|
||||
if (A) { A = 0 } elseif (A) { A = 0 }
|
||||
if (A) { A = 0 } elseif (A) { A = 0 }
|
||||
|
||||
while (A) { A = 0 }
|
||||
|
||||
for (B = 1, 2) { A = 0 }
|
||||
for (B = 1, 2, 3) { A = 0 }
|
||||
|
||||
foreach (K, V: number = array(1, 2, 3)) { A = 0 }
|
||||
|
||||
while (A) { break }
|
||||
while (A) { continue }
|
||||
|
||||
A++
|
||||
A--
|
||||
A += 1
|
||||
A -= 1
|
||||
A *= 1
|
||||
A /= 1
|
||||
|
||||
local B = vec()
|
||||
B[1] = 2
|
||||
|
||||
switch (A) {
|
||||
case A + A,
|
||||
A = 0
|
||||
A = 0
|
||||
case A + A + A,
|
||||
A = 0
|
||||
break
|
||||
default,
|
||||
A = 0
|
||||
}
|
||||
|
||||
function f() {}
|
||||
function void f() {}
|
||||
function void f() { return }
|
||||
function number g() { return 0 }
|
||||
function number f(X) { return X }
|
||||
function vector f(X: vector) { return X }
|
||||
function number f(X, Y) { return X + Y }
|
||||
function number f(X, Y: vector) { return X }
|
||||
function number f([X Y]) { return X + Y }
|
||||
function number f([X Y]: number) { return X + Y }
|
||||
|
||||
A ? A : A
|
||||
A ?: A
|
||||
A | A
|
||||
A & A
|
||||
A || A
|
||||
A && A
|
||||
A ^^ A
|
||||
A == A
|
||||
A != A
|
||||
A > A
|
||||
A < A
|
||||
A >= A
|
||||
A <= A
|
||||
A << A
|
||||
A >> A
|
||||
A + A
|
||||
A - A
|
||||
A * A
|
||||
A / A
|
||||
A % A
|
||||
A ^ A
|
||||
+A
|
||||
-A
|
||||
!A
|
||||
|
||||
array():count()
|
||||
array()[0, number]
|
||||
(A)
|
||||
0
|
||||
"foo"
|
||||
~In
|
||||
$In
|
||||
->In
|
||||
A
|
||||
|
||||
table(1 = 1, 2 = 2)
|
11
data/expression2/tests/regressions/1975.txt
Normal file
11
data/expression2/tests/regressions/1975.txt
Normal file
@ -0,0 +1,11 @@
|
||||
vec() * 0
|
||||
0 * vec()
|
||||
|
||||
local Calls = 0
|
||||
function number f() {
|
||||
Calls++
|
||||
return 1
|
||||
}
|
||||
f() * 0
|
||||
0 * f()
|
||||
assert(Calls == 2)
|
@ -318,6 +318,14 @@ e2function void error( string reason )
|
||||
error(reason, 2)
|
||||
end
|
||||
|
||||
e2function void assert(condition)
|
||||
if not condition then error("assert failed", 2) end
|
||||
end
|
||||
|
||||
e2function void assert(condition, string reason)
|
||||
if not condition then error(reason, 2) end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
__e2setcost(100) -- approximation
|
||||
|
@ -824,6 +824,8 @@ E2Helper.Descriptions["setName(e:s)"] = "Set the name of another E2 or component
|
||||
E2Helper.Descriptions["cpuUsage()"] = "Returns the average time per tick the server spends running this E2, in seconds (multiply it by 1000000 to get the same value as is displayed on the E2 overlay)"
|
||||
E2Helper.Descriptions["cpuUsage(e:)"] = "Returns the average time per tick the server spends running the specified E2, in seconds (multiply it by 1000000 to get the same value as is displayed on the E2 overlay)"
|
||||
E2Helper.Descriptions["error(s)"] = "Shuts down the E2 with specified script error message"
|
||||
E2Helper.Descriptions["assert(n)"] = "If the argument is 0, shut down the E2 with an error message"
|
||||
E2Helper.Descriptions["assert(ns)"] = "If the first argument is 0, shut down the E2 with the given error message string"
|
||||
E2Helper.Descriptions["reset()"] = "Reset the expression itself as if it was just spawned, stops execution"
|
||||
E2Helper.Descriptions["exit()"] = "Stops the execution of any code after it"
|
||||
E2Helper.Descriptions["getCode()"] = "Returns the code of the E2 as a string"
|
||||
|
Loading…
Reference in New Issue
Block a user