-
Notifications
You must be signed in to change notification settings - Fork 0
/
smetana_test.go
78 lines (68 loc) · 1.89 KB
/
smetana_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package smetana
import (
"reflect"
"runtime/debug"
"testing"
)
func assert[T any](t *testing.T, exp T, got T, equal bool) {
if reflect.DeepEqual(exp, got) != equal {
debug.PrintStack()
t.Fatalf("Expecting '%v' got '%v'\n", exp, got)
}
}
func assertEqual[T any](t *testing.T, exp T, got T) {
assert(t, exp, got, true)
}
func assertNotEqual[T any](t *testing.T, exp T, got T) {
assert(t, exp, got, false)
}
func assertOneOf[T any](t *testing.T, exp []T, got T) {
for _, option := range exp {
if reflect.DeepEqual(option, got) {
return
}
}
debug.PrintStack()
t.Fatalf("Expecting one of '%v' got '%v'\n", exp, got)
}
func TestCanCreateSmetanaContextWithDefaults(t *testing.T) {
smetana := NewSmetana()
assertEqual(t, 0, len(smetana.Styles.Elements))
assertEqual(t, 0, len(smetana.Palettes))
}
func TestCanCreateSmetanaContextWithPalettes(t *testing.T) {
smetana := NewSmetanaWithPalettes(Palettes{
"default": {
"color": Hex("#FFFFFF"),
},
})
assertEqual(t, 0, len(smetana.Styles.Elements))
assertEqual(t, 1, len(smetana.Palettes))
assertNotEqual(t, nil, smetana.Palettes["default"])
assertNotEqual(t, nil, smetana.Palettes["default"]["color"])
}
func TestCanAddAPaletteToASmetanaContext(t *testing.T) {
smetana := NewSmetana()
smetana.AddPalette("default", Palette{
"color": Hex("#FFFFFF"),
})
assertEqual(t, 1, len(smetana.Palettes))
assertNotEqual(t, nil, smetana.Palettes["default"])
assertNotEqual(t, nil, smetana.Palettes["default"]["color"])
}
func TestCanRenderStylesFromASmetanaContext(t *testing.T) {
smetana := NewSmetanaWithPalettes(Palettes{
"light": {
"bg": Hex("#FFFFFF"),
},
"dark": {
"bg": Hex("#000000"),
},
})
smetana.Styles.AddBlock("body", CssProps{
{"background", PaletteValue("bg")},
})
css := smetana.RenderStyles()
assertEqual(t, "body{background:#FFFFFF;}", css["light"])
assertEqual(t, "body{background:#000000;}", css["dark"])
}