-
Notifications
You must be signed in to change notification settings - Fork 11
/
rawx12file_test.go
124 lines (118 loc) · 3.91 KB
/
rawx12file_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package gox12
import (
"log"
"os"
"strings"
"testing"
)
// AAA
func TestArbitraryDelimiters(t *testing.T) {
str1 := "ISA&00& &00& &ZZ&ZZ000 &ZZ&ZZ001 &030828&1128&U&00401&000010121&0&T&!+\n"
str1 += "GS&HC&ZZ000&ZZ001&20030828&1128&17&X&004010X098+\n"
str1 += "ST&837&11280001+\n"
str1 += "TST&AA!1!1&BB!5+\n"
str1 += "SE&3&11280001+\n"
str1 += "GE&1&17+\n"
str1 += "IEA&1&000010121+\n"
inFile := strings.NewReader(str1)
raw, err := NewRawX12FileReader(inFile)
if err != nil {
t.Errorf("NewRawX12FileReader failed")
}
//expectedDelimeters := Delimiters{'+', '&', '!', 0}
expectedSegTerm := '+'
expectedElementTerm := '&'
expectedSubelementTerm := '!'
expectedRepetitionTerm := 0
if raw.segmentTerm != byte(expectedSegTerm) {
t.Errorf("Didn't get expected result [%c], instead got [%c]", expectedSegTerm, raw.segmentTerm)
}
if raw.elementTerm != byte(expectedElementTerm) {
t.Errorf("Didn't get expected result [%c], instead got [%c]", expectedElementTerm, raw.elementTerm)
}
if raw.subelementTerm != byte(expectedSubelementTerm) {
t.Errorf("Didn't get expected result [%c], instead got [%c]", expectedSubelementTerm, raw.subelementTerm)
}
if raw.repetitionTerm != byte(expectedRepetitionTerm) {
t.Errorf("Didn't get expected result [%c], instead got [%c]", expectedRepetitionTerm, raw.repetitionTerm)
}
expectedCount := 7
ct := 0
for _ = range raw.GetSegments() {
ct += 1
}
if ct != expectedCount {
t.Errorf("Didn't get expected segment count of %d, instead got %d", expectedCount, ct)
}
}
func TestArbitraryDelimiters5010(t *testing.T) {
str1 := "ISA&00& &00& &ZZ&ZZ000 &ZZ&ZZ001 &030828&1128&^&00501&000010121&0&T&!+\n"
str1 += "GS&HC&ZZ000&ZZ001&20030828&1128&17&X&005010X223+\n"
str1 += "ST&837&11280001+\n"
str1 += "TST&AA!1!1&BB!5+\n"
str1 += "SE&3&11280001+\n"
str1 += "GE&1&17+\n"
str1 += "IEA&1&000010121+\n"
inFile := strings.NewReader(str1)
raw, err := NewRawX12FileReader(inFile)
if err != nil {
t.Errorf("NewRawX12FileReader failed")
}
//expectedDelimeters := Delimiters{'+', '&', '!', 0}
expectedSegTerm := '+'
expectedElementTerm := '&'
expectedSubelementTerm := '!'
expectedRepetitionTerm := '^'
if raw.segmentTerm != byte(expectedSegTerm) {
t.Errorf("Didn't get expected result [%c], instead got [%c]", expectedSegTerm, raw.segmentTerm)
}
if raw.elementTerm != byte(expectedElementTerm) {
t.Errorf("Didn't get expected result [%c], instead got [%c]", expectedElementTerm, raw.elementTerm)
}
if raw.subelementTerm != byte(expectedSubelementTerm) {
t.Errorf("Didn't get expected result [%c], instead got [%c]", expectedSubelementTerm, raw.subelementTerm)
}
if raw.repetitionTerm != byte(expectedRepetitionTerm) {
t.Errorf("Didn't get expected result [%c], instead got [%c]", expectedRepetitionTerm, raw.repetitionTerm)
}
expectedCount := 7
ct := 0
for _ = range raw.GetSegments() {
ct += 1
}
if ct != expectedCount {
t.Errorf("Didn't get expected segment count of %d, instead got %d", expectedCount, ct)
}
}
//str1 = strings.Replace(str1, "&", "\x1C", -1)
func X12InterchangeControlVersion5010(t *testing.T) {
isa_line := "ISA&00& &00& &ZZ&ZZ000 &ZZ&ZZ001 &030828&1128&^&00501&000010121&0&T&!+\n"
inFile := strings.NewReader(isa_line)
raw, err := NewRawX12FileReader(inFile)
if err != nil {
t.Errorf("NewRawX12FileReader failed")
}
expected := "00501"
if raw.icvn != expected {
t.Errorf("Didn't get expected result [%s], instead got s%c]", expected, raw.icvn)
}
}
func testParse834(t *testing.T) {
inFilename := "test834.txt"
//inFile *os.File
//inFile io.Reader
inFile, err := os.Open(inFilename)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
defer inFile.Close()
raw, err := NewRawX12FileReader(inFile)
ct := 0
for _ = range raw.GetSegments() {
ct += 1
}
if ct != 7 {
t.Errorf("Didn't get expected segment count of %d, instead got %d", 7, ct)
}
}