Skip to content

Commit 6790f4f

Browse files
committed
add test for parameters
1 parent 18bff16 commit 6790f4f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
runs = {}
3+
local ResourceTypeA = world.get_type_by_name("TestResource")
4+
local ResourceTypeB = world.get_type_by_name("TestResourceWithVariousFields")
5+
local ComponentA = world.get_type_by_name("CompWithFromWorldAndComponentData")
6+
local ComponentB = world.get_type_by_name("CompWithDefaultAndComponentData")
7+
8+
function on_test()
9+
local post_update_schedule = world.get_schedule_by_name("PostUpdate")
10+
11+
local entity = world.spawn()
12+
local entity2 = world.spawn()
13+
14+
15+
world.add_default_component(entity, ComponentA)
16+
world.add_default_component(entity, ComponentB)
17+
world.add_default_component(entity2, ComponentA)
18+
world.add_default_component(entity2, ComponentB)
19+
20+
world.add_system(
21+
post_update_schedule,
22+
system_builder("my_parameterised_system", script_id)
23+
:resource(ResourceTypeA)
24+
:query(world.query():component(ComponentA):with(ComponentB))
25+
:resource(ResourceTypeB)
26+
)
27+
28+
return true
29+
end
30+
31+
function my_parameterised_system(resourceA,query,resourceB)
32+
print("my_parameterised_system")
33+
runs[#runs + 1] = "my_non_exclusive_system"
34+
35+
assert(resourceA ~= nil, "Expected to get resource but got nil")
36+
assert(query ~= nil, "Expected to get query but got nil")
37+
assert(resourceB ~= nil, "Expected to get resource but got nil")
38+
39+
assert(#resourceA.bytes == 6, "Expected 6 bytes, got: " .. #resourceA.bytes)
40+
assert(resourceB.string == "Initial Value", "Expected 'Initial Value', got: " .. resourceB.string)
41+
assert(#query == 2, "Expected 3 results, got: " .. #query)
42+
end
43+
44+
45+
function on_test_post_update()
46+
return true
47+
end
48+
49+
function on_test_last()
50+
assert(#runs == 1, "Expected 1 runs, got: " .. #runs)
51+
return true
52+
end

0 commit comments

Comments
 (0)