]> gitweb.factorcode.org Git - factor.git/blob - extra/gdbm/gdbm-tests.factor
calendar.format: make duration>human-readable more human readable
[factor.git] / extra / gdbm / gdbm-tests.factor
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 ;
5 IN: gdbm.tests
6
7 : db-path ( -- filename ) cpu name>> "-test.db" append temp-file ;
8
9 : CLEANUP ( -- ) db-path ?delete-file ;
10
11 : test.db ( -- gdbm ) <gdbm> db-path >>name ;
12
13 : with-test.db ( quot -- ) test.db swap with-gdbm ; inline
14
15 CLEANUP
16
17 [
18     test.db reader >>role [ ] with-gdbm
19 ] [ gdbm-file-open-error = ] must-fail-with
20
21 { f } [ [ "foo" gdbm-exists? ] with-test.db ] unit-test
22
23 { } [ [ "foo" 41 gdbm-insert ] with-test.db ] unit-test
24
25 [
26     db-path [ "foo" 42 gdbm-insert ] with-gdbm-writer
27 ] [ gdbm-cannot-replace = ] must-fail-with
28
29 { }
30 [
31     [
32         "foo" 42 gdbm-replace
33         "bar" 43 gdbm-replace
34         "baz" 44 gdbm-replace
35     ] with-test.db
36 ] unit-test
37
38 { 42 t } [ db-path [ "foo" gdbm-fetch* ] with-gdbm-reader ] unit-test
39
40 { f f } [ [ "unknown" gdbm-fetch* ] with-test.db ] unit-test
41
42 { t }
43 [
44     V{ } [ [ 2array append ] each-gdbm-record ] with-test.db
45     V{ "foo" "bar" "baz" 42 43 44 } set=
46
47 ] unit-test
48
49 { f }
50 [
51     test.db newdb >>role [ "foo" gdbm-exists? ] with-gdbm
52 ] unit-test
53
54 CLEANUP