-
Notifications
You must be signed in to change notification settings - Fork 5
/
value_test.go
46 lines (40 loc) · 1.23 KB
/
value_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
package css
import (
"testing"
"github.com/gorilla/css/scanner"
"github.com/stretchr/testify/assert"
)
func TestCSSValue(t *testing.T) {
for _, c := range []struct{ inp, out string }{
{`"identifier"`, `identifier`},
{`identifier/path`, `identifier/path`},
{`"with \' \" \\ chars"`, `with ' " \ chars`},
} {
t.Run(c.inp, func(t *testing.T) {
val := NewCSSValue(c.inp)
assert.Equal(t, val.Text(), c.inp)
assert.Equal(t, val.ParsedText(), c.out)
})
}
}
func TestNewCSSValueString(t *testing.T) {
for _, c := range []struct{ inp, out string }{
{`identifier`, `"identifier"`},
{`with special ' \ " char`, `"with special ' \\ \" char"`},
} {
t.Run(c.inp, func(t *testing.T) {
val := NewCSSValueString(c.inp)
assert.Equal(t, val.Text(), c.out)
assert.Equal(t, val.ParsedText(), c.inp)
})
}
}
func TestSplitOnToken(t *testing.T) {
val := NewCSSValue(`monospace, font-name, "font3",sans-serif`)
split := val.SplitOnToken(&scanner.Token{Type: scanner.TokenChar, Value: ","})
assert.Equal(t, len(split), 4)
assert.Equal(t, split[0].ParsedText(), "monospace")
assert.Equal(t, split[1].ParsedText(), "font-name")
assert.Equal(t, split[2].ParsedText(), "font3")
assert.Equal(t, split[3].ParsedText(), "sans-serif")
}