Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Jul 6, 2024
1 parent 59d2eca commit cc422ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions sentence.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ func (p *SentenceParser) parseBaseSentence(raw string) (BaseSentence, error) {
if raw == "" {
return BaseSentence{}, errors.New("nmea: can not parse empty input")
}
tagBlock, sentenceStartIndex, err := ParseTagBlock(raw)
tagBlock, tagBlockLen, err := ParseTagBlock(raw)
if err != nil {
return BaseSentence{}, err
}
if sentenceStartIndex > 0 && p.OnTagBlock != nil {
if tagBlockLen > 0 && p.OnTagBlock != nil {
if err := p.OnTagBlock(tagBlock); err != nil {
return BaseSentence{}, err
}
}
raw = raw[sentenceStartIndex:]
raw = raw[tagBlockLen:]

startIndex := strings.IndexAny(raw, SentenceStart+SentenceStartEncapsulated)
if startIndex != 0 {
Expand Down
2 changes: 1 addition & 1 deletion tagblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TagBlock struct {
}

// ParseTagBlock parses tag blocks from a sentence string.
// The second return value is the index where the sentence starts.
// The second return value is the length of the tag block prefix.
// See: https://gpsd.gitlab.io/gpsd/AIVDM.html#_nmea_tag_blocks
func ParseTagBlock(raw string) (TagBlock, int, error) {
startOfTagBlock := strings.IndexByte(raw, TagBlockSep)
Expand Down
20 changes: 11 additions & 9 deletions tagblock_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nmea

import (
"log"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -11,7 +13,7 @@ var tagblocktests = []struct {
raw string
err string
block TagBlock
index int
len int
}{
{

Expand All @@ -21,7 +23,7 @@ var tagblocktests = []struct {
Time: 1553390539,
Source: "Satelite_1",
},
index: 30,
len: 30,
},
{

Expand All @@ -31,7 +33,7 @@ var tagblocktests = []struct {
Time: 1564827317,
Source: "satelite",
},
index: 28,
len: 28,
},
{

Expand All @@ -41,7 +43,7 @@ var tagblocktests = []struct {
Time: 1564827317,
Source: "",
},
index: 28,
len: 28,
},
{
name: "Test unix timestamp",
Expand All @@ -50,7 +52,7 @@ var tagblocktests = []struct {
Time: 1564827317,
Source: "",
},
index: 28,
len: 28,
},
{

Expand All @@ -60,7 +62,7 @@ var tagblocktests = []struct {
Time: 1564827317000,
Source: "",
},
index: 31,
len: 31,
},
{

Expand All @@ -75,7 +77,7 @@ var tagblocktests = []struct {
Text: "helloworld",
LineCount: 13,
},
index: 72,
len: 72,
},
{

Expand Down Expand Up @@ -122,14 +124,14 @@ var tagblocktests = []struct {
func TestParseTagBlock(t *testing.T) {
for _, tt := range tagblocktests {
t.Run(tt.name, func(t *testing.T) {
b, index, err := ParseTagBlock(tt.raw)
b, n, err := ParseTagBlock(tt.raw)
if tt.err != "" {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.block, b)
assert.Equal(t, tt.index, index)
assert.Equal(t, tt.len, n)
})
}
}

0 comments on commit cc422ce

Please sign in to comment.