| 
									
										
										
										
											2016-03-30 21:43:14 -04:00
										 |  |  | USING: accessors continuations debugger eval io kernel | 
					
						
							|  |  |  | kernel.private math memory namespaces sequences tools.test | 
					
						
							|  |  |  | vectors words ;
 | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | IN: continuations.tests | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : (callcc1-test) ( n obj -- n' obj )
 | 
					
						
							|  |  |  |     [ 1 - dup ] dip ?push
 | 
					
						
							|  |  |  |     over 0 = [ "test-cc" get continue-with ] when
 | 
					
						
							|  |  |  |     (callcc1-test) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : callcc1-test ( x -- list )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         "test-cc" set V{ } clone (callcc1-test) | 
					
						
							|  |  |  |     ] callcc1 nip ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : callcc-namespace-test ( -- ? )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         "test-cc" set
 | 
					
						
							| 
									
										
										
										
											2016-03-03 14:54:33 -05:00
										 |  |  |         5 "x" set
 | 
					
						
							|  |  |  |         H{ } clone [ | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  |             6 "x" set "test-cc" get continue
 | 
					
						
							| 
									
										
										
										
											2016-03-03 14:54:33 -05:00
										 |  |  |         ] with-variables
 | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  |     ] callcc0 "x" get 5 = ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { t } [ 10 callcc1-test 10 iota reverse >vector = ] unit-test | 
					
						
							|  |  |  | { t } [ callcc-namespace-test ] unit-test | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ 5 throw ] [ 5 = ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { t } [ | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  |     [ "Hello" throw ] ignore-errors
 | 
					
						
							|  |  |  |     error get-global
 | 
					
						
							|  |  |  |     "Hello" =
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "!!! The following error is part of the test" print
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { } [ [ 6 [ 12 [ "2 car" ] ] ] print-error ] unit-test | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | "!!! The following error is part of the test" print
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { } [ [ [ "2 car" ] eval ] try ] unit-test | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ f throw ] must-fail | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Weird PowerPC bug. | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { } [ | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  |     [ "4" throw ] ignore-errors
 | 
					
						
							|  |  |  |     gc | 
					
						
							|  |  |  |     gc | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : don't-compile-me ( -- ) ;
 | 
					
						
							| 
									
										
										
										
											2015-08-13 13:11:59 -04:00
										 |  |  | : foo ( -- ) get-callstack "c" set don't-compile-me ;
 | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | : bar ( -- a b ) 1 foo 2 ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | << { don't-compile-me foo bar } [ t "no-compile" set-word-prop ] each >> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { 1 2 } [ bar ] unit-test | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { t } [ \ bar def>> "c" get innermost-frame-executing = ] unit-test | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { 1 } [ "c" get innermost-frame-scan ] unit-test | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: always-counter | 
					
						
							|  |  |  | SYMBOL: error-counter | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-03 17:36:48 -05:00
										 |  |  | H{ | 
					
						
							|  |  |  |     { always-counter 0 } | 
					
						
							|  |  |  |     { error-counter 0 } | 
					
						
							|  |  |  | } [ | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     [ ] [ always-counter inc ] [ error-counter inc ] cleanup
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ 1 ] [ always-counter get ] unit-test | 
					
						
							|  |  |  |     [ 0 ] [ error-counter get ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         [ "a" throw ] | 
					
						
							|  |  |  |         [ always-counter inc ] | 
					
						
							|  |  |  |         [ error-counter inc ] cleanup
 | 
					
						
							|  |  |  |     ] [ "a" = ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ 2 ] [ always-counter get ] unit-test | 
					
						
							|  |  |  |     [ 1 ] [ error-counter get ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         [ ] | 
					
						
							|  |  |  |         [ always-counter inc "a" throw ] | 
					
						
							|  |  |  |         [ error-counter inc ] cleanup
 | 
					
						
							|  |  |  |     ] [ "a" = ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [ 3 ] [ always-counter get ] unit-test | 
					
						
							|  |  |  |     [ 1 ] [ error-counter get ] unit-test | 
					
						
							| 
									
										
										
										
											2016-03-02 20:18:42 -05:00
										 |  |  | ] with-variables
 | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { } [ [ return ] with-return ] unit-test | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ { } [ ] attempt-all ] [ attempt-all-error? ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 20:28:17 -04:00
										 |  |  | { { 4 } } [ { 2 2 } [ + ] with-datastack ] unit-test | 
					
						
							| 
									
										
										
										
											2010-01-30 23:39:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ with-datastack ] must-infer |