forked from aerogo/scarlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRename_test.go
57 lines (48 loc) · 1.06 KB
/
Rename_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
package starlet
import (
"fmt"
"os"
"reflect"
"strings"
"testing"
"github.com/aerogo/codetree"
)
func TestRename(t *testing.T) {
reader, _ := os.Open("testdata/classes.strlt")
tree, err := codetree.FromReader(reader)
defer reader.Close()
if err != nil {
t.Fatal(err)
return
}
compiler := FromCodeTree(tree)
renamingMap := compiler.RenameClasses()
builder := &strings.Builder{}
compiler.Render(builder, false)
css := builder.String()
wantedMap := &RenamingMap{
Map: map[string]string{
"class": "a",
"foo": "b",
"bar": "c",
},
Len: 3,
}
if !reflect.DeepEqual(renamingMap, wantedMap) {
t.Errorf("RenamingMap doesn't match: %#v != %#v", renamingMap, wantedMap)
}
wantedCSS := ".a .a-b{font-weight:bold}.a .a-c{font-style:italic}"
if css != wantedCSS {
t.Errorf("CSS output doesn't match: %s != %s", css, wantedCSS)
}
}
func TestAssign(t *testing.T) {
m := NewRenamingMap()
a := ""
for i := 0; i < 1000; i++ {
a = m.Assign(fmt.Sprintf("LongID%d", i))
}
if a != "aa1" {
t.Errorf("Last assigned class name was %s", a)
}
}