1 ! Copyright (C) 2010 Dmitry Shubin.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays continuations gdbm io.directories
4 io.files.temp kernel sequences sets system tools.test ;
7 : db-path ( -- filename ) cpu name>> "-test.db" append temp-file ;
9 : CLEANUP ( -- ) db-path ?delete-file ;
11 : test.db ( -- gdbm ) <gdbm> db-path >>name ;
13 : with-test.db ( quot -- ) test.db swap with-gdbm ; inline
18 test.db reader >>role [ ] with-gdbm
19 ] [ gdbm-file-open-error = ] must-fail-with
21 { f } [ [ "foo" gdbm-exists? ] with-test.db ] unit-test
23 { } [ [ "foo" 41 gdbm-insert ] with-test.db ] unit-test
26 db-path [ "foo" 42 gdbm-insert ] with-gdbm-writer
27 ] [ gdbm-cannot-replace = ] must-fail-with
38 { 42 t } [ db-path [ "foo" gdbm-fetch* ] with-gdbm-reader ] unit-test
40 { f f } [ [ "unknown" gdbm-fetch* ] with-test.db ] unit-test
44 V{ } [ [ 2array append ] each-gdbm-record ] with-test.db
45 V{ "foo" "bar" "baz" 42 43 44 } set=
51 test.db newdb >>role [ "foo" gdbm-exists? ] with-gdbm