Skip to content

Commit

Permalink
fix: parser unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBaulch committed Oct 7, 2024
1 parent 56382d2 commit 2a8a3a2
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions internal/parser/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parser

import (
"errors"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -140,7 +141,7 @@ func TestParser_Skip(t *testing.T) {
name string
fields fields
args args
want bool
want error
idAfterSkip int
}{
{
Expand All @@ -152,7 +153,7 @@ func TestParser_Skip(t *testing.T) {
args: args{
skip: '?',
},
want: true,
want: nil,
idAfterSkip: 1,
},
{
Expand All @@ -164,7 +165,7 @@ func TestParser_Skip(t *testing.T) {
args: args{
skip: '!',
},
want: false,
want: errors.New("got '?', wanted '!'"),
idAfterSkip: 0,
},
}
Expand All @@ -179,7 +180,7 @@ func TestParser_Skip(t *testing.T) {
}
}

func TestParser_SkipBytes(t *testing.T) {
func TestParser_SkipPrefix(t *testing.T) {
type fields struct {
b []byte
i int
Expand All @@ -191,7 +192,7 @@ func TestParser_SkipBytes(t *testing.T) {
name string
fields fields
args args
want bool
want error
idAfterSkip int
}{
{
Expand All @@ -203,7 +204,7 @@ func TestParser_SkipBytes(t *testing.T) {
args: args{
skip: []byte("? = "),
},
want: true,
want: nil,
idAfterSkip: 4,
},
{
Expand All @@ -215,19 +216,19 @@ func TestParser_SkipBytes(t *testing.T) {
args: args{
skip: []byte("hoge"),
},
want: false,
want: errors.New(`got "? = ?", wanted prefix "hoge"`),
idAfterSkip: 0,
},
{
name: "return false when argument is longer than the remaining bytes",
name: "return error when argument is longer than the remaining bytes",
fields: fields{
b: []byte("? = ?"),
i: 0,
},
args: args{
skip: []byte("? = ? hoge"),
},
want: false,
want: errors.New(`got "? = ?", wanted prefix "? = ? hoge"`),
idAfterSkip: 0,
},
}
Expand All @@ -237,7 +238,7 @@ func TestParser_SkipBytes(t *testing.T) {
b: tt.fields.b,
i: tt.fields.i,
}
require.Equal(t, tt.want, p.SkipBytes(tt.args.skip))
require.Equal(t, tt.want, p.SkipPrefix(tt.args.skip))
require.Equal(t, tt.idAfterSkip, p.i)
})
}
Expand Down

0 comments on commit 2a8a3a2

Please # to comment.