| 
									
										
										
										
											2011-10-13 23:25:53 -04:00
										 |  |  | USING: accessors io io.streams.string kernel math parser sbufs | 
					
						
							| 
									
										
										
										
											2011-10-19 04:16:41 -04:00
										 |  |  | sequences tools.test words namespaces strings ;
 | 
					
						
							| 
									
										
										
										
											2008-03-01 17:00:45 -05:00
										 |  |  | IN: io.tests | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 21:29:34 -04:00
										 |  |  | { f } [ | 
					
						
							| 
									
										
										
										
											2009-02-15 20:53:21 -05:00
										 |  |  |     "vocab:io/test/no-trailing-eol.factor" run-file | 
					
						
							| 
									
										
										
										
											2011-11-06 18:57:24 -05:00
										 |  |  |     "foo" "io.tests" lookup-word | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Make sure we use correct to_c_string form when writing | 
					
						
							| 
									
										
										
										
											2011-10-13 21:29:34 -04:00
										 |  |  | { } [ "\0" write ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Test default input stream protocol methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: up-to-13-reader { i fixnum initial: 0 } ;
 | 
					
						
							| 
									
										
										
										
											2011-10-18 19:24:50 -04:00
										 |  |  | INSTANCE: up-to-13-reader input-stream | 
					
						
							| 
									
										
										
										
											2011-10-13 21:29:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: up-to-13-reader stream-element-type drop +byte+ ; inline
 | 
					
						
							|  |  |  | M: up-to-13-reader stream-read1 | 
					
						
							|  |  |  |     [ dup 1 + ] change-i drop
 | 
					
						
							|  |  |  |     dup 13 >= [ drop f ] when ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { B{ 0 1 2 } } [ 3 up-to-13-reader new stream-read ] unit-test | 
					
						
							|  |  |  | { B{ 0 1 2 } } [ 3 up-to-13-reader new stream-read-partial ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { B{ 0 1 2 3 4 5 6 7 8 9 10 11 12 } f } | 
					
						
							|  |  |  | [ up-to-13-reader new [ 20 swap stream-read ] [ 20 swap stream-read ] bi ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 22:58:29 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-11-09 20:21:44 -05:00
										 |  |  |     T{ slice f 0 8 B{ 0 1 2 3 4 5 6 7 } } t
 | 
					
						
							|  |  |  |     T{ slice f 0 5 B{ 8 9 10 11 12 205 206 207 } } t
 | 
					
						
							|  |  |  |     T{ slice f 0 0 B{ 8 9 10 11 12 205 206 207 } } f
 | 
					
						
							| 
									
										
										
										
											2011-10-14 22:58:29 -04:00
										 |  |  | } [ | 
					
						
							|  |  |  |     up-to-13-reader new
 | 
					
						
							|  |  |  |     [ B{ 200 201 202 203 204 205 206 207 } swap stream-read-into ] | 
					
						
							|  |  |  |     [ B{ 200 201 202 203 204 205 206 207 } swap stream-read-into ] | 
					
						
							|  |  |  |     [ B{ 200 201 202 203 204 205 206 207 } swap stream-read-into ] tri
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2011-10-13 21:29:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     B{ 0 1 2 3 4 5 6 7 8 } 9
 | 
					
						
							|  |  |  |     B{ 10 11 12 } f
 | 
					
						
							|  |  |  |     f f
 | 
					
						
							|  |  |  | } [ | 
					
						
							|  |  |  |     up-to-13-reader new
 | 
					
						
							|  |  |  |     [ "\t" swap stream-read-until ] | 
					
						
							|  |  |  |     [ "\t" swap stream-read-until ] | 
					
						
							|  |  |  |     [ "\t" swap stream-read-until ] tri
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { B{ 0 1 2 3 4 5 6 7 8 9 } B{ 11 12 } f } [ | 
					
						
							|  |  |  |     up-to-13-reader new
 | 
					
						
							|  |  |  |     [ stream-readln ] [ stream-readln ] [ stream-readln ] tri
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Test default output stream protocol methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: dumb-writer vector ;
 | 
					
						
							| 
									
										
										
										
											2011-10-18 19:24:50 -04:00
										 |  |  | INSTANCE: dumb-writer output-stream | 
					
						
							| 
									
										
										
										
											2011-10-13 21:29:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <dumb-writer> ( -- x ) BV{ } clone dumb-writer boa ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: dumb-writer stream-element-type drop +byte+ ; inline
 | 
					
						
							|  |  |  | M: dumb-writer stream-write1 vector>> push ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { BV{ 11 22 33 } } [ | 
					
						
							|  |  |  |     <dumb-writer>  | 
					
						
							|  |  |  |     [ B{ 11 22 33 } swap stream-write ] | 
					
						
							|  |  |  |     [ vector>> ] bi
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { BV{ 11 22 33 10 } } [ | 
					
						
							|  |  |  |     <dumb-writer>  | 
					
						
							|  |  |  |     [ B{ 11 22 33 } swap stream-write ] | 
					
						
							|  |  |  |     [ stream-nl ] | 
					
						
							|  |  |  |     [ vector>> ] tri
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2011-10-13 23:25:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | { SBUF" asdf" } | 
					
						
							|  |  |  | [ "asdf" <string-reader> 4 <sbuf> [ stream-copy ] keep ] unit-test | 
					
						
							| 
									
										
										
										
											2011-10-19 03:56:11 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ "asdf" ] | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         [ "asdf" error-stream get stream-write ] with-error>output
 | 
					
						
							|  |  |  |     ] with-string-writer | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ "asdf" ] | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     <string-writer> [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             [ "asdf" output-stream get stream-write ] with-output>error
 | 
					
						
							|  |  |  |         ] with-error-stream
 | 
					
						
							|  |  |  |     ] keep >string
 | 
					
						
							| 
									
										
										
										
											2011-11-06 18:57:24 -05:00
										 |  |  | ] unit-test |