-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconverter_test.go
More file actions
114 lines (106 loc) · 4.52 KB
/
Copy pathconverter_test.go
File metadata and controls
114 lines (106 loc) · 4.52 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package gflowparser_test
import (
"io/ioutil"
"os"
"reflect"
"testing"
"github.com/flowdev/gflowparser"
"github.com/flowdev/gflowparser/data"
)
func TestConvertFlowDSLToSVG(t *testing.T) {
specs := []struct {
givenFlowName string
givenFlowContent string
expectedSVG string
expectedCompTypes []data.Type
expectedDataTypes []data.Type
expectedFeedback string
expectedError string
}{
{
givenFlowName: "simple success",
givenFlowContent: "in (data)-> [a] -> out",
expectedSVG: `<?xml version="1.0" ?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="259px" height="64px">
<!-- Generated by FlowDev tool. -->
<rect fill="rgb(255,255,255)" fill-opacity="1" stroke="none" stroke-opacity="1" stroke-width="0.0" width="259" height="64" x="0" y="0"/>
<line stroke="rgb(0,0,0)" stroke-opacity="1.0" stroke-width="2.5" x1="26" y1="25" x2="140" y2="25"/>
<line stroke="rgb(0,0,0)" stroke-opacity="1.0" stroke-width="2.5" x1="132" y1="17" x2="140" y2="25"/>
<line stroke="rgb(0,0,0)" stroke-opacity="1.0" stroke-width="2.5" x1="132" y1="33" x2="140" y2="25"/>
<line stroke="rgb(0,0,0)" stroke-opacity="1.0" stroke-width="2.5" x1="176" y1="25" x2="218" y2="25"/>
<line stroke="rgb(0,0,0)" stroke-opacity="1.0" stroke-width="2.5" x1="210" y1="17" x2="218" y2="25"/>
<line stroke="rgb(0,0,0)" stroke-opacity="1.0" stroke-width="2.5" x1="210" y1="33" x2="218" y2="25"/>
<rect fill="rgb(96,196,255)" fill-opacity="1.0" stroke="rgb(0,0,0)" stroke-opacity="1.0" stroke-width="2.5" width="36" height="48" x="140" y="7" rx="10" ry="10"/>
<text fill="rgb(0,0,0)" fill-opacity="1.0" font-family="monospace" font-size="16" x="3" y="31" textLength="22" lengthAdjust="spacingAndGlyphs" xml:space="preserve">in</text>
<text fill="rgb(0,0,0)" fill-opacity="1.0" font-family="monospace" font-size="16" x="41" y="17" textLength="72" lengthAdjust="spacingAndGlyphs" xml:space="preserve">(data)</text>
<text fill="rgb(0,0,0)" fill-opacity="1.0" font-family="monospace" font-size="16" x="152" y="31" textLength="12" lengthAdjust="spacingAndGlyphs" xml:space="preserve">a</text>
<text fill="rgb(0,0,0)" fill-opacity="1.0" font-family="monospace" font-size="16" x="221" y="31" textLength="34" lengthAdjust="spacingAndGlyphs" xml:space="preserve">out</text>
</svg>
`,
expectedCompTypes: []data.Type{
{LocalType: "a", SrcPos: 13},
},
expectedDataTypes: []data.Type{
{LocalType: "data", SrcPos: 4},
},
expectedFeedback: "",
expectedError: ``,
}, {
givenFlowName: "missing first data",
givenFlowContent: "in ()-> [a] -> out",
expectedSVG: ``,
expectedFeedback: "",
expectedError: `Found errors while parsing flow:
ERROR: File 'missing first data', line 1, column 1:
in ()-> [a] -> out
At least 1 matches expected but got only 0.
ERROR: File 'missing first data', line 1, column 1:
in ()-> [a] -> out
At least 2 matches expected but got only 0.
ERROR: File 'missing first data', line 1, column 1:
in ()-> [a] -> out
Any subparser should match. But all 2 subparsers failed.
ERROR: File 'missing first data', line 1, column 4:
in ()-> [a] -> out
Literal '->' expected.
ERROR: File 'missing first data', line 1, column 1:
in ()-> [a] -> out
Literal '[' expected.
`,
},
}
for _, spec := range specs {
t.Logf("Testing flow: %s\n", spec.givenFlowName)
gotSVG, gotCompTypes, gotDataTypes, gotFeedback, gotError := gflowparser.ConvertFlowDSLToSVG(
spec.givenFlowContent, spec.givenFlowName)
if spec.expectedError != "" && gotError != nil {
if spec.expectedError != gotError.Error() {
t.Errorf("Expected error '%s' but got: '%s'",
spec.expectedError, gotError)
}
} else if spec.expectedError != "" && gotError == nil {
t.Error("Expected an error but didn't get one.")
} else if spec.expectedError == "" && gotError != nil {
t.Errorf("Expected no error but got: %s", gotError)
}
if spec.expectedError != "" || gotError != nil {
continue
}
if !reflect.DeepEqual(gotCompTypes, spec.expectedCompTypes) {
t.Errorf("Expected component types '%#v' but got: '%#v'",
spec.expectedCompTypes, gotCompTypes)
}
if !reflect.DeepEqual(gotDataTypes, spec.expectedDataTypes) {
t.Errorf("Expected component types '%#v' but got: '%#v'",
spec.expectedDataTypes, gotDataTypes)
}
if spec.expectedFeedback != gotFeedback {
t.Errorf("Expected feedback '%s' but got: '%s'",
spec.expectedFeedback, gotFeedback)
}
if spec.expectedSVG != string(gotSVG) {
ioutil.WriteFile("fail.svg", gotSVG, os.FileMode(0644))
t.Fatal("Got unexpected SVG, please look into 'fail.svg'.")
}
}
}