-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
89 lines (74 loc) · 1.83 KB
/
parser_test.go
File metadata and controls
89 lines (74 loc) · 1.83 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
89
package ham
import (
"bytes"
"encoding/json"
"fmt"
"os"
"testing"
"golang.org/x/net/html"
)
func TestParsePage(t *testing.T) {
file, _ := os.Open("./test-site/src/index.html")
// parse dom
doc, _ := html.Parse(file)
page := ParsePage(doc)
want := 4
got := len(page.Embeds)
if got != want {
t.Errorf("parse failed: expected %d but got %d page embeds", want, got)
}
want = 0
got = len(page.Layout.Js)
if got != want {
t.Errorf("parse failed: expected %d but got %d layout Js embeds", want, got)
}
want = 0
got = len(page.Layout.CSS)
if got != want {
t.Errorf("parse failed: expected %d but got %d layout CSS embeds", want, got)
}
buf := &bytes.Buffer{}
if err := html.Render(buf, doc); err != nil {
t.Errorf("render failed: %v", err)
}
fmt.Println(buf.String())
}
func TestParseLayout(t *testing.T) {
file, _ := os.Open("./test-site/src/default.lhtml")
// parse dom
doc, _ := html.Parse(file)
layout := ParseLayout(doc)
want := 3
got := len(layout.Embeds)
if got != want {
t.Errorf("parse failed: expected %d but got %d page embeds", want, got)
}
}
func TestConfigParse(t *testing.T) {
config := `{
"layout": "../layouts/authed.html",
"css": [
"../assets/css/global.css"
],
"js":[
"../assets/js/app.js"
]}`
var layout Layout
err := json.Unmarshal([]byte(config), &layout)
if err != nil {
t.Errorf("parse failed: %v", err)
return
}
if layout.Src != "../layouts/authed.html" {
t.Errorf("parse failed: expected %s but got %s", "../layouts/authed.html", layout.Src)
}
if len(layout.CSS) != 1 {
t.Errorf("parse failed: expected %d but got %d", 1, len(layout.CSS))
}
if len(layout.Js) != 1 {
t.Errorf("parse failed: expected %d but got %d", 1, len(layout.Js))
}
if len(layout.JsMod) != 0 {
t.Errorf("parse failed: expected %d but got %d", 0, len(layout.JsMod))
}
}