forked from Joker/jade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjade_test.go
80 lines (65 loc) · 1.52 KB
/
jade_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
79
80
package jade
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"github.com/Joker/hpp"
)
func TestJadeExamples(t *testing.T) {
PrettyOutput = false
files, _ := ioutil.ReadDir("./testdata")
var name, fext string
for _, file := range files {
name = file.Name()
fext = filepath.Ext(name)
if fext != ".jade" && fext != ".pug" {
continue
}
fmt.Println("_________" + name)
dat, err := ioutil.ReadFile("testdata/" + name)
if err != nil {
fmt.Printf("--- FAIL: ReadFile error: %v\n\n", err)
t.Fail()
continue
}
tpl, err := Parse(name, string(dat))
if err != nil {
fmt.Printf("--- FAIL: Parse error: %v\n\n", err)
t.Fail()
continue
}
tmpl := bufio.NewScanner(bytes.NewReader(hpp.Print(strings.NewReader(tpl))))
tmpl.Split(bufio.ScanLines)
inFile, err := os.Open("testdata/" + strings.TrimSuffix(name, fext) + ".html")
if err != nil {
fmt.Println("```", tpl, "\n\n```")
ioutil.WriteFile("testdata/"+strings.TrimSuffix(name, fext)+".html", hpp.Print(strings.NewReader(tpl)), 0644)
continue
}
html := bufio.NewScanner(inFile)
html.Split(bufio.ScanLines)
nilerr, line := 0, 0
for tmpl.Scan() {
html.Scan()
a := tmpl.Text()
b := html.Text()
line += 1
if strings.Compare(a, b) != 0 && nilerr < 4 {
fmt.Printf("%s\n%s\n%d^___________________________\n", a, b, line)
nilerr += 1
t.Fail()
}
}
inFile.Close()
if nilerr == 0 {
fmt.Println(" PASS\n ")
} else {
fmt.Println("--- FAIL\n ")
}
}
}