-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.lua
70 lines (63 loc) · 1.99 KB
/
environment.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local test_position = {x=51,y=1,z=50}
-- minetest.dig_node(pos)
-- ^ Dig node with the same effects that a player would cause
-- Returns true if successful, false on failure (e.g. protected location)
describe("minetest.dig_node(pos)", function()
set_up(function()
original_protection = minetest.is_protected
end)
it("Returns false on failure (e.g. protected location) (minetest/minetest#2015)", function()
Given "an undiggable node"
minetest.is_protected = function(pos, name) return true end
minetest.set_node(test_position, {name = cubictest.dummies.nodes.undiggable.name })
When "digging it"
local dig = minetest.dig_node(test_position)
Then "return false"
assert.is.False(dig)
end)
tear_down(function()
-- revert to former state after run
minetest.is_protected = original_protection
end)
end)
describe("core.string_to_pos(string)", function()
it("parses correctly formed position strings", function()
for pos_string, expected in pairs({
["10.0, 5, -2"] = {x=10.0, y=5, z=-2},
["( 10.0, 5, -2)"] = {x=10.0, y=5, z=-2}
}) do
local pos = core.string_to_pos(pos_string)
assert.are_same(expected, pos)
end
end)
it("rejects malformed position strings", function()
for _, pos_string in pairs({
"asd, 5, -2)",
"(,,)",
"( 10.0, 5, -2) cobble cobble cobble!",
}) do
local pos = core.string_to_pos(pos_string)
assert.is_nil(pos)
end
end)
end)
if core.string_to_area then
describe("core.string_to_area(string)", function()
it("parses correctly formed area strings", function()
local p1, p2 = core.string_to_area("(10.0, 5, -2) ( 30.2, 4, -12.53)")
assert.are_same(p1, {x=10.0, y=5, z=-2})
assert.are_same(p2, {x=30.2, y=4, z=-12.53})
end)
it("rejects malformed area strings", function()
for _, area_string in pairs({
"(10.0, 5, -2 30.2, 4, -12.53",
"(10.0, 5,) -2 fgdf2, 4, -12.53",
"(,,) (,,)",
}) do
local p1, p2 = core.string_to_area(area_string)
assert.is_nil(p1)
assert.is_nil(p2)
end
end)
end)
end