|
1 | 1 | package nmea |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "testing" |
5 | 6 |
|
6 | 7 | "github.com/stretchr/testify/assert" |
@@ -58,11 +59,11 @@ var sentencetests = []struct { |
58 | 59 | }, |
59 | 60 | }, |
60 | 61 | { |
61 | | - name: "valid NMEA 4.10 TAG Block", |
62 | | - raw: "\\s:Satelite_1,c:1553390539*62\\!AIVDM,1,1,,A,13M@ah0025QdPDTCOl`K6`nV00Sv,0*52", |
| 62 | + name: "valid NMEA 4.10 TAG Block", |
| 63 | + raw: "\\s:Satelite_1,c:1553390539*62\\!AIVDM,1,1,,A,13M@ah0025QdPDTCOl`K6`nV00Sv,0*52", |
63 | 64 | datatype: "VDM", |
64 | 65 | talkerid: "AI", |
65 | | - prefix: "AIVDM", |
| 66 | + prefix: "AIVDM", |
66 | 67 | sent: BaseSentence{ |
67 | 68 | Talker: "AI", |
68 | 69 | Type: "VDM", |
@@ -108,17 +109,17 @@ var sentencetests = []struct { |
108 | 109 | { |
109 | 110 | name: "missing TAG Block start delimiter", |
110 | 111 | raw: "s:Satelite_1,c:1553390539*62\\!AIVDM,1,1,,A,13M@ah0025QdPDTCOl`K6`nV00Sv,0*52", |
111 | | - err: "nmea: sentence does not start with a '$' or '!'", |
| 112 | + err: "nmea: sentence does not start with a '$' or '!'", |
112 | 113 | }, |
113 | 114 | { |
114 | 115 | name: "missing TAG Block end delimiter", |
115 | 116 | raw: "\\s:Satelite_1,c:1553390539*62!AIVDM,1,1,,A,13M@ah0025QdPDTCOl`K6`nV00Sv,0*52", |
116 | | - err: "nmea: sentence does not start with a '$' or '!'", |
| 117 | + err: "nmea: sentence does not start with a '$' or '!'", |
117 | 118 | }, |
118 | 119 | { |
119 | 120 | name: "invalid TAG Block contents", |
120 | 121 | raw: "\\\\!AIVDM,1,1,,A,13M@ah0025QdPDTCOl`K6`nV00Sv,0*52", |
121 | | - err: "nmea: tagblock does not contain checksum separator", |
| 122 | + err: "nmea: tagblock does not contain checksum separator", |
122 | 123 | }, |
123 | 124 | } |
124 | 125 |
|
@@ -191,32 +192,32 @@ func TestPrefix(t *testing.T) { |
191 | 192 | var parsetests = []struct { |
192 | 193 | name string |
193 | 194 | raw string |
194 | | - err string |
| 195 | + err error |
195 | 196 | msg interface{} |
196 | 197 | }{ |
197 | 198 | { |
198 | 199 | name: "bad sentence", |
199 | 200 | raw: "SDFSD,2340dfmswd", |
200 | | - err: "nmea: sentence does not start with a '$' or '!'", |
| 201 | + err: errors.New("nmea: sentence does not start with a '$' or '!'"), |
201 | 202 | }, |
202 | 203 | { |
203 | 204 | name: "bad sentence type", |
204 | 205 | raw: "$INVALID,123,123,*7D", |
205 | | - err: "nmea: sentence prefix 'INVALID' not supported", |
| 206 | + err: &NotSupportedError{Prefix: "INVALID"}, |
206 | 207 | }, |
207 | 208 | { |
208 | 209 | name: "bad encapsulated sentence type", |
209 | 210 | raw: "!INVALID,1,2,*7E", |
210 | | - err: "nmea: sentence prefix 'INVALID' not supported", |
| 211 | + err: &NotSupportedError{Prefix: "INVALID"}, |
211 | 212 | }, |
212 | 213 | } |
213 | 214 |
|
214 | 215 | func TestParse(t *testing.T) { |
215 | 216 | for _, tt := range parsetests { |
216 | 217 | t.Run(tt.name, func(t *testing.T) { |
217 | 218 | m, err := Parse(tt.raw) |
218 | | - if tt.err != "" { |
219 | | - assert.EqualError(t, err, tt.err) |
| 219 | + if tt.err != nil { |
| 220 | + assert.Equal(t, err, tt.err) |
220 | 221 | } else { |
221 | 222 | assert.NoError(t, err) |
222 | 223 | assert.Equal(t, tt.msg, m) |
|
0 commit comments