Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/parser: fix test case for Skip&SkipPrefix #1022

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions schema/append_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func FieldAppender(dialect Dialect, field *Field) AppenderFunc {
}

if fieldType.Kind() != reflect.Ptr {
if reflect.PtrTo(fieldType).Implements(driverValuerType) {
if reflect.PointerTo(fieldType).Implements(driverValuerType) {
return addrAppender(appendDriverValue)
}
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func appender(dialect Dialect, typ reflect.Type) AppenderFunc {
}

if kind != reflect.Ptr {
ptr := reflect.PtrTo(typ)
ptr := reflect.PointerTo(typ)
if ptr.Implements(queryAppenderType) {
return addrAppender(appendQueryAppenderValue)
}
Expand Down
2 changes: 1 addition & 1 deletion schema/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func scanner(typ reflect.Type) ScannerFunc {
}

if kind != reflect.Ptr {
ptr := reflect.PtrTo(typ)
ptr := reflect.PointerTo(typ)
if ptr.Implements(scannerType) {
return addrScanner(scanScanner)
}
Expand Down
2 changes: 1 addition & 1 deletion schema/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (table *Table) init(dialect Dialect, typ reflect.Type, canAddr bool) {
{afterScanRowHookType, afterScanRowHookFlag},
}

typ = reflect.PtrTo(table.Type)
typ = reflect.PointerTo(table.Type)
for _, hook := range hooks {
if typ.Implements(hook.typ) {
table.flags = table.flags.Set(hook.flag)
Expand Down
2 changes: 1 addition & 1 deletion schema/zerochecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func zeroChecker(typ reflect.Type) IsZeroerFunc {
kind := typ.Kind()

if kind != reflect.Ptr {
ptr := reflect.PtrTo(typ)
ptr := reflect.PointerTo(typ)
if ptr.Implements(isZeroerType) {
return addrChecker(isZeroInterface)
}
Expand Down
Loading