-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathparser_test.go
More file actions
40 lines (35 loc) · 979 Bytes
/
parser_test.go
File metadata and controls
40 lines (35 loc) · 979 Bytes
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
package main
import (
"testing"
)
func TestIsHeartbeat(t *testing.T) {
heartbeat := "SR0001L0001 006969XX [ID00000000]"
match := IsHeartbeat([]byte(heartbeat))
if !match {
t.Fatal("HB match fail")
}
nobeat := "some other text"
match = IsHeartbeat([]byte(nobeat))
if match {
t.Fatal("HB matched while it shouldn't")
}
}
func TestParseSIA(t *testing.T) {
sia := "01010053\"SIA-DCS\"0007R0075L0001[#001465|NRP000*'DECKERS'NM]7C9677F21948CC12|#001465"
match, err := ParseSIA([]byte(sia))
if err != nil {
t.Fatal("SIA match fail")
}
if len(match) != 6 {
t.Fatalf("Didn't find all fields, found (%d)", len(match))
}
if match[0] != "0007" || match[1] != "0075" || match[2] != "0001" ||
match[3] != "001465" || match[4] != "RP" || match[5] != "000" {
t.Fatalf("Failed to match sequence %v", match)
}
sia = "01010053\"SIA-DCS\"0007R0075L0001[#001465"
_, err = ParseSIA([]byte(sia))
if err == nil {
t.Fatal("SIA match should have failed")
}
}