-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_test.go
55 lines (43 loc) · 1.4 KB
/
class_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
package merge
import (
"fmt"
"slices"
"strings"
"testing"
)
func TestClassMergeFuncSimple(t *testing.T) {
m := New(map[string][]MergeFunc{
"class": {ClassMergeFunc},
})
existingClasses := []string{"px-3", "mx-2", "bg-red-500"}
incomingClasses := []string{"font-bold"}
res := m.Merge(map[string]any{"class": strings.Join(existingClasses, " ")}, map[string]any{"class": strings.Join(incomingClasses, " ")})
fmt.Println(res)
for _, val := range []string{"px-3", "mx-2", "bg-red-500", "font-bold"} {
classesStr := fmt.Sprint(res["class"])
arr := strings.Split(classesStr, " ")
if !slices.Contains(arr, val) {
t.Fatalf("Expected %v to include class=%q", res, val)
}
}
}
func TestClassMergeFuncCollision(t *testing.T) {
m := New(map[string][]MergeFunc{
"class": {ClassMergeFunc},
})
existingClasses := []string{"px-4", "mx-2", "bg-red-500"}
incomingClasses := []string{"font-bold", "px-4"}
res := m.Merge(map[string]any{"class": strings.Join(existingClasses, " ")}, map[string]any{"class": strings.Join(incomingClasses, " ")})
fmt.Println(res)
classesStr := fmt.Sprint(res["class"])
arr := strings.Split(classesStr, " ")
expectedArr := []string{"px-4", "mx-2", "bg-red-500", "font-bold"}
for _, val := range expectedArr {
if !slices.Contains(arr, val) {
t.Fatalf("Expected %v to include class=%q", res, val)
}
}
if len(arr) != len(expectedArr) {
t.Fatal("Too many classes")
}
}