-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sx.lua
executable file
·52 lines (48 loc) · 1.51 KB
/
test_sx.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
#!/usr/bin/env lua
-- Copyright © 2025 Mark Summerfield. All rights reserved.
local lx = require("lx")
local sx = require("sx")
local check, report = require("check").checker()
local e = "this and that"
local s = " \tthis and that\n"
local t = sx.trim(s)
check(e == t)
check(s ~= t)
check(e == sx.trim(s))
check(sx.contains(s, "and"))
check(not sx.contains(s, "the"))
check("XYis and XYat" == sx.replace(e, "th", "XY"))
check(e == sx.replace(e, "thx", "Z"))
check(sx.startswith(e, "thi"))
check(not sx.startswith(e, "thiS"))
check(sx.endswith(e, "hat"))
check(not sx.endswith(e, "Hat"))
check("thistle and that" == sx.insert(e, 5, "tle"))
check("A this and that" == sx.insert(e, 1, "A "))
t = " \tthis and\t that\n"
check("this and that" == sx.clean(t))
t = "AbcdE"
check("A" == sx.at(t, 1))
check("b" == sx.at(t, 2))
check("c" == sx.at(t, 3))
check("d" == sx.at(t, 4))
check("E" == sx.at(t, 5))
check("A" == sx.at(t, -5))
check("b" == sx.at(t, -4))
check("c" == sx.at(t, -3))
check("d" == sx.at(t, -2))
check("E" == sx.at(t, -1))
check(sx.isin("cat", "dog", "pie", "cat"))
check(not sx.isin("cap", "dog", "pie", "cat"))
check(sx.isin("cat", { "dog", "pie", "cat" }))
check(not sx.isin("cap", { "dog", "pie", "cat" }))
local line = " LET A=0"
check(sx.trim(line) == "LET A=0")
local a = sx.chars("One € … two!")
local b =
{ "O", "n", "e", " ", "€", " ", "…", " ", "t", "w", "o", "!" }
check(lx.dump(a) == lx.dump(b))
-- for pos, c in utf8.codes("One € … two!") do
-- print(pos, utf8.char(c))
-- end
report("sx")