Skip to content

Commit

Permalink
test(internal/parser): fix case for Skip&SkipPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
j2gg0s committed Sep 18, 2024
1 parent 6c83b05 commit ab7ea93
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 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 (
"fmt"
"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: fmt.Errorf("got %q, wanted %q", '?', '!'),
idAfterSkip: 0,
},
}
Expand All @@ -174,12 +175,20 @@ func TestParser_Skip(t *testing.T) {
b: tt.fields.b,
i: tt.fields.i,
}
require.Equal(t, tt.want, p.Skip(tt.args.skip))
equalError(t, tt.want, p.Skip(tt.args.skip))
})
}
}

func TestParser_SkipBytes(t *testing.T) {
func equalError(t *testing.T, want, got error) {
if want != nil && got != nil {
require.Equal(t, want.Error(), got.Error())
return
}
require.Equal(t, want, got)
}

func TestParser_SkipPrefix(t *testing.T) {
type fields struct {
b []byte
i int
Expand All @@ -191,7 +200,7 @@ func TestParser_SkipBytes(t *testing.T) {
name string
fields fields
args args
want bool
want error
idAfterSkip int
}{
{
Expand All @@ -203,7 +212,7 @@ func TestParser_SkipBytes(t *testing.T) {
args: args{
skip: []byte("? = "),
},
want: true,
want: nil,
idAfterSkip: 4,
},
{
Expand All @@ -215,7 +224,7 @@ func TestParser_SkipBytes(t *testing.T) {
args: args{
skip: []byte("hoge"),
},
want: false,
want: fmt.Errorf(`got "? = ?", wanted prefix "hoge"`),
idAfterSkip: 0,
},
{
Expand All @@ -227,7 +236,7 @@ func TestParser_SkipBytes(t *testing.T) {
args: args{
skip: []byte("? = ? hoge"),
},
want: false,
want: fmt.Errorf(`got "? = ?", wanted prefix "? = ? hoge"`),
idAfterSkip: 0,
},
}
Expand All @@ -237,7 +246,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))
equalError(t, tt.want, p.SkipPrefix(tt.args.skip))
require.Equal(t, tt.idAfterSkip, p.i)
})
}
Expand Down

0 comments on commit ab7ea93

Please sign in to comment.