| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | ! Copyright (C) 2010 Dmitry Shubin. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2010-06-27 19:50:06 -04:00
										 |  |  | USING: accessors arrays continuations gdbm io.directories | 
					
						
							| 
									
										
										
										
											2010-07-22 20:29:20 -04:00
										 |  |  | io.files.temp kernel sequences sets system tools.test ;
 | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | IN: gdbm.tests | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : db-path ( -- filename ) "test.db" temp-file ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : CLEANUP ( -- ) [ db-path delete-file ] ignore-errors ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : test.db ( -- gdbm ) <gdbm> db-path >>name ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : with-test.db ( quot -- ) test.db swap with-gdbm ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  | os windows? cpu x86.64? and [ | 
					
						
							|  |  |  |     CLEANUP | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     [ | 
					
						
							|  |  |  |         test.db reader >>role [ ] with-gdbm | 
					
						
							|  |  |  |     ] [ gdbm-file-open-error = ] must-fail-with | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     [ f ] [ [ "foo" exists? ] with-test.db ] unit-test | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     [ ] [ [ "foo" 41 insert ] with-test.db ] unit-test | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     [ | 
					
						
							|  |  |  |         db-path [ "foo" 42 insert ] with-gdbm-writer | 
					
						
							|  |  |  |     ] [ gdbm-cannot-replace = ] must-fail-with | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     [ ] | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |         [ | 
					
						
							|  |  |  |             "foo" 42 replace | 
					
						
							|  |  |  |             "bar" 43 replace | 
					
						
							|  |  |  |             "baz" 44 replace | 
					
						
							|  |  |  |         ] with-test.db | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     [ 42 t ] [ db-path [ "foo" fetch* ] with-gdbm-reader ] unit-test | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     [ f f ] [ [ "unknown" fetch* ] with-test.db ] unit-test | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |         [ | 
					
						
							|  |  |  |             300 set-cache-size 300 set-cache-size | 
					
						
							|  |  |  |         ] with-test.db | 
					
						
							|  |  |  |     ] [ gdbm-option-already-set = ] must-fail-with | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     [ t ] | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         V{ } [ [ 2array append ] each-record ] with-test.db | 
					
						
							|  |  |  |         V{ "foo" "bar" "baz" 42 43 44 } set= | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     ] unit-test | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     [ f ] | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         test.db newdb >>role [ "foo" exists? ] with-gdbm | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							| 
									
										
										
										
											2010-06-27 17:45:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 17:34:59 -04:00
										 |  |  |     CLEANUP | 
					
						
							|  |  |  | ] unless
 |