summaryrefslogtreecommitdiff
path: root/honey/ecs.test.lua
blob: 7814097cf74170e094ab1d2213a5c7633e367ee8 (plain)
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
local function test(msg, f)
	local success, error = pcall(f)
	if success then
		print(msg .. "\t\t[OK]")
	else
		print(msg .. "\t\t[FAIL]")
		print(error)
	end
end


local ecs = require 'ecs'
local Filter = ecs.Filter


test("Filter.AND correctly matches basic keys", function()
	local filter = Filter.AND{"hello", "world"}

	assert(filter{hello=true} == false)
	assert(filter{world=true} == false)
	assert(filter{hello=true, world=true} == true)
	assert(filter{asm=true, hello=true, world=true} == true)
end)
test("Filter.AND correctly matches subfilters", function()
	local subfilter = Filter.AND{"hello"}
	local filter = Filter.AND{subfilter, "world"}

	assert(filter{hello=true} == false)
	assert(filter{world=true} == false)
	assert(filter{hello=true, world=true} == true)
	assert(filter{asm=true, hello=true, world=true} == true)
end)


test("Filter.OR correctly matches basic keys", function()
	local filter = Filter.OR{"hello", "world"}

	assert(filter{hello=true} == true)
	assert(filter{world=true} == true)
	assert(filter{hello=true, world=true} == true)
	assert(filter{asm=true} == false)
end)
test("Filter.OR correctly matches subfilters", function()
	local subfilter = Filter.OR{"hello"}
	local filter = Filter.OR{subfilter, "world"}

	assert(filter{hello=true} == true)
	assert(filter{world=true} == true)
	assert(filter{hello=true, world=true} == true)
	assert(filter{asm=true} == false)
end)