Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
72cf0e47
Commit
72cf0e47
authored
Jan 01, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Misc.
parent
fcb3fce3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
25 deletions
+13
-25
function_test.go
function_test.go
+13
-25
No files found.
function_test.go
View file @
72cf0e47
...
@@ -21,19 +21,14 @@ func TestScalarFunction(t *testing.T) {
...
@@ -21,19 +21,14 @@ func TestScalarFunction(t *testing.T) {
t
.
Fatalf
(
"couldn't open database file: %s"
,
err
)
t
.
Fatalf
(
"couldn't open database file: %s"
,
err
)
}
}
defer
db
.
Close
()
defer
db
.
Close
()
err
=
db
.
CreateScalarFunction
(
"half"
,
1
,
nil
,
half
,
nil
)
if
err
=
db
.
CreateScalarFunction
(
"half"
,
1
,
nil
,
half
,
nil
);
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't create function: %s"
,
err
)
t
.
Fatalf
(
"couldn't create function: %s"
,
err
)
}
}
s
,
err
:=
db
.
Prepare
(
"select half(6)"
)
s
,
err
:=
db
.
Prepare
(
"select half(6)"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't prepare statement: %s"
,
err
)
t
.
Fatalf
(
"couldn't prepare statement: %s"
,
err
)
}
}
b
,
err
:=
s
.
Next
()
if
b
:=
Must
(
s
.
Next
());
!
b
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't step statement: %s"
,
err
)
}
if
!
b
{
t
.
Fatalf
(
"No result"
)
t
.
Fatalf
(
"No result"
)
}
}
d
,
_
,
err
:=
s
.
ScanDouble
(
0
)
d
,
_
,
err
:=
s
.
ScanDouble
(
0
)
...
@@ -43,12 +38,10 @@ func TestScalarFunction(t *testing.T) {
...
@@ -43,12 +38,10 @@ func TestScalarFunction(t *testing.T) {
if
d
!=
3
{
if
d
!=
3
{
t
.
Errorf
(
"Expected %f but got %f"
,
3
,
d
)
t
.
Errorf
(
"Expected %f but got %f"
,
3
,
d
)
}
}
err
=
s
.
Finalize
()
if
err
=
s
.
Finalize
();
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't finalize statement: %s"
,
err
)
t
.
Fatalf
(
"couldn't finalize statement: %s"
,
err
)
}
}
err
=
db
.
CreateScalarFunction
(
"half"
,
1
,
nil
,
nil
,
nil
)
if
err
=
db
.
CreateScalarFunction
(
"half"
,
1
,
nil
,
nil
,
nil
);
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"couldn't destroy function: %s"
,
err
)
t
.
Errorf
(
"couldn't destroy function: %s"
,
err
)
}
}
}
}
...
@@ -77,25 +70,25 @@ func re(ctx *Context, nArg int) {
...
@@ -77,25 +70,25 @@ func re(ctx *Context, nArg int) {
ctx
.
ResultBool
(
m
)
ctx
.
ResultBool
(
m
)
}
}
// Useless (just for test)
func
reDestroy
(
ad
interface
{})
{
//println("reDestroy")
}
func
TestRegexpFunction
(
t
*
testing
.
T
)
{
func
TestRegexpFunction
(
t
*
testing
.
T
)
{
db
,
err
:=
Open
(
""
)
db
,
err
:=
Open
(
""
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't open database file: %s"
,
err
)
t
.
Fatalf
(
"couldn't open database file: %s"
,
err
)
}
}
defer
db
.
Close
()
defer
db
.
Close
()
err
=
db
.
CreateScalarFunction
(
"regexp"
,
2
,
nil
,
re
,
nil
)
if
err
=
db
.
CreateScalarFunction
(
"regexp"
,
2
,
nil
,
re
,
reDestroy
);
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't create function: %s"
,
err
)
t
.
Fatalf
(
"couldn't create function: %s"
,
err
)
}
}
s
,
err
:=
db
.
Prepare
(
"select regexp('l.s[aeiouy]', name) from (select 'lisa' as name union all select 'bart' as name)"
)
s
,
err
:=
db
.
Prepare
(
"select regexp('l.s[aeiouy]', name) from (select 'lisa' as name union all select 'bart' as name)"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't prepare statement: %s"
,
err
)
t
.
Fatalf
(
"couldn't prepare statement: %s"
,
err
)
}
}
b
,
err
:=
s
.
Next
()
if
b
:=
Must
(
s
.
Next
());
!
b
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't step statement: %s"
,
err
)
}
if
!
b
{
t
.
Fatalf
(
"No result"
)
t
.
Fatalf
(
"No result"
)
}
}
i
,
_
,
err
:=
s
.
ScanInt
(
0
)
i
,
_
,
err
:=
s
.
ScanInt
(
0
)
...
@@ -105,11 +98,7 @@ func TestRegexpFunction(t *testing.T) {
...
@@ -105,11 +98,7 @@ func TestRegexpFunction(t *testing.T) {
if
i
!=
1
{
if
i
!=
1
{
t
.
Errorf
(
"Expected %d but got %d"
,
1
,
i
)
t
.
Errorf
(
"Expected %d but got %d"
,
1
,
i
)
}
}
b
,
err
=
s
.
Next
()
if
b
:=
Must
(
s
.
Next
());
!
b
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't step statement: %s"
,
err
)
}
if
!
b
{
t
.
Fatalf
(
"No result"
)
t
.
Fatalf
(
"No result"
)
}
}
i
,
_
,
err
=
s
.
ScanInt
(
0
)
i
,
_
,
err
=
s
.
ScanInt
(
0
)
...
@@ -119,8 +108,7 @@ func TestRegexpFunction(t *testing.T) {
...
@@ -119,8 +108,7 @@ func TestRegexpFunction(t *testing.T) {
if
i
!=
0
{
if
i
!=
0
{
t
.
Errorf
(
"Expected %d but got %d"
,
0
,
i
)
t
.
Errorf
(
"Expected %d but got %d"
,
0
,
i
)
}
}
err
=
s
.
Finalize
()
if
err
=
s
.
Finalize
();
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't finalize statement: %s"
,
err
)
t
.
Fatalf
(
"couldn't finalize statement: %s"
,
err
)
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment