-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lua
59 lines (52 loc) · 1.32 KB
/
test.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
local S = require "structure"
local s = S.new {
a = S.NUMBER + S.NIL
}
assert(s:check { a = 1 })
s = S.BOOLEAN
assert(s:check(true))
assert(s:check(false) == false)
s = S.INTEGER
assert(s:check(1))
assert(s:check(0))
assert(s:check(-1))
assert(not s:check(1.1))
s = S.NIL
assert(s:check(nil) == nil)
s = S.NUMBER
assert(s:check(1))
s = S.FUNCTION
assert(s:check(function()end))
s = S.STRING
assert(s:check(""))
s = S.TABLE
assert(s:check({}))
s = S.new {}
assert(s:check({}))
local s = S.new {
probes = {
path = S.STRING,
matcher = S.STRING + S.FUNCTION,
},
matches = {
s = 1,
}
}
assert(function() s:check { probes = { path = '', matcher = function() end }, matches = { s = 1 } } end)
assert(function() s:check { probes = { path = '', matcher = nil }, matches = { s = 1 } } end)
local s = S.new {
["probes" + S.BOOLEAN] = {
{ -- array
path = S.STRING,
matcher = S.STRING / string.lower + S.FUNCTION,
},
},
matches = {
s = 1,
}
}
assert(s:check { probes = { {path = '', matcher = function() end}, }, matches = { s = 1 }, })
assert(s:check { [true] = { {path = '', matcher = function() end}, }, matches = { s = 1 }, })
local a = assert(s:check { probes = { {path = '', matcher = "Hi"}, }, matches = { s = 1 }, })
assert(a.probes[1].matcher == "hi")
assert(not s:check { matches = { s = 1 }, })