-
Notifications
You must be signed in to change notification settings - Fork 11
/
path_finder_test.go
97 lines (89 loc) · 2.49 KB
/
path_finder_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package gox12
import (
"testing"
)
// AAA
func TestMatcherISA(t *testing.T) {
finder := NewHeaderMapFinder()
//finder := MakeMapFinder()
str1 := "ISA&00& &00& "
seg := NewSegment(str1, '&', '!', '^')
foundPath, ok, _ := finder.FindNext("", seg)
if !ok {
t.Errorf("Should have found path for [%s], ok was false", foundPath)
}
expectedPath := "/ISA_LOOP/ISA"
if expectedPath != foundPath {
t.Errorf("Didn't get expected result [%s], instead got [%s]", expectedPath, foundPath)
}
}
func TestMatcherST(t *testing.T) {
finder := NewHeaderMapFinder()
str1 := "ST*001*AFD"
seg := NewSegment(str1, '*', '!', '^')
foundPath, ok, _ := finder.FindNext("", seg)
if !ok {
t.Errorf("Should have found path for [%s], ok was false", foundPath)
}
expectedPath := "/ISA_LOOP/GS_LOOP/ST_LOOP/ST"
if expectedPath != foundPath {
t.Errorf("Didn't get expected result [%s], instead got [%s]", expectedPath, foundPath)
}
}
func TestMatcherGE(t *testing.T) {
finder := NewHeaderMapFinder()
str1 := "GE*001*0002"
seg := NewSegment(str1, '*', '!', '^')
foundPath, ok, _ := finder.FindNext("", seg)
if !ok {
t.Errorf("Should have found path for [%s], ok was false", foundPath)
}
expectedPath := "/ISA_LOOP/GS_LOOP/GE"
if expectedPath != foundPath {
t.Errorf("Didn't get expected result [%s], instead got [%s]", expectedPath, foundPath)
}
}
func TestMatcherMissing(t *testing.T) {
finder := NewHeaderMapFinder()
str1 := "AAA*001*002"
seg := NewSegment(str1, '*', '!', '^')
foundPath, ok, _ := finder.FindNext("", seg)
if ok {
t.Errorf("Should not have found path for [%s], ok was true", foundPath)
}
expectedPath := ""
if expectedPath != foundPath {
t.Errorf("Didn't get expected result [%s], instead got [%s]", expectedPath, foundPath)
}
}
func TestMatcherAgg(t *testing.T) {
var tests = []struct {
isFound bool
spath string
seg_id string
}{
{true, "/ISA_LOOP/ISA", "ISA"},
{true, "/ISA_LOOP/GS_LOOP/ST_LOOP/ST", "ST"},
{false, "", "AAA"},
}
finder := NewFirstMatchPathFinder(NewHeaderMapFinder())
curPath := ""
for _, tt := range tests {
seg := Segment{SegmentId: tt.seg_id}
newpath, ok, err := finder.FindNext(curPath, seg)
if err != nil {
t.Errorf("Error for [%s]", tt.seg_id)
}
if ok != tt.isFound {
t.Errorf("Didn't get expected result [%s], instead got [%s]", tt.isFound, ok)
}
if newpath != tt.spath {
t.Errorf("Didn't get expected result [%s], instead got [%s]", tt.spath, newpath)
}
if ok {
curPath = newpath
} else {
curPath = ""
}
}
}