factor/basis/db/sqlite/sqlite-tests.factor

76 lines
1.9 KiB
Factor
Raw Normal View History

USING: io io.files io.files.temp io.directories io.launcher
kernel namespaces prettyprint tools.test db.sqlite db sequences
continuations db.types db.tuples unicode.case ;
2008-03-01 17:00:45 -05:00
IN: db.sqlite.tests
2008-02-01 18:43:44 -05:00
: db-path ( -- path ) "test.db" temp-file ;
: test.db ( -- sqlite-db ) db-path <sqlite-db> ;
2008-02-01 18:43:44 -05:00
2008-03-05 14:51:31 -05:00
[ ] [ [ db-path delete-file ] ignore-errors ] unit-test
2008-02-01 18:43:44 -05:00
2008-02-04 14:57:22 -05:00
[ ] [
test.db [
"create table person (name varchar(30), country varchar(30))" sql-command
"insert into person values('John', 'America')" sql-command
"insert into person values('Jane', 'New Zealand')" sql-command
2008-03-05 14:51:31 -05:00
] with-db
2008-02-04 14:57:22 -05:00
] unit-test
2008-02-01 18:43:44 -05:00
2008-02-04 14:57:22 -05:00
[ { { "John" "America" } { "Jane" "New Zealand" } } ] [
test.db [
"select * from person" sql-query
2008-03-05 14:51:31 -05:00
] with-db
2008-02-01 18:43:44 -05:00
] unit-test
2008-02-04 14:57:22 -05:00
[ { { "1" "John" "America" } { "2" "Jane" "New Zealand" } } ]
2008-03-05 14:51:31 -05:00
[ test.db [ "select rowid, * from person" sql-query ] with-db ] unit-test
2008-02-01 18:43:44 -05:00
2008-02-04 14:57:22 -05:00
[ ] [
test.db [
2008-02-01 18:43:44 -05:00
"insert into person(name, country) values('Jimmy', 'Canada')"
sql-command
2008-03-05 14:51:31 -05:00
] with-db
2008-02-01 18:43:44 -05:00
] unit-test
[
{
{ "1" "John" "America" }
{ "2" "Jane" "New Zealand" }
{ "3" "Jimmy" "Canada" }
}
2008-03-05 14:51:31 -05:00
] [ test.db [ "select rowid, * from person" sql-query ] with-db ] 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
2008-03-05 14:51:31 -05:00
] with-db
] must-fail
2008-02-01 18:43:44 -05:00
[ 3 ] [
test.db [
"select * from person" sql-query length
2008-03-05 14:51:31 -05:00
] with-db
2008-02-01 18:43:44 -05:00
] 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
2008-03-05 14:51:31 -05:00
] with-db
2008-02-01 18:43:44 -05:00
] unit-test
[ 5 ] [
test.db [
"select * from person" sql-query length
2008-03-05 14:51:31 -05:00
] with-db
] unit-test