-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentity_test.go
65 lines (51 loc) · 1.92 KB
/
entity_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
package main
import (
"testing"
"github.com/blefort/DTDParser/DTD"
)
// loadEntityTests Load entity tests
func loadEntityTests(file string) []DTD.Entity {
var tests []DTD.Entity
loadJSON(file, &tests)
return tests
}
func TestParseEntityBlock(t *testing.T) {
// - parse the DTD test
// - compare it to data stored in a json file
// - render it in the tmp dir
log.Warn("Start tests on 'tests/entity.dtd'")
testEntityDTD(t, "tests/entity.dtd", true)
// - load the generated DTD
// - compare it to data stored in a json file
// log.Warn("Start tests on generated 'tmp/entity.dtd'")
testEntityDTD(t, "tmp/entity.dtd", false)
}
// testEntityDTD Main testing func for entity
func testEntityDTD(t *testing.T, path string, recreate bool) {
var tests []DTD.Entity
var dir string
if recreate {
dir = "tmp"
} else {
dir = "tmp2"
}
// New parser
p := newParser(dir)
p.Parse(path)
tests = loadEntityTests("tests/entity.json")
if len(p.Collection) != len(tests) {
t.Errorf("Number of elements in the collection (%d) differs from number of tests (%d), please update either your DTD test or the corresponding json file", len(p.Collection), len(tests))
t.SkipNow()
}
for idx, test := range tests {
entityBlock := p.Collection[idx].(*DTD.Entity)
t.Run("Check name", checkStrValue(entityBlock.Name, test.Name, entityBlock, test))
t.Run("Check value", checkStrValue(entityBlock.Value, test.Value, entityBlock, test))
t.Run("Check Parameter", checkBoolValue(entityBlock.Parameter, test.Parameter, entityBlock, test))
t.Run("Check System", checkBoolValue(entityBlock.System, test.System, entityBlock, test))
t.Run("Check Public", checkBoolValue(entityBlock.Public, test.Public, entityBlock, test))
t.Run("Check External Entity", checkBoolValue(entityBlock.IsExternal, test.IsExternal, entityBlock, test))
t.Run("Check Url", checkStrValue(entityBlock.Url, test.Url, entityBlock, test))
}
t.Run("Render DTD", render(p))
}