Skip to content

Commit

Permalink
Testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Jul 26, 2024
1 parent 7312594 commit c766a4f
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 58 deletions.
16 changes: 8 additions & 8 deletions ext/blobio/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func readblob(ctx sqlite3.Context, arg ...sqlite3.Value) {
blob, err := getAuxBlob(ctx, arg, false)
if err != nil {
ctx.ResultError(err)
return
return // notest
}

_, err = blob.Seek(arg[4].Int64(), io.SeekStart)
if err != nil {
ctx.ResultError(err)
return
return // notest
}

n := arg[5].Int64()
Expand All @@ -61,7 +61,7 @@ func readblob(ctx sqlite3.Context, arg ...sqlite3.Value) {
_, err = io.ReadFull(blob, buf)
if err != nil {
ctx.ResultError(err)
return
return // notest
}

ctx.ResultBlob(buf)
Expand All @@ -72,19 +72,19 @@ func writeblob(ctx sqlite3.Context, arg ...sqlite3.Value) {
blob, err := getAuxBlob(ctx, arg, true)
if err != nil {
ctx.ResultError(err)
return
return // notest
}

_, err = blob.Seek(arg[4].Int64(), io.SeekStart)
if err != nil {
ctx.ResultError(err)
return
return // notest
}

_, err = blob.Write(arg[5].RawBlob())
if err != nil {
ctx.ResultError(err)
return
return // notest
}

setAuxBlob(ctx, blob, false)
Expand All @@ -99,14 +99,14 @@ func openblob(ctx sqlite3.Context, arg ...sqlite3.Value) {
blob, err := getAuxBlob(ctx, arg, arg[4].Bool())
if err != nil {
ctx.ResultError(err)
return
return // notest
}

fn := arg[5].Pointer().(OpenCallback)
err = fn(blob, arg[6:]...)
if err != nil {
ctx.ResultError(err)
return
return // notest
}

setAuxBlob(ctx, blob, true)
Expand Down
69 changes: 43 additions & 26 deletions ext/blobio/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func Test_readblob(t *testing.T) {
CREATE TABLE test1 (col);
CREATE TABLE test2 (col);
INSERT INTO test1 VALUES (x'cafe');
INSERT INTO test1 VALUES (x'dead');
INSERT INTO test2 VALUES (x'babe');
`)
if err != nil {
Expand All @@ -107,34 +108,50 @@ func Test_readblob(t *testing.T) {
t.Log(err)
}

stmt, _, err := db.Prepare(`SELECT readblob('main', value, 'col', 1, 1, 1) FROM array(?)`)
if err != nil {
t.Fatal(err)
}
defer stmt.Close()

err = stmt.BindPointer(1, []string{"test1", "test2"})
if err != nil {
t.Fatal(err)
tests := []struct {
name string
sql string
want1 string
want2 string
}{
{"rows", `SELECT readblob('main', 'test1', 'col', rowid, 1, 1) FROM test1`, "\xfe", "\xad"},
{"tables", `SELECT readblob('main', value, 'col', 1, 1, 1) FROM array(?)`, "\xfe", "\xbe"},
}

if stmt.Step() {
got := stmt.ColumnText(0)
if got != "\xfe" {
t.Errorf("got %q", got)
}
}

if stmt.Step() {
got := stmt.ColumnText(0)
if got != "\xbe" {
t.Errorf("got %q", got)
}
}

err = stmt.Err()
if err != nil {
t.Fatal(err)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
stmt, _, err := db.Prepare(tt.sql)
if err != nil {
t.Fatal(err)
}
defer stmt.Close()

if stmt.BindCount() == 1 {
err = stmt.BindPointer(1, []string{"test1", "test2"})
if err != nil {
t.Fatal(err)
}
}

if stmt.Step() {
got := stmt.ColumnText(0)
if got != tt.want1 {
t.Errorf("got %q", got)
}
}

if stmt.Step() {
got := stmt.ColumnText(0)
if got != tt.want2 {
t.Errorf("got %q", got)
}
}

err = stmt.Err()
if err != nil {
t.Fatal(err)
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion ext/fileio/fileio.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func readfile(fsys fs.FS) func(ctx sqlite3.Context, arg ...sqlite3.Value) {
case err == nil:
ctx.ResultBlob(data)
case !errors.Is(err, fs.ErrNotExist):
ctx.ResultError(fmt.Errorf("readfile: %w", err))
ctx.ResultError(fmt.Errorf("readfile: %w", err)) // notest
}
}
}
4 changes: 2 additions & 2 deletions ext/fileio/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func writefile(ctx sqlite3.Context, arg ...sqlite3.Value) {
err := os.Chmod(file, mode.Perm())
if err != nil {
ctx.ResultError(fmt.Errorf("writefile: %w", err))
return
return // notest
}
}

Expand All @@ -48,7 +48,7 @@ func writefile(ctx sqlite3.Context, arg ...sqlite3.Value) {
err := os.Chtimes(file, time.Time{}, mtime)
if err != nil {
ctx.ResultError(fmt.Errorf("writefile: %w", err))
return
return // notest
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions ext/regexp/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func load(ctx sqlite3.Context, i int, expr string) (*regexp.Regexp, error) {
func regex(ctx sqlite3.Context, arg ...sqlite3.Value) {
re, err := load(ctx, 0, arg[0].Text())
if err != nil {
ctx.ResultError(err)
ctx.ResultError(err) // notest
} else {
ctx.ResultBool(re.Match(arg[1].RawText()))
}
Expand All @@ -53,7 +53,7 @@ func regex(ctx sqlite3.Context, arg ...sqlite3.Value) {
func regexLike(ctx sqlite3.Context, arg ...sqlite3.Value) {
re, err := load(ctx, 1, arg[1].Text())
if err != nil {
ctx.ResultError(err)
ctx.ResultError(err) // notest
} else {
ctx.ResultBool(re.Match(arg[0].RawText()))
}
Expand All @@ -62,7 +62,7 @@ func regexLike(ctx sqlite3.Context, arg ...sqlite3.Value) {
func regexSubstr(ctx sqlite3.Context, arg ...sqlite3.Value) {
re, err := load(ctx, 1, arg[1].Text())
if err != nil {
ctx.ResultError(err)
ctx.ResultError(err) // notest
} else {
ctx.ResultRawText(re.Find(arg[0].RawText()))
}
Expand All @@ -71,7 +71,7 @@ func regexSubstr(ctx sqlite3.Context, arg ...sqlite3.Value) {
func regexReplace(ctx sqlite3.Context, arg ...sqlite3.Value) {
re, err := load(ctx, 1, arg[1].Text())
if err != nil {
ctx.ResultError(err)
ctx.ResultError(err) // notest
} else {
ctx.ResultRawText(re.ReplaceAll(arg[0].RawText(), arg[2].RawText()))
}
Expand Down
2 changes: 1 addition & 1 deletion ext/stats/percentile.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (q *percentile) Value(ctx sqlite3.Context) {
ctx.ResultJSON(floats)
}
if err != nil {
ctx.ResultError(fmt.Errorf("percentile: %w", err))
ctx.ResultError(fmt.Errorf("percentile: %w", err)) // notest
}
}

Expand Down
8 changes: 4 additions & 4 deletions ext/unicode/unicode.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Register(db *sqlite3.Conn) error {
err := RegisterCollation(db, arg[0].Text(), name)
if err != nil {
ctx.ResultError(err)
return
return // notest
}
}))
}
Expand All @@ -75,7 +75,7 @@ func upper(ctx sqlite3.Context, arg ...sqlite3.Value) {
t, err := language.Parse(arg[1].Text())
if err != nil {
ctx.ResultError(err)
return
return // notest
}
c := cases.Upper(t)
ctx.SetAuxData(1, c)
Expand All @@ -94,7 +94,7 @@ func lower(ctx sqlite3.Context, arg ...sqlite3.Value) {
t, err := language.Parse(arg[1].Text())
if err != nil {
ctx.ResultError(err)
return
return // notest
}
c := cases.Lower(t)
ctx.SetAuxData(1, c)
Expand All @@ -109,7 +109,7 @@ func regex(ctx sqlite3.Context, arg ...sqlite3.Value) {
r, err := regexp.Compile(arg[0].Text())
if err != nil {
ctx.ResultError(err)
return
return // notest
}
re = r
ctx.SetAuxData(0, r)
Expand Down
8 changes: 4 additions & 4 deletions ext/uuid/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func generate(ctx sqlite3.Context, arg ...sqlite3.Value) {
ns = uuid.NameSpaceX500
default:
ctx.ResultError(err)
return
return // notest
}
}
if ver == 3 {
Expand All @@ -121,7 +121,7 @@ func generate(ctx sqlite3.Context, arg ...sqlite3.Value) {
}

if err != nil {
ctx.ResultError(fmt.Errorf("uuid: %w", err))
ctx.ResultError(fmt.Errorf("uuid: %w", err)) // notest
} else {
ctx.ResultText(u.String())
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func fromValue(arg sqlite3.Value) (u uuid.UUID, err error) {
func toBlob(ctx sqlite3.Context, arg ...sqlite3.Value) {
u, err := fromValue(arg[0])
if err != nil {
ctx.ResultError(err)
ctx.ResultError(err) // notest
} else {
ctx.ResultBlob(u[:])
}
Expand All @@ -161,7 +161,7 @@ func toBlob(ctx sqlite3.Context, arg ...sqlite3.Value) {
func toString(ctx sqlite3.Context, arg ...sqlite3.Value) {
u, err := fromValue(arg[0])
if err != nil {
ctx.ResultError(err)
ctx.ResultError(err) // notest
} else {
ctx.ResultText(u.String())
}
Expand Down
10 changes: 2 additions & 8 deletions vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ func vfsOpen(ctx context.Context, mod api.Module, pVfs, zPath, pFile uint32, fla

func vfsClose(ctx context.Context, mod api.Module, pFile uint32) _ErrorCode {
err := vfsFileClose(ctx, mod, pFile)
if err != nil {
return vfsErrorCode(err, _IOERR_CLOSE)
}
return _OK
return vfsErrorCode(err, _IOERR_CLOSE)
}

func vfsRead(ctx context.Context, mod api.Module, pFile, zBuf uint32, iAmt int32, iOfst int64) _ErrorCode {
Expand All @@ -189,10 +186,7 @@ func vfsWrite(ctx context.Context, mod api.Module, pFile, zBuf uint32, iAmt int3
buf := util.View(mod, zBuf, uint64(iAmt))

_, err := file.WriteAt(buf, iOfst)
if err != nil {
return vfsErrorCode(err, _IOERR_WRITE)
}
return _OK
return vfsErrorCode(err, _IOERR_WRITE)
}

func vfsTruncate(ctx context.Context, mod api.Module, pFile uint32, nByte int64) _ErrorCode {
Expand Down

0 comments on commit c766a4f

Please sign in to comment.