parent
437428714e
commit
0aeb676866
|
@ -0,0 +1,41 @@
|
||||||
|
USING: assocs continuations debugger io.files kernel
|
||||||
|
namespaces store tools.test ;
|
||||||
|
IN: temporary
|
||||||
|
|
||||||
|
SYMBOL: store
|
||||||
|
SYMBOL: foo
|
||||||
|
SYMBOL: bar
|
||||||
|
|
||||||
|
|
||||||
|
: the-store ( -- path )
|
||||||
|
"store-test.store" resource-path ;
|
||||||
|
|
||||||
|
: delete-the-store ( -- )
|
||||||
|
[ the-store delete-file ] catch drop ;
|
||||||
|
|
||||||
|
: load-the-store ( -- )
|
||||||
|
the-store load-store store set ;
|
||||||
|
|
||||||
|
: save-the-store ( -- )
|
||||||
|
store get save-store ;
|
||||||
|
|
||||||
|
delete-the-store
|
||||||
|
the-store load-store store set
|
||||||
|
|
||||||
|
[ f ] [ foo store get store-data at ] unit-test
|
||||||
|
|
||||||
|
[ ] [ 100 foo store get store-variable ] unit-test
|
||||||
|
|
||||||
|
[ ] [ save-the-store ] unit-test
|
||||||
|
|
||||||
|
[ 100 ] [ foo store get store-data at ] unit-test
|
||||||
|
|
||||||
|
1000 foo set
|
||||||
|
|
||||||
|
[ ] [ save-the-store ] unit-test
|
||||||
|
|
||||||
|
[ ] [ load-the-store ] unit-test
|
||||||
|
|
||||||
|
[ 1000 ] [ foo store get store-data at ] unit-test
|
||||||
|
|
||||||
|
delete-the-store
|
|
@ -11,12 +11,12 @@ C: <store> store
|
||||||
[ store-data ] keep store-path <file-writer> [
|
[ store-data ] keep store-path <file-writer> [
|
||||||
[
|
[
|
||||||
dup
|
dup
|
||||||
[ drop [ get ] keep rot set-at ] curry* assoc-each
|
[ >r drop [ get ] keep r> set-at ] curry assoc-each
|
||||||
] keep serialize
|
] keep serialize
|
||||||
] with-stream ;
|
] with-stream ;
|
||||||
|
|
||||||
: load-store ( path -- store )
|
: load-store ( path -- store )
|
||||||
resource-path dup exists? [
|
dup exists? [
|
||||||
dup <file-reader> [
|
dup <file-reader> [
|
||||||
deserialize
|
deserialize
|
||||||
] with-stream
|
] with-stream
|
||||||
|
@ -30,4 +30,3 @@ C: <store> store
|
||||||
] [
|
] [
|
||||||
drop >r 2dup set-global r> set-at
|
drop >r 2dup set-global r> set-at
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue