-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
invokedAction_test.go
41 lines (36 loc) · 1.63 KB
/
invokedAction_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
package carapace
import (
"strings"
"testing"
"github.com/carapace-sh/carapace/pkg/style"
)
func TestToMultiParts(t *testing.T) {
_test := func(value, expected string, delimiter ...string) {
a := ActionStyledValuesDescribed(
"A/a:1", "one", style.Green,
"A/a:2", "two", style.BgBlue,
"A/b:3", "three", style.Red,
"B/b:4", "four", style.Magenta,
"B/c:5:1", "fiftyone", style.Black,
"B/c:5:2/z", "fiftytwo", style.Yellow,
"B/c/", "withsuffix", style.Underlined,
"C/d/1()2", "withbrackets", style.Yellow,
)
a = a.Invoke(Context{}).ToMultiPartsA(delimiter...)
if actual := a.Invoke(Context{Value: value}).value("export", value); !strings.Contains(actual, expected) {
t.Errorf("expected '%v' in '%v' for '%v'", expected, actual, value)
}
}
_test("A/a:1", `{"value":"A/a:1","display":"1","description":"one","style":"green"}`, "/", ":")
_test("A/a:1", `{"value":"A/a:1","display":"1","description":"one","style":"green"}`, ":", "/")
_test("A/a:1", `{"value":"A/a:1","display":"a:1","description":"one","style":"green"}`, "/")
_test("A", `{"value":"A/","display":"A/"}`, "/", ":")
_test("A", `{"value":"A/","display":"A/"}`, "/")
_test("", `{"value":"A/","display":"A/"}`, "/")
_test("A/", `{"value":"A/a:","display":"a:"}`, "/", ":")
_test("A/", `{"value":"A/a:1","display":"a:1","description":"one","style":"green"}`, "/")
_test("B/c:5", `{"value":"B/c:5:2/","display":"c:5:2/"}`, "/")
_test("B/c:5", `{"value":"B/c:5:","display":"5:"}`, "/", ":")
_test("B/c:5", `{"value":"B/c:5:","display":"5:"}`, ":", "/")
_test("C/d/1", `{"value":"C/d/1()2","display":"1()2","description":"withbrackets","style":"yellow"}`, "/")
}