Skip to content

Commit a1fa85e

Browse files
committed
Add variable tests.
1 parent c0ae4a8 commit a1fa85e

File tree

9 files changed

+180
-212
lines changed

9 files changed

+180
-212
lines changed

src/test/java/org/byteskript/skript/test/AtomicsTest.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/test/java/org/byteskript/skript/test/VariablesTest.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/test/resources/atomics.bsk renamed to src/test/resources/tests/atomicvariable.bsk

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11

2+
function atomic_variables:
3+
trigger:
4+
set {@var} to 6
5+
assert {@var} is 6: "Atomic variable set/retrieval failed."
6+
set {runnable} to a new runnable:
7+
assert {@var} is 6: "Atomic variable retrieval in runnable failed."
8+
set {@var} to {@var} + 3
9+
assert {@var} is 9: "Atomic variable change in runnable failed."
10+
assert {@var} is 6: "Atomic variable retrieval failed."
11+
run {runnable}
12+
assert {@var} is 9: "Atomic modification failed."
13+
assert {@var} exists: "Atomic variable exists check failed."
14+
delete {@var}
15+
assert {@var} is null: "Atomic variable deletion failed."
216

317
function basic_use:
418
trigger:
@@ -52,3 +66,13 @@ function test_param_atomic (@var):
5266
assert {@var} is 6: "Parameter was not boxed properly."
5367
set {@var} to {@var} + 1
5468
assert {@var} is 7: "Atomic variable failed to update."
69+
70+
function test:
71+
trigger:
72+
run basic_use()
73+
run passed_use()
74+
run as_simple_parameter()
75+
run as_atomic_parameter()
76+
run reverse_case()
77+
run atomic_variables()
78+
return true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
function test:
3+
trigger:
4+
set {thread} to the current thread
5+
set {!var} to 1
6+
assert {!var} is 1: "Global variable retrieval failed."
7+
set {!var} to {!var} + 1
8+
assert {!var} is 2: "Global variable set failed."
9+
assert {!var} exists: "Global variable exists check failed."
10+
set {!blob} to 3
11+
assert {!blob} is 3: "Global variable retrieval failed."
12+
delete {!blob}
13+
assert {!blob} is null: "Global variable deletion failed."
14+
run a new runnable:
15+
assert {!var} is 2: "Global variable access from runnable failed."
16+
run a new runnable in the background:
17+
assert {!var} is 2: "Global variable access from background thread failed."
18+
wait 1 ms
19+
wake {thread}
20+
sleep
21+
delete {!var}
22+
return true

