-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
macro_test.go
62 lines (49 loc) · 1.73 KB
/
macro_test.go
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
package spec
import (
"testing"
"github.com/carapace-sh/carapace"
)
type Arg struct {
Name string
Option bool
}
func (a Arg) Default() Arg {
a.Option = true
return a
}
func TestSignature(t *testing.T) {
signature := MacroI(func(a Arg) carapace.Action { return carapace.ActionValues() }).macro.Signature()
if expected := `{name: "", option: false}`; signature != expected {
t.Errorf("should be: %v", expected)
}
signature = MacroI(func(a []Arg) carapace.Action { return carapace.ActionValues() }).macro.Signature()
if expected := `[{name: "", option: false}]`; signature != expected {
t.Errorf("should be: %v", expected)
}
signature = MacroI(func(b bool) carapace.Action { return carapace.ActionValues() }).macro.Signature()
if expected := `false`; signature != expected {
t.Errorf("should be: %v", expected)
}
signature = MacroV(func(a ...Arg) carapace.Action { return carapace.ActionValues() }).macro.Signature()
if expected := `[{name: "", option: false}]`; signature != expected {
t.Errorf("should be: %v", expected)
}
signature = MacroV(func(b ...bool) carapace.Action { return carapace.ActionValues() }).macro.Signature()
if expected := `[false]`; signature != expected {
t.Errorf("should be: %v", expected)
}
signature = MacroI(func(s string) carapace.Action { return carapace.ActionValues() }).macro.Signature()
if expected := `""`; signature != expected {
t.Errorf("should be: %v", expected)
}
}
func TestDefault(t *testing.T) {
var actual Arg
m := MacroI(func(a Arg) carapace.Action { actual = a; return carapace.ActionValues() })
if m.Parse("$default"); !actual.Option {
t.Error("should be true (default)")
}
if m.Parse("$default({option: false})"); actual.Option {
t.Error("should be false")
}
}