-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
90 lines (77 loc) · 1.78 KB
/
Copy pathparser_test.go
File metadata and controls
90 lines (77 loc) · 1.78 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
90
// Copyright (c) 2015, Ben Morgan. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
package pre
import (
"path/filepath"
"testing"
"github.com/goulash/osutil"
)
const (
testExt = "test"
resultExt = "result"
)
// proc is the default processor for our tests.
var proc *Processor
func TestParser(z *testing.T) {
proc = New()
proc.AddCommenter(CComment, true)
proc.AddCommenter(CppComment, true)
matches, err := filepath.Glob("testdata/*." + testExt)
if err != nil {
z.Fatal(err)
}
for _, m := range matches {
testParser(z, m)
}
}
func testParser(z *testing.T, path string) {
result := path[:len(path)-len(testExt)] + resultExt
ex, err := osutil.FileExists(result)
if err != nil {
z.Fatal(err)
}
if !ex {
z.Fatalf("missing result file: %s", result)
}
n, err := proc.Parse(path)
if err != nil {
z.Error(err)
return
}
r, err := proc.Parse(result)
if err != nil {
z.Error(err)
return
}
ns, rs := n.String(), r.String()
if ns == "" || rs == "" {
z.Errorf("neither test nor exp. result should be empty string")
} else if ns != rs {
z.Errorf("processed test did not match result\nGOT:\n%s\n\nEXPECTED:\n%s\n", ns, rs)
}
}
var tests = []struct {
Test string
Exp string
}{
{"// Comments will be stripped\nBut the rest of the file should remain.\n",
"\nBut the rest of the file should remain.\n"},
}
func TestSimple(z *testing.T) {
p := New()
p.AddCommenter(CppComment, true)
for _, t := range tests {
n, err := p.ParseString("internal", t.Test)
if err != nil {
z.Error(err)
}
if n.Len() == 0 {
z.Errorf("ParseString(%q).Len() == 0, want > 0", t.Test)
continue
}
if n.String() != t.Exp {
z.Errorf("ParseString(%q) = %q, want %q", t.Test, n.String(), t.Exp)
}
}
}