2 _G.vector = {metatable = {}}
3 dofile("builtin/common/vector.lua")
4 dofile("builtin/common/misc_helpers.lua")
6 describe("string", function()
7 it("trim()", function()
8 assert.equal("foo bar", string.trim("\n \t\tfoo bar\t "))
11 describe("split()", function()
12 it("removes empty", function()
13 assert.same({ "hello" }, string.split("hello"))
14 assert.same({ "hello", "world" }, string.split("hello,world"))
15 assert.same({ "hello", "world" }, string.split("hello,world,,,"))
16 assert.same({ "hello", "world" }, string.split(",,,hello,world"))
17 assert.same({ "hello", "world", "2" }, string.split("hello,,,world,2"))
18 assert.same({ "hello ", " world" }, string.split("hello :| world", ":|"))
21 it("keeps empty", function()
22 assert.same({ "hello" }, string.split("hello", ",", true))
23 assert.same({ "hello", "world" }, string.split("hello,world", ",", true))
24 assert.same({ "hello", "world", "" }, string.split("hello,world,", ",", true))
25 assert.same({ "hello", "", "", "world", "2" }, string.split("hello,,,world,2", ",", true))
26 assert.same({ "", "", "hello", "world", "2" }, string.split(",,hello,world,2", ",", true))
27 assert.same({ "hello ", " world | :" }, string.split("hello :| world | :", ":|"))
30 it("max_splits", function()
31 assert.same({ "one" }, string.split("one", ",", true, 2))
32 assert.same({ "one,two,three,four" }, string.split("one,two,three,four", ",", true, 0))
33 assert.same({ "one", "two", "three,four" }, string.split("one,two,three,four", ",", true, 2))
34 assert.same({ "one", "", "two,three,four" }, string.split("one,,two,three,four", ",", true, 2))
35 assert.same({ "one", "two", "three,four" }, string.split("one,,,,,,two,three,four", ",", false, 2))
38 it("pattern", function()
39 assert.same({ "one", "two" }, string.split("one,two", ",", false, -1, true))
40 assert.same({ "one", "two", "three" }, string.split("one2two3three", "%d", false, -1, true))
45 describe("privs", function()
46 it("from string", function()
47 assert.same({ a = true, b = true }, core.string_to_privs("a,b"))
50 it("to string", function()
51 assert.equal("one", core.privs_to_string({ one=true }))
53 local ret = core.privs_to_string({ a=true, b=true })
54 assert(ret == "a,b" or ret == "b,a")
58 describe("pos", function()
59 it("from string", function()
60 assert.equal(vector.new(10, 5.1, -2), core.string_to_pos("10.0, 5.1, -2"))
61 assert.equal(vector.new(10, 5.1, -2), core.string_to_pos("( 10.0, 5.1, -2)"))
62 assert.is_nil(core.string_to_pos("asd, 5, -2)"))
65 it("to string", function()
66 assert.equal("(10.1,5.2,-2.3)", core.pos_to_string({ x = 10.1, y = 5.2, z = -2.3}))
70 describe("table", function()
71 it("indexof()", function()
72 assert.equal(1, table.indexof({"foo", "bar"}, "foo"))
73 assert.equal(-1, table.indexof({"foo", "bar"}, "baz"))