-
Notifications
You must be signed in to change notification settings - Fork 0
/
deserialize_mapblock.spec.lua
52 lines (41 loc) · 1.64 KB
/
deserialize_mapblock.spec.lua
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
mtt.register("mapblock_lib.localize_nodeids (all known)", function(callback)
local node_mapping = {
["air"] = 0,
["default:stone"] = 1
}
local node_ids = {0,1}
local all_nodes_known, unknown_nodes = mapblock_lib.localize_nodeids(node_mapping, node_ids)
assert(all_nodes_known)
assert(#unknown_nodes == 0)
assert(node_ids[1] == minetest.get_content_id("air"))
assert(node_ids[2] == minetest.get_content_id("default:stone"))
callback()
end)
mtt.register("mapblock_lib.localize_nodeids (with unknown nodes assigned)", function(callback)
local node_mapping = {
["air"] = 0,
["default:node_not_found"] = 1
}
local node_ids = {0,1}
local all_nodes_known, unknown_nodes = mapblock_lib.localize_nodeids(node_mapping, node_ids)
assert(not all_nodes_known)
assert(unknown_nodes[1] == "default:node_not_found")
assert(node_ids[1] == minetest.get_content_id("air"))
assert(node_ids[2] < 0)
callback()
end)
minetest.register_alias("mapblock_lib:fancy_node", "default:gravel")
mtt.register("mapblock_lib.localize_nodeids (with alias)", function(callback)
assert(minetest.registered_nodes["mapblock_lib:fancy_node"], "aliased node is in registered_nodes")
local node_mapping = {
["air"] = 0,
["mapblock_lib:fancy_node"] = 1
}
local node_ids = {0,1}
local all_nodes_known, unknown_nodes = mapblock_lib.localize_nodeids(node_mapping, node_ids)
assert(all_nodes_known)
assert(#unknown_nodes == 0)
assert(node_ids[1] == minetest.get_content_id("air"))
assert(node_ids[2] == minetest.get_content_id("default:gravel"))
callback()
end)