factor/extra/db/sqlite/sqlite-tests.factor

111 lines
2.4 KiB
Factor
Raw Normal View History

2008-02-01 18:43:44 -05:00
USING: io io.files io.launcher kernel namespaces
prettyprint tools.test db.sqlite db db.sql sequences
continuations ;
IN: temporary
! "sqlite3 -init test.txt test.db"
IN: scratchpad
2008-02-01 18:43:44 -05:00
: test.db "extra/db/sqlite/test.db" resource-path ;
IN: temporary
2008-02-01 18:43:44 -05:00
: (create-db) ( -- str )
[
"sqlite3 -init " %
test.db %
2008-02-01 18:43:44 -05:00
" " %
test.db %
] "" make ;
: create-db ( -- ) (create-db) run-process drop ;
[ ] [ test.db delete-file ] unit-test
[ ] [ create-db ] unit-test
[
{
{ "John" "America" }
{ "Jane" "New Zealand" }
}
] [
test.db [
"select * from person" sql-query
] with-sqlite
] unit-test
2008-02-01 18:43:44 -05:00
[
{ { "John" "America" } }
] [
test.db [
2008-02-01 18:43:44 -05:00
"select * from person where name = :name and country = :country"
<simple-statement> [
{ { ":name" "Jane" } { ":country" "New Zealand" } }
over do-bound-query
2008-02-01 18:43:44 -05:00
{ { "Jane" "New Zealand" } } =
[ "test fails" throw ] unless
2008-02-01 18:43:44 -05:00
{ { ":name" "John" } { ":country" "America" } }
swap do-bound-query
] with-disposal
2008-02-01 18:43:44 -05:00
] with-sqlite
] unit-test
[
{
{ "1" "John" "America" }
{ "2" "Jane" "New Zealand" }
}
] [ test.db [ "select rowid, * from person" sql-query ] with-sqlite ] unit-test
2008-02-01 18:43:44 -05:00
[
] [
test.db [
2008-02-01 18:43:44 -05:00
"insert into person(name, country) values('Jimmy', 'Canada')"
sql-command
2008-02-01 18:43:44 -05:00
] with-sqlite
] unit-test
[
{
{ "1" "John" "America" }
{ "2" "Jane" "New Zealand" }
{ "3" "Jimmy" "Canada" }
}
] [ test.db [ "select rowid, * from person" sql-query ] with-sqlite ] unit-test
2008-02-01 18:43:44 -05:00
[
test.db [
2008-02-01 18:43:44 -05:00
[
"insert into person(name, country) values('Jose', 'Mexico')" sql-command
"insert into person(name, country) values('Jose', 'Mexico')" sql-command
2008-02-01 18:43:44 -05:00
"oops" throw
] with-transaction
] with-sqlite
] unit-test-fails
[ 3 ] [
test.db [
"select * from person" sql-query length
2008-02-01 18:43:44 -05:00
] with-sqlite
] unit-test
[
] [
test.db [
2008-02-01 18:43:44 -05:00
[
"insert into person(name, country) values('Jose', 'Mexico')"
sql-command
"insert into person(name, country) values('Jose', 'Mexico')"
sql-command
2008-02-01 18:43:44 -05:00
] with-transaction
] with-sqlite
] unit-test
[ 5 ] [
test.db [
"select * from person" sql-query length
2008-02-01 18:43:44 -05:00
] with-sqlite
] unit-test