-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathcss_test.go
More file actions
88 lines (74 loc) · 1.74 KB
/
Copy pathcss_test.go
File metadata and controls
88 lines (74 loc) · 1.74 KB
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
81
82
83
84
85
86
87
88
package languages
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zzet/gortex/internal/graph"
)
func TestCSSExtractor_Selectors(t *testing.T) {
src := []byte(`.container {
display: flex;
}
#main-content {
padding: 20px;
}
:root {
--primary-color: #333;
}
`)
e := NewCSSExtractor()
result, err := e.Extract("style.css", src)
require.NoError(t, err)
// Should have file node at minimum.
assert.GreaterOrEqual(t, len(result.Nodes), 1)
}
func TestCSSExtractor_Import(t *testing.T) {
src := []byte(`@import url("reset.css");
@import "theme.css";
`)
e := NewCSSExtractor()
result, err := e.Extract("style.css", src)
require.NoError(t, err)
imports := edgesOfKind(result.Edges, graph.EdgeImports)
assert.GreaterOrEqual(t, len(imports), 1)
}
func TestCSSExtractor_ClassSelector(t *testing.T) {
src := []byte(`.btn {
padding: 10px;
}
.btn-primary {
color: blue;
}
`)
e := NewCSSExtractor()
result, err := e.Extract("buttons.css", src)
require.NoError(t, err)
types := nodesOfKind(result.Nodes, graph.KindType)
assert.GreaterOrEqual(t, len(types), 2)
}
func TestCSSExtractor_IDSelector(t *testing.T) {
src := []byte(`#header {
height: 60px;
}
#footer {
height: 40px;
}
`)
e := NewCSSExtractor()
result, err := e.Extract("layout.css", src)
require.NoError(t, err)
vars := nodesOfKind(result.Nodes, graph.KindVariable)
assert.GreaterOrEqual(t, len(vars), 2)
}
func TestCSSExtractor_CustomProperties(t *testing.T) {
src := []byte(`:root {
--primary-color: #333;
--font-size: 16px;
}
`)
e := NewCSSExtractor()
result, err := e.Extract("vars.css", src)
require.NoError(t, err)
vars := nodesOfKind(result.Nodes, graph.KindVariable)
assert.GreaterOrEqual(t, len(vars), 2)
}