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
60
61
62
63
64
65local utils = require('codeshot.utils')
describe('Generate Args', function()
it('Test generate from object', function()
local args = {
b = true,
boolean = false,
str = 'Hola',
str_empty = '',
algo = nil,
show_a = false,
}
assert.are.same(utils.obj_to_args(args), { '-b', '--str', "'Hola'" })
end)
it('Test ignore from object', function()
local args = {
b = true,
boolean = false,
str = 'Hola',
str_empty = '',
algo = nil,
show_a = false,
}
local ignore = { 'b' }
assert.are.same(utils.obj_to_args(args, ignore), { '--str', "'Hola'" })
end)
end)
describe('Validation objects', function()
it('Basic test', function()
local default = {
b = true,
boolean = false,
str = 'Hola',
str_empty = '',
algo = nil,
show_a = false,
}
local rcv = {
str = 'Hola',
str_empty = '',
algo = nil,
show_a = false,
}
utils.validate(default, rcv)
end)
it('Bad Types', function()
local default = {
name = 'Hola',
}
local rcv = {
name = false,
}
local res = function()
utils.validate(default, rcv)
end
assert.has_error(res, "Validation failed: for 'name' we expected a value of type: 'string'")
end)
end)