]> gitweb.factorcode.org Git - factor.git/blob - extra/gdbm/gdbm-tests.factor
dc4f2b2bf29bee4763826f3b7aceafee828a30ec
[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 ] ignore-errors ;
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" exists? ] with-test.db ] unit-test
22
23 [ ] [ [ "foo" 41 insert ] with-test.db ] unit-test
24
25 [
26     db-path [ "foo" 42 insert ] with-gdbm-writer
27 ] [ gdbm-cannot-replace = ] must-fail-with
28
29 [ ]
30 [
31     [
32         "foo" 42 replace
33         "bar" 43 replace
34         "baz" 44 replace
35     ] with-test.db
36 ] unit-test
37
38 [ 42 t ] [ db-path [ "foo" fetch* ] with-gdbm-reader ] unit-test
39
40 [ f f ] [ [ "unknown" fetch* ] with-test.db ] unit-test
41
42 [
43     [
44         300 set-cache-size 300 set-cache-size
45     ] with-test.db
46 ] [ gdbm-option-already-set = ] must-fail-with
47
48 [ t ]
49 [
50     V{ } [ [ 2array append ] each-record ] with-test.db
51     V{ "foo" "bar" "baz" 42 43 44 } set=
52
53 ] unit-test
54
55 [ f ]
56 [
57     test.db newdb >>role [ "foo" exists? ] with-gdbm
58 ] unit-test
59
60 CLEANUP