src/test/resources/tests/loadedscripts.bsk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ function test:
33
trigger:
44
assert loaded scripts exists
55
assert size of (loaded scripts) > 0
6+
set {list} to all loaded scripts
7+
assert {list} exists: "Couldn't get loaded scripts"
8+
loop {script} in {list}:
9+
assert {script} exists: "Loop extracted null-value."
10+
assert {script} exists: "Nothing was looped."
611
return true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
function test:
3+
trigger:
4+
set {var} to 1
5+
assert {var} is 1: "Variable set/retrieval failed."
6+
set {var} to {var} + 1
7+
assert {var} is 2: "Variable set/retrieval failed."
8+
assert {var} exists: "Variable exists check failed."
9+
delete {var}
10+
assert {var} is null: "Variable deletion failed."
11+
return true
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
function handles:
3+
trigger:
4+
set {system} to get_class("java.lang.System")
5+
set {object} to get_class("java.lang.Object")
6+
assert {object} is object: "Class/type comparison failed."
7+
assert has_java_field({system}, "out") is true: "Field access failed."
8+
set {out} to get_java_field({system}, "out")
9+
assert {out} exists: "Field retrieval failed."
10+
set {method} to get_java_method("hello", "toString")
11+
assert {method} exists: "Method retrieval failed."
12+
assert result of {method} is "hello": "Reflective call failed."
13+
14+
function maths:
15+
trigger:
16+
assert 10 exists: "Int literal failed."
17+
assert 10L exists: "Long literal failed."
18+
assert 10.0 exists: "Double literal failed."
19+
assert 10.0F exists: "Float literal failed."
20+
set {three} to 1 - 4
21+
assert abs({three}) is 3: "Absolute function returned wrong result."
22+
assert sin(30) < 0.5: "Sine function returned wrong result."
23+
assert round(sin(90)) is 1: "Sine function returned wrong result."
24+
assert sin(40) > 0.6: "Sine function returned wrong result."
25+
assert sin(40) < 0.65: "Sine function returned wrong result."
26+
assert cos(0) is 1: "Cosine function returned wrong result."
27+
assert round(cos(90)) is 0: "Cosine function returned wrong result."
28+
assert cos(40) > 0.76: "Cosine function returned wrong result."
29+
assert cos(40) < 0.77: "Cosine function returned wrong result."
30+
assert round(tan(0)) is 0: "Tangent function returned wrong result."
31+
assert tan(40) < 0.84: "Tangent function returned wrong result."
32+
assert tan(40) > 0.83: "Tangent function returned wrong result."
33+
assert tan(20) < 0.37: "Tangent function returned wrong result."
34+
assert tan(20) > 0.36: "Tangent function returned wrong result."
35+
assert asin(0) is 0: "Arcus sine function returned wrong result."
36+
assert round(asin(0.5)) is 30: "Arcus sine function returned wrong result."
37+
assert acos(0) is 90: "Arcus cosine function returned wrong result."
38+
assert round(acos(0.5)) is 60: "Arcus cosine function returned wrong result."
39+
assert acos(0.3) > 72.5: "Arcus cosine function returned wrong result."
40+
assert acos(0.3) < 72.6: "Arcus cosine function returned wrong result."
41+
assert atan(0) is 0: "Arcus tangent function returned wrong result."
42+
assert atan(0.5) > 26.5: "Arcus tangent function returned wrong result."
43+
assert atan(0.5) < 26.6: "Arcus tangent function returned wrong result."
44+
assert sinh(30) > 31: "Hyperbolic sine function returned wrong result."
45+
assert sinh(30) < 32: "Hyperbolic sine function returned wrong result."
46+
assert cosh(40) > 71.8: "Hyperbolic cosine function returned wrong result."
47+
assert cosh(40) < 71.9: "Hyperbolic cosine function returned wrong result."
48+
assert tanh(40) > 34.5: "Hyperbolic tangent function returned wrong result."
49+
assert tanh(40) < 34.6: "Hyperbolic tangent function returned wrong result."
50+
assert round(atan2(5, 5)) is 45: "2-arg tangent function returned wrong result."
51+
assert atan2(5, 6) > 50.1: "2-arg tangent function returned wrong result."
52+
assert atan2(5, 6) < 50.2: "2-arg tangent function returned wrong result."
53+
assert sqrt(25) is 5: "Square root function returned wrong result."
54+
assert newton_root(25, 0) >= 5: "Newton root function returned wrong result."
55+
assert floor(5.9) is 5: "Floor function returned wrong result."
56+
assert floor(5) is 5: "Floor function returned wrong result."
57+
assert ceil(4.1) is 5: "Ceil function returned wrong result."
58+
assert ceil(5.0) is 5: "Ceil function returned wrong result."
59+
assert round(4.5) is 5: "Round function returned wrong result."
60+
assert round(5) is 5: "Round function returned wrong result."
61+
assert ln(-3) < 1: "Ln function returned wrong result."
62+
assert log(3) > 1: "Log function returned wrong result."
63+
64+
function generic:
65+
trigger:
66+
assert get_class("java.lang.String") is a class: "Generic function failed."
67+
assert current_time_millis() is a number: "Generic function failed."
68+
assert current_time_millis() is greater than 0: "Generic function failed."
69+
assert nano_time() is a number: "Generic function failed."
70+
assert line_separator() is a string: "Generic function failed."
71+
assert hashcode("hello") is a number: "Generic function failed."
72+
assert strict_equals(1, 1) is true: "Generic function failed."
73+
assert strict_equals("cc", "c" + "c") is false: "Generic function failed."
74+
75+
function test:
76+
trigger:
77+
run generic()
78+
run maths()
79+
run handles()
80+
return true
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
function test:
3+
trigger:
4+
set {thread} to the current thread
5+
set {_var} to 1
6+
assert {_var} is 1: "Thread variable retrieval failed."
7+
set {_var} to {_var} + 1
8+
assert {_var} is 2: "Thread variable set failed."
9+
assert {_var} exists: "Thread variable exists check failed."
10+
assert {_blob} is null: "Thread variable unset check failed."
11+
run a new runnable:
12+
assert {_var} is 2: "Thread variable access from runnable failed."
13+
run a new runnable in the background:
14+
assert {_var} is null: "Thread variable access from wrong thread passed."
15+
wait 1 ms
16+
wake {thread}
17+
sleep
18+
run a new runnable in the background:
19+
run copy_threadlocals_from({thread})
20+
assert {_var} is 2: "Thread locals copying failed."
21+
wait 1 ms
22+
wake {thread}
23+
sleep
24+
delete {_var}
25+
assert {_var} is null: "Thread variable deletion failed."
26+
return true
27+
28+
on load:
29+
trigger:
30+
assert {_var} is null: "Thread variable set at thread start."
31+
set {_var} to 10
32+
assert {_var} is 10
33+
34+
on load:
35+
trigger:
36+
assert {_var} is null: "Thread variable set at thread start."
37+
set {_var} to 10
38+
assert {_var} is 10

0 commit comments

Comments
 (0)