-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_test.v
80 lines (65 loc) · 1.56 KB
/
cmd_test.v
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module clive
const cmd_name = 'my_cmd'
const cmd_alias = 'mc'
const cmd_desc = 'My Command'
fn test_cmd_new() {
cmd := Cmd.new(
name: clive.cmd_name
alias: clive.cmd_alias
description: clive.cmd_desc
exec: cmd_exec
)
assert cmd.name == clive.cmd_name
assert cmd.alias == clive.cmd_alias
assert cmd.description == cmd.description
assert cmd.exec == cmd_exec
}
fn test_cmd_new_defaults() {
cmd := Cmd.new(name: clive.cmd_name)
assert cmd.name == clive.cmd_name
assert cmd.alias.is_blank()
assert cmd.description.is_blank()
assert isnil(cmd.exec)
}
fn test_cmds_add() {
mut cmd1 := Cmd.new(name: 'cmd1')
cmd2 := Cmd.new(name: 'cmd2', alias: 'c2')
cmd1.cmds.add(cmd2)
mut name_exists := true
cmd1.cmds.get(cmd2.name) or { name_exists = false }
assert name_exists
mut alias_exists := true
cmd1.cmds.get(cmd2.alias) or { alias_exists = false }
assert alias_exists
}
fn test_cmds_get() {
mut cmd1 := Cmd.new(name: 'cmd1')
cmd2 := Cmd.new(name: 'cmd2', alias: 'c2')
cmd1.cmds.add(cmd2)
match cmd1.cmds.get(cmd2.name) {
none { assert false }
else { assert true }
}
match cmd1.cmds.get(cmd2.alias) {
none { assert false }
else { assert true }
}
}
fn test_cmds_get_none() {
cmd := Cmd.new(name: clive.cmd_name)
match cmd.cmds.get('does-not-exist') {
none { assert true }
else { assert false }
}
}
fn test_cmds_new_adds_help() {
cmd := Cmd.new(name: clive.cmd_name)
mut exists := true
cmd.cmds.get('help') or { exists = false }
assert exists
exists = true
cmd.cmds.get('h') or { exists = false }
assert !exists
}
fn cmd_exec(args Args) {
}