-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.lua
47 lines (34 loc) · 917 Bytes
/
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
local Type = require("type")
local address = Type:number()
local address2 = address:extend():odd()
address:assert(2)
address2:assert(3)
local test = Type:boolean()
test:assert(false)
local user = Type:object({
name = Type:string(),
age = Type:number():integer(),
social = Type:object({
twitter = Type:string()
})
}):set_name("User")
user:assert({
name = "test",
age = 20,
social = {
twitter = "martonlederer"
}
})
local table1 = { "test", "haha", "test" }
local tabl_assert = Type:keys(Type:number()):values(Type:string())
tabl_assert:assert(table1)
local opt_type = Type:optional(Type:string())
local opt = "test"
opt_type:assert(opt)
opt = nil
opt_type:assert(opt)
local eithertest = Type:set_name("EitherTest"):either(Type:number(), Type:string(), Type:table())
eithertest:assert("true")
local nottest = Type:is_not(Type:string():length(2))
nottest:assert(2)
nottest:assert(2)