-
Notifications
You must be signed in to change notification settings - Fork 0
/
segments_test.go
64 lines (53 loc) · 1.62 KB
/
segments_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
package hedi
import (
"bytes"
"github.com/stretchr/testify/assert"
"testing"
)
func TestSegments_String(t *testing.T) {
seg := Segments{
Segment{ID: "ISA", Elements: Elements{{Value: "00"}}},
Segment{ID: "GS", Elements: Elements{{Value: "PO"}}},
}
assert.Equal(t, "ISA*00~GS*PO~", seg.String())
}
func TestSegments_DString(t *testing.T) {
seg := Segments{
Segment{ID: "ISA", Elements: Elements{{Value: "00"}}},
Segment{ID: "GS", Elements: Elements{{Value: "PO"}}},
}
delimiters := Delimiters{Element: '|', SubElement: ':', Segment: '~'}
assert.Equal(t, "ISA|00~GS|PO~", seg.DString(delimiters))
}
func TestSegments_WriteTo(t *testing.T) {
seg := Segments{
Segment{ID: "ISA", Elements: Elements{{Value: "00"}}},
Segment{ID: "GS", Elements: Elements{{Value: "PO"}}},
}
buf := bytes.NewBuffer([]byte{})
n, err := seg.WriteTo(buf)
assert.NoError(t, err)
assert.Equal(t, int64(13), n)
assert.Equal(t, "ISA*00~GS*PO~", buf.String())
}
func TestSegments_DWriteTo(t *testing.T) {
seg := Segments{
Segment{ID: "ISA", Elements: Elements{{Value: "00"}}},
Segment{ID: "GS", Elements: Elements{{Value: "PO"}}},
}
buf := bytes.NewBuffer([]byte{})
delimiters := Delimiters{Element: '|', SubElement: ':', Segment: '~'}
n, err := seg.DWriteTo(delimiters, buf)
assert.NoError(t, err)
assert.Equal(t, int64(13), n)
assert.Equal(t, "ISA|00~GS|PO~", buf.String())
}
func TestSegments_Last(t *testing.T) {
seg := Segments{
Segment{ID: "ISA", Elements: Elements{{Value: "00"}}},
Segment{ID: "GS", Elements: Elements{{Value: "PO"}}},
}
lastSeg, ok := seg.Last()
assert.True(t, ok)
assert.Equal(t, "GS", lastSeg.ID)
}