| 1 |
package element |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
func TestSegmentHeaderGroupDataElements(t *testing.T) { |
| 6 |
header := NewSegmentHeader("abc", 1, 2) |
| 7 |
|
| 8 |
elements := header.GroupDataElements() |
| 9 |
|
| 10 |
expectedLength := 4 |
| 11 |
|
| 12 |
if expectedLength != len(elements) { |
| 13 |
t.Logf("Expected %d GroupDataElements, got %d\n", expectedLength, len(elements)) |
| 14 |
t.Fail() |
| 15 |
} |
| 16 |
|
| 17 |
header = NewReferencingSegmentHeader("abc", 1, 2, 3) |
| 18 |
|
| 19 |
elements = header.GroupDataElements() |
| 20 |
|
| 21 |
expectedLength = 4 |
| 22 |
|
| 23 |
if expectedLength != len(elements) { |
| 24 |
t.Logf("Expected %d GroupDataElements, got %d\n", expectedLength, len(elements)) |
| 25 |
t.Fail() |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
func TestSegmentHeaderString(t *testing.T) { |
| 30 |
header := NewSegmentHeader("abc", 1, 2) |
| 31 |
|
| 32 |
expectedString := "abc:1:2:" |
| 33 |
|
| 34 |
actualString := header.String() |
| 35 |
|
| 36 |
if expectedString != actualString { |
| 37 |
t.Logf("Expected String() to equal %q, was %q\n", expectedString, actualString) |
| 38 |
t.Fail() |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
func TestSegmentHeaderType(t *testing.T) { |
| 43 |
header := NewSegmentHeader("abc", 1, 2) |
| 44 |
|
| 45 |
expectedType := segmentHeaderDEG |
| 46 |
|
| 47 |
actualType := header.Type() |
| 48 |
|
| 49 |
if expectedType != actualType { |
| 50 |
t.Logf("Expected Type() to return %v, got %v\n", expectedType, actualType) |
| 51 |
t.Fail() |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
func TestSegmentHeaderUnmarshalHBCI(t *testing.T) { |
| 56 |
test := "HNHBK:1:3:4" |
| 57 |
|
| 58 |
elem := &SegmentHeader{} |
| 59 |
|
| 60 |
err := elem.UnmarshalHBCI([]byte(test)) |
| 61 |
|
| 62 |
if err != nil { |
| 63 |
t.Logf("Expected no error, got %T:%v\n", err, err) |
| 64 |
t.Fail() |
| 65 |
} |
| 66 |
|
| 67 |
expected := NewReferencingSegmentHeader("HNHBK", 1, 3, 4).String() |
| 68 |
|
| 69 |
actual := elem.String() |
| 70 |
|
| 71 |
if expected != actual { |
| 72 |
t.Logf("Expected element to equal\n%q\n\tgot\n%q\n", expected, actual) |
| 73 |
t.Fail() |
| 74 |
} |
| 75 |
} |