forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rte_test.go
123 lines (121 loc) · 4.38 KB
/
rte_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package nmea_test
import (
. "github.com/munnik/go-nmea"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
)
var _ = Describe("RTE", func() {
var (
sentence Sentence
parsed RTE
err error
raw string
)
Describe("Parsing", func() {
JustBeforeEach(func() {
sentence, err = Parse(raw)
if sentence != nil {
parsed = sentence.(RTE)
} else {
parsed = RTE{}
}
})
Context("a valid sentence", func() {
BeforeEach(func() {
raw = "$IIRTE,4,1,c,Rte 1,411,412,413,414,415*6F"
})
It("returns no errors", func() {
Expect(err).NotTo(HaveOccurred())
})
It("equals a valid RTE struct", func() {
Expect(parsed).To(MatchFields(IgnoreExtras, Fields{
"NumberOfSentences": Equal(NewInt64(4)),
"SentenceNumber": Equal(NewInt64(1)),
"ActiveRouteOrWaypointList": Equal(NewString(ActiveRoute)),
"Name": Equal(NewString("Rte 1")),
"Idents": Equal(NewStringList([]String{NewString("411"), NewString("412"), NewString("413"), NewString("414"), NewString("415")})),
}))
})
})
Context("a sentence without any waypoints", func() {
BeforeEach(func() {
raw = "$IIRTE,4,1,c,Rte 1*77"
})
It("returns no errors", func() {
Expect(err).NotTo(HaveOccurred())
})
It("equals a valid RTE struct", func() {
Expect(parsed).To(MatchFields(IgnoreExtras, Fields{
"NumberOfSentences": Equal(NewInt64(4)),
"SentenceNumber": Equal(NewInt64(1)),
"ActiveRouteOrWaypointList": Equal(NewString(ActiveRoute)),
"Name": Equal(NewString("Rte 1")),
"Idents": Equal(NewInvalidStringList("index out of range")),
}))
})
})
Context("a sentence with an invalid number of sentences", func() {
BeforeEach(func() {
raw = "$IIRTE,X,1,c,Rte 1,411,412,413,414,415*03"
})
It("returns no errors", func() {
Expect(err).NotTo(HaveOccurred())
})
It("equals a valid RTE struct", func() {
Expect(parsed).To(MatchFields(IgnoreExtras, Fields{
"NumberOfSentences": Equal(NewInvalidInt64("strconv.ParseInt: parsing \"X\": invalid syntax")),
"SentenceNumber": Equal(NewInt64(1)),
"ActiveRouteOrWaypointList": Equal(NewString(ActiveRoute)),
"Name": Equal(NewString("Rte 1")),
"Idents": Equal(NewStringList([]String{NewString("411"), NewString("412"), NewString("413"), NewString("414"), NewString("415")})),
}))
})
})
Context("a sentence with an invalid sentence number", func() {
BeforeEach(func() {
raw = "$IIRTE,4,X,c,Rte 1,411,412,413,414,415*06"
})
It("returns no errors", func() {
Expect(err).NotTo(HaveOccurred())
})
It("equals a valid RTE struct", func() {
Expect(parsed).To(MatchFields(IgnoreExtras, Fields{
"NumberOfSentences": Equal(NewInt64(4)),
"SentenceNumber": Equal(NewInvalidInt64("strconv.ParseInt: parsing \"X\": invalid syntax")),
"ActiveRouteOrWaypointList": Equal(NewString(ActiveRoute)),
"Name": Equal(NewString("Rte 1")),
"Idents": Equal(NewStringList([]String{NewString("411"), NewString("412"), NewString("413"), NewString("414"), NewString("415")})),
}))
})
})
Context("a sentence with an invalid active route or waypoint list", func() {
BeforeEach(func() {
raw = "$IIRTE,4,1,X,Rte 1,411,412,413,414,415*54"
})
It("returns no errors", func() {
Expect(err).NotTo(HaveOccurred())
})
It("equals a valid RTE struct", func() {
Expect(parsed).To(MatchFields(IgnoreExtras, Fields{
"NumberOfSentences": Equal(NewInt64(4)),
"SentenceNumber": Equal(NewInt64(1)),
"ActiveRouteOrWaypointList": Equal(NewInvalidString("not a valid option")),
"Name": Equal(NewString("Rte 1")),
"Idents": Equal(NewStringList([]String{NewString("411"), NewString("412"), NewString("413"), NewString("414"), NewString("415")})),
}))
})
})
Context("a sentence with a bad checksum", func() {
BeforeEach(func() {
raw = "$IIRTE,4,1,c,Rte 1,411,412,413,414,415*70"
})
It("returns an error", func() {
Expect(err).To(MatchError("nmea: sentence checksum mismatch [6F != 70]"))
})
It("returns nil", func() {
Expect(sentence).To(BeNil())
})
})
})
})