-
Notifications
You must be signed in to change notification settings - Fork 36
/
parse_test.go
59 lines (50 loc) · 1 KB
/
parse_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
package main
import (
"bytes"
"strings"
"testing"
"text/template"
)
func TestErd_unquote(t *testing.T) {
e := &Erd{}
value := e.unquote("\"test\"")
if value != "test" {
t.Errorf("got: %v\nwant: %v", value, "test")
}
}
func TestIntegration(t *testing.T) {
contents := `
[Person]
*name
height
weight
+birth_location_id
[Location]
*id
city
state
country
Person *--1 Location
`
parser := &Parser{Buffer: contents}
err := parser.Init()
if err != nil {
t.Fatal(err)
}
err = parser.Parse()
if err != nil {
t.Fatal(err)
}
parser.Execute()
if parser.Erd.IsError {
t.Fatal()
}
dot, _ := Asset("templates/dot.tmpl")
tables, _ := Asset("templates/dot_tables.tmpl")
relations, _ := Asset("templates/dot_relations.tmpl")
templates := template.Must(template.New("").Funcs(template.FuncMap{"StringsJoin": strings.Join}).Parse(string(dot) + string(tables) + string(relations)))
fd := bytes.NewBufferString("")
if err := templates.ExecuteTemplate(fd, "dot", parser.Erd); err != nil {
t.Fatal(err)
}
}