-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment_test.go
50 lines (42 loc) · 1.28 KB
/
segment_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
package hedi
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestSegment_NewSegment(t *testing.T) {
segment := NewSegment("ISA")
assert.Equal(t, "ISA", segment.ID)
}
func TestSegment_String(t *testing.T) {
segment := NewSegment("ISA")
segment.AddElement(Element{Value: "00"})
segment.AddElement(Element{Value: "ZZ"})
assert.Equal(t, "ISA*00*ZZ~", segment.String())
}
func TestSegment_DString(t *testing.T) {
segment := NewSegment("ISA")
segment.AddElement(Element{Value: "00"})
segment.AddElement(Element{Value: "ZZ"})
assert.Equal(t, "ISA*00*ZZ~", segment.DString(DefaultDelimiters))
}
func TestSegment_GetElement(t *testing.T) {
segment := NewSegment("ISA")
segment.AddElement(Element{Value: "00"})
element, found := segment.GetElement(0)
assert.True(t, found)
assert.Equal(t, "00", element.Value)
_, found = segment.GetElement(1)
assert.False(t, found)
}
func TestSegment_AddElement(t *testing.T) {
segment := NewSegment("ISA")
segment.AddElement(Element{Value: "00"})
assert.Len(t, segment.Elements, 1)
assert.Equal(t, "00", segment.Elements[0].Value)
}
func TestSegment_SetElement(t *testing.T) {
segment := NewSegment("ISA")
segment.SetElement(1, Element{Value: "ZZ"})
assert.Len(t, segment.Elements, 2)
assert.Equal(t, "ZZ", segment.Elements[1].Value)
}