| 
									
										
										
										
											2011-09-25 14:49:27 -04:00
										 |  |  | USING: alien alien.c-types alien.data arrays classes.struct | 
					
						
							| 
									
										
										
										
											2010-02-24 10:50:31 -05:00
										 |  |  | debugger.threads destructors generic.single io io.directories | 
					
						
							|  |  |  | io.encodings.8-bit.latin1 io.encodings.ascii | 
					
						
							|  |  |  | io.encodings.binary io.encodings.string io.files | 
					
						
							|  |  |  | io.files.private io.files.temp io.files.unique kernel make math | 
					
						
							| 
									
										
										
										
											2010-04-13 09:14:53 -04:00
										 |  |  | sequences specialized-arrays system threads tools.test vocabs | 
					
						
							|  |  |  | compiler.units ;
 | 
					
						
							|  |  |  | FROM: specialized-arrays.private => specialized-array-vocab ;
 | 
					
						
							| 
									
										
										
										
											2010-02-24 02:18:41 -05:00
										 |  |  | SPECIALIZED-ARRAY: int | 
					
						
							| 
									
										
										
										
											2008-03-01 17:00:45 -05:00
										 |  |  | IN: io.files.tests | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  | [ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test | 
					
						
							| 
									
										
										
										
											2008-02-27 15:59:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  | [ ] [ "append-test" temp-file ascii <file-appender> dispose ] unit-test | 
					
						
							| 
									
										
										
										
											2008-02-27 15:59:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  | [ | 
					
						
							|  |  |  |     "This is a line.\rThis is another line.\r" | 
					
						
							|  |  |  | ] [ | 
					
						
							| 
									
										
										
										
											2009-02-15 21:45:06 -05:00
										 |  |  |     "vocab:io/test/mac-os-eol.txt" latin1 | 
					
						
							|  |  |  |     [ 500 read ] with-file-reader | 
					
						
							| 
									
										
										
										
											2008-02-27 15:59:15 -05:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  | [ | 
					
						
							|  |  |  |     255
 | 
					
						
							|  |  |  | ] [ | 
					
						
							| 
									
										
										
										
											2009-02-15 21:45:06 -05:00
										 |  |  |     "vocab:io/test/binary.txt" latin1 | 
					
						
							|  |  |  |     [ read1 ] with-file-reader >fixnum
 | 
					
						
							| 
									
										
										
										
											2008-02-27 15:59:15 -05:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-16 00:42:33 -05:00
										 |  |  | [ | 
					
						
							|  |  |  |     "This" CHAR: \s
 | 
					
						
							|  |  |  | ] [ | 
					
						
							|  |  |  |     "vocab:io/test/read-until-test.txt" ascii | 
					
						
							|  |  |  |     [ " " read-until ] with-file-reader | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     "This" CHAR: \s
 | 
					
						
							|  |  |  | ] [ | 
					
						
							|  |  |  |     "vocab:io/test/read-until-test.txt" binary | 
					
						
							|  |  |  |     [ " " read-until [ ascii decode ] dip ] with-file-reader | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-27 15:59:15 -05:00
										 |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  |     "It seems Jobs has lost his grasp on reality again.\n" | 
					
						
							|  |  |  |     "separator-test.txt" temp-file latin1 set-file-contents | 
					
						
							| 
									
										
										
										
											2008-03-26 20:40:40 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-27 21:10:47 -04:00
										 |  |  | [ | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         { "It seems " CHAR: J } | 
					
						
							|  |  |  |         { "obs has lost h" CHAR: i } | 
					
						
							|  |  |  |         { "s grasp on reality again.\n" f } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | ] [ | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         "separator-test.txt" temp-file | 
					
						
							| 
									
										
										
										
											2009-02-15 21:45:06 -05:00
										 |  |  |         latin1 [ | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  |             "J" read-until 2array , | 
					
						
							|  |  |  |             "i" read-until 2array , | 
					
						
							|  |  |  |             "X" read-until 2array , | 
					
						
							| 
									
										
										
										
											2009-02-15 21:45:06 -05:00
										 |  |  |         ] with-file-reader | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  |     ] { } make | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ | 
					
						
							|  |  |  |     image binary [ | 
					
						
							|  |  |  |         10 [ 65536 read drop ] times
 | 
					
						
							|  |  |  |     ] with-file-reader | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-24 02:18:41 -05:00
										 |  |  | ! Writing specialized arrays to binary streams should work | 
					
						
							|  |  |  | [ ] [ | 
					
						
							|  |  |  |     "test.txt" temp-file binary [ | 
					
						
							|  |  |  |         int-array{ 1 2 3 } write
 | 
					
						
							|  |  |  |     ] with-file-writer | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ int-array{ 1 2 3 } ] [ | 
					
						
							|  |  |  |     "test.txt" temp-file binary [ | 
					
						
							|  |  |  |         3 4 * read
 | 
					
						
							|  |  |  |     ] with-file-reader | 
					
						
							| 
									
										
										
										
											2011-09-25 14:49:27 -04:00
										 |  |  |     int cast-array | 
					
						
							| 
									
										
										
										
											2010-02-24 02:18:41 -05:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-24 10:50:31 -05:00
										 |  |  | [ ] [ | 
					
						
							|  |  |  |     BV{ 0 1 2 } "test.txt" temp-file binary set-file-contents | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							|  |  |  |     "test.txt" temp-file binary file-contents | 
					
						
							|  |  |  |     B{ 0 1 2 } =
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STRUCT: pt { x uint } { y uint } ;
 | 
					
						
							|  |  |  | SPECIALIZED-ARRAY: pt | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CONSTANT: pt-array-1 | 
					
						
							|  |  |  |     pt-array{ S{ pt f 1 1 } S{ pt f 2 2 } S{ pt f 3 3 } } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ | 
					
						
							|  |  |  |     pt-array-1 | 
					
						
							|  |  |  |     "test.txt" temp-file binary set-file-contents | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							|  |  |  |     "test.txt" temp-file binary file-contents | 
					
						
							|  |  |  |     pt-array-1 >c-ptr sequence=
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Slices should support >c-ptr and byte-length | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ | 
					
						
							|  |  |  |     pt-array-1 rest-slice
 | 
					
						
							|  |  |  |     "test.txt" temp-file binary set-file-contents | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							|  |  |  |     "test.txt" temp-file binary file-contents | 
					
						
							| 
									
										
										
										
											2011-09-25 14:49:27 -04:00
										 |  |  |     pt cast-array | 
					
						
							| 
									
										
										
										
											2010-02-24 10:50:31 -05:00
										 |  |  |     pt-array-1 rest-slice sequence=
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-13 09:14:53 -04:00
										 |  |  | [ ] [ | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         pt specialized-array-vocab forget-vocab | 
					
						
							|  |  |  |     ] with-compilation-unit | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-24 02:18:41 -05:00
										 |  |  | ! Writing strings to binary streams should fail | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     "test.txt" temp-file binary [ | 
					
						
							|  |  |  |         "OMGFAIL" write
 | 
					
						
							|  |  |  |     ] with-file-writer | 
					
						
							|  |  |  | ] must-fail | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  | ! Test EOF behavior | 
					
						
							|  |  |  | [ 10 ] [ | 
					
						
							|  |  |  |     image binary [ | 
					
						
							|  |  |  |         0 read drop
 | 
					
						
							|  |  |  |         10 read length
 | 
					
						
							|  |  |  |     ] with-file-reader | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-12-14 22:21:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-24 02:18:41 -05:00
										 |  |  | ! Make sure that writing to a closed stream from another thread doesn't crash | 
					
						
							| 
									
										
										
										
											2008-12-14 22:21:44 -05:00
										 |  |  | [ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ "test-quux.txt" temp-file delete-file ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ "test-quux.txt" "quux-test.txt" [ temp-file ] bi@ move-file ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ "quux-test.txt" temp-file exists? ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ "quux-test.txt" temp-file delete-file ] unit-test | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! File seeking tests | 
					
						
							|  |  |  | [ B{ 3 2 3 4 5 } ] | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     "seek-test1" unique-file binary | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         [ | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             B{ 1 2 3 4 5 } write
 | 
					
						
							|  |  |  |             tell-output 5 assert=
 | 
					
						
							|  |  |  |             0 seek-absolute seek-output
 | 
					
						
							|  |  |  |             tell-output 0 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |             B{ 3 } write
 | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             tell-output 1 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |         ] with-file-writer | 
					
						
							|  |  |  |     ] [ | 
					
						
							|  |  |  |         file-contents | 
					
						
							|  |  |  |     ] 2bi
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ B{ 1 2 3 4 3 } ] | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     "seek-test2" unique-file binary | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         [ | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             B{ 1 2 3 4 5 } write
 | 
					
						
							|  |  |  |             tell-output 5 assert=
 | 
					
						
							|  |  |  |             -1 seek-relative seek-output
 | 
					
						
							|  |  |  |             tell-output 4 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |             B{ 3 } write
 | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             tell-output 5 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |         ] with-file-writer | 
					
						
							|  |  |  |     ] [ | 
					
						
							|  |  |  |         file-contents | 
					
						
							|  |  |  |     ] 2bi
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ B{ 1 2 3 4 5 0 3 } ] | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     "seek-test3" unique-file binary | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         [ | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             B{ 1 2 3 4 5 } write
 | 
					
						
							|  |  |  |             tell-output 5 assert=
 | 
					
						
							|  |  |  |             1 seek-relative seek-output
 | 
					
						
							|  |  |  |             tell-output 6 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |             B{ 3 } write
 | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             tell-output 7 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |         ] with-file-writer | 
					
						
							|  |  |  |     ] [ | 
					
						
							|  |  |  |         file-contents | 
					
						
							|  |  |  |     ] 2bi
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ B{ 3 } ] | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     B{ 1 2 3 4 5 } "seek-test4" unique-file binary [ | 
					
						
							|  |  |  |         set-file-contents | 
					
						
							|  |  |  |     ] [ | 
					
						
							|  |  |  |         [ | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             tell-input 0 assert=
 | 
					
						
							|  |  |  |             -3 seek-end seek-input
 | 
					
						
							|  |  |  |             tell-input 2 assert=
 | 
					
						
							|  |  |  |             1 read
 | 
					
						
							|  |  |  |             tell-input 3 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |         ] with-file-reader | 
					
						
							|  |  |  |     ] 2bi
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ B{ 2 } ] | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     B{ 1 2 3 4 5 } "seek-test5" unique-file binary [ | 
					
						
							|  |  |  |         set-file-contents | 
					
						
							|  |  |  |     ] [ | 
					
						
							|  |  |  |         [ | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             tell-input 0 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |             3 seek-absolute seek-input
 | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             tell-input 3 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |             -2 seek-relative seek-input
 | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             tell-input 1 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |             1 read
 | 
					
						
							| 
									
										
										
										
											2010-07-07 02:26:03 -04:00
										 |  |  |             tell-input 2 assert=
 | 
					
						
							| 
									
										
										
										
											2009-02-08 14:59:32 -05:00
										 |  |  |         ] with-file-reader | 
					
						
							|  |  |  |     ] 2bi
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2009-02-08 21:18:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     "seek-test6" unique-file binary [ | 
					
						
							|  |  |  |         -10 seek-absolute seek-input
 | 
					
						
							|  |  |  |     ] with-file-reader | 
					
						
							|  |  |  | ] must-fail | 
					
						
							| 
									
										
										
										
											2009-04-20 04:26:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-07 17:32:30 -04:00
										 |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2012-11-30 21:27:36 -05:00
										 |  |  |     "resource:license.txt" binary [ | 
					
						
							| 
									
										
										
										
											2010-07-07 17:32:30 -04:00
										 |  |  |         44 read drop
 | 
					
						
							|  |  |  |         tell-input 44 assert=
 | 
					
						
							|  |  |  |         -44 seek-relative seek-input
 | 
					
						
							|  |  |  |         tell-input 0 assert=
 | 
					
						
							|  |  |  |     ] with-file-reader | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-20 04:26:56 -04:00
										 |  |  | [ | 
					
						
							|  |  |  |     "non-string-error" unique-file ascii [ | 
					
						
							|  |  |  |         { } write
 | 
					
						
							|  |  |  |     ] with-file-writer | 
					
						
							|  |  |  | ] [ no-method? ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     "non-byte-array-error" unique-file binary [ | 
					
						
							|  |  |  |         "" write
 | 
					
						
							|  |  |  |     ] with-file-writer | 
					
						
							| 
									
										
										
										
											2009-08-24 21:27:22 -04:00
										 |  |  | ] [ no-method? ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! What happens if we close a file twice? | 
					
						
							|  |  |  | [ ] [ | 
					
						
							|  |  |  |     "closing-twice" unique-file ascii <file-writer> | 
					
						
							|  |  |  |     [ dispose ] [ dispose ] bi
 | 
					
						
							| 
									
										
										
										
											2009-11-12 19:36:47 -05:00
										 |  |  | ] unit-test |