forked from Matir/adifparser
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adifrecord_test.go
94 lines (81 loc) · 2.08 KB
/
adifrecord_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
package adifparser
import (
"strings"
"testing"
)
func TestGetFields(t *testing.T) {
testData := "<call:4>W1AW<STATION_CALL:6>KF4MDV <EOR>"
expected := [2]string{"call", "station_call"}
buf := strings.NewReader(testData)
reader := NewADIFReader(buf)
record, err := reader.ReadRecord()
if err != nil {
t.Fatal(err)
}
fieldNames := record.GetFields()
if len(fieldNames) != len(expected) {
t.Fatalf("Expected %d fields but got %d", len(expected), len(fieldNames))
}
OUTER:
for _, exp := range expected {
for _, field := range fieldNames {
if exp == field {
continue OUTER
}
}
t.Fatalf("Expected field %v wasn't in the actual fields", exp)
}
}
func TestSetValue(t *testing.T) {
testData := map[string]string{"call": "W1AW", "STATION_CALL": "KF4MDV"}
expected := [2]string{"call", "station_call"}
record := NewADIFRecord()
for k, v := range testData {
record.SetValue(k, v)
}
fieldNames := record.GetFields()
if len(fieldNames) != len(expected) {
t.Fatalf("Expected %d fields but got %d", len(expected), len(fieldNames))
}
OUTER:
for _, exp := range expected {
for _, field := range fieldNames {
if exp == field {
continue OUTER
}
}
t.Fatalf("Expected field %v wasn't in the actual fields", exp)
}
}
func TestDeleteField(t *testing.T) {
testData := map[string]string{
"call": "W1AW",
"notes": "This is a notice",
"STATION_CALL": "KF4MDV"}
expected := [2]string{"call", "station_call"}
record := NewADIFRecord()
for k, v := range testData {
record.SetValue(k, v)
}
success, err := record.DeleteField("nothere")
if err != ErrNoSuchField {
t.Fatal(err)
}
success, err = record.DeleteField("notes")
if !success || err != nil {
t.Fatalf("success: %t, err: %v", success, err)
}
fieldNames := record.GetFields()
if len(fieldNames) != len(expected) {
t.Fatalf("Expected %d fields but got %d", len(expected), len(fieldNames))
}
OUTER:
for _, exp := range expected {
for _, field := range fieldNames {
if exp == field {
continue OUTER
}
}
t.Fatalf("Expected field %v wasn't in the actual fields", exp)
}
}