Minetest-WorldEditAdditions/.tests/parse/axes/axes_keyword.test.lua

79 lines
2.2 KiB
Lua
Raw Normal View History

2023-12-21 17:32:30 +01:00
local Vector3 = require("worldeditadditions_core.utils.vector3")
local facing_dirs = dofile("./.tests/parse/axes/include_facing_dirs.lua")
local parse = require("worldeditadditions_core.utils.parse.axes_parser")
local parse_keyword = parse.keyword
describe("parse_keyword", function()
-- Basic tests
it("should work on single axes", function()
local ktype, axis, sign = parse_keyword("x")
2024-09-12 01:52:37 +02:00
assert.are.equals("axis", ktype)
assert.are.same({"x"}, axis)
assert.are.equals(1, sign)
2023-12-21 17:32:30 +01:00
end)
it("should work with axis clumping", function()
local ktype, axis, sign = parse_keyword("zx")
2024-09-12 01:52:37 +02:00
assert.are.equals("axis", ktype)
assert.are.same({"x", "z"}, axis)
assert.are.equals(1, sign)
2023-12-21 17:32:30 +01:00
end)
it("should work with h and v", function()
local ktype, axis, sign = parse_keyword("hv")
2024-09-12 01:52:37 +02:00
assert.are.equals("axis", ktype)
assert.are.same(
{"x", "y", "z", rev={"x", "y", "z"}},
axis)
assert.are.equals(1, sign)
2023-12-21 17:32:30 +01:00
end)
it("should work with h and v in clumping", function()
local ktype, axis, sign = parse_keyword("hyxz")
2024-09-12 01:52:37 +02:00
assert.are.equals("axis", ktype)
assert.are.same(
{"x", "y", "z", rev={"x", "z"}},
axis)
assert.are.equals(1, sign)
2023-12-21 17:32:30 +01:00
end)
it("should work with negatives", function()
local ktype, axis, sign = parse_keyword("-xv")
2024-09-12 01:52:37 +02:00
assert.are.equals("axis", ktype)
assert.are.same({"x", "y", rev={"y"}}, axis)
assert.are.equals(-1, sign)
2023-12-21 17:32:30 +01:00
end)
it("should work with dirs", function()
local ktype, axis, sign = parse_keyword("left")
2024-09-12 01:52:37 +02:00
assert.are.equals("dir", ktype)
assert.are.equals("left", axis)
assert.are.equals(1, sign)
2023-12-21 17:32:30 +01:00
end)
it("should work with negative dirs", function()
local ktype, axis, sign = parse_keyword("-right")
2024-09-12 01:52:37 +02:00
assert.are.equals("dir", ktype)
assert.are.equals("right", axis)
assert.are.equals(-1, sign)
2023-12-21 17:32:30 +01:00
end)
it("should work with mirroring", function()
local ktype, axis, sign = parse_keyword("m")
2024-09-12 01:52:37 +02:00
assert.are.equals("rev", ktype)
assert.are.equals("mirroring", axis)
assert.are.equals(nil, sign)
2023-12-21 17:32:30 +01:00
end)
-- Error tests
it("should return error for bad axis", function()
local ktype, axis, sign = parse_keyword("-axv")
2024-09-12 01:52:37 +02:00
assert.are.equals("err", ktype)
2023-12-21 17:32:30 +01:00
end)
end)