2016-03-30 21:43:14 -04:00
|
|
|
USING: accessors alien alien.accessors arrays assocs byte-arrays
|
|
|
|
continuations debugger grouping io.streams.string kernel
|
|
|
|
kernel.private literals locals.backend math memory namespaces
|
|
|
|
prettyprint sequences sequences.private tools.test words ;
|
2008-03-01 17:00:45 -05:00
|
|
|
IN: kernel.tests
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 0 } [ f size ] unit-test
|
|
|
|
{ t } [ [ \ = \ = ] all-equal? ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{
|
2014-07-22 09:09:26 -04:00
|
|
|
{
|
|
|
|
{ 1 2 0 }
|
|
|
|
{ 1 2 1 }
|
|
|
|
{ 1 2 2 }
|
|
|
|
{ 1 2 3 }
|
|
|
|
{ 1 2 4 }
|
|
|
|
{ 1 2 5 }
|
|
|
|
{ 1 2 6 }
|
|
|
|
{ 1 2 7 }
|
|
|
|
{ 1 2 8 }
|
|
|
|
{ 1 2 9 }
|
|
|
|
}
|
2017-06-01 17:59:35 -04:00
|
|
|
} [ 1 2 10 <iota> [ 3array ] 2with map ] unit-test
|
2014-07-22 09:09:26 -04:00
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
! Don't leak extra roots if error is thrown
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ 1000 [ [ 3 throw ] ignore-errors ] times ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ 1000 [ [ -1 f <array> ] ignore-errors ] times ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
! Make sure we report the correct error on stack underflow
|
2014-06-04 10:51:26 -04:00
|
|
|
[ clear drop ] [
|
2016-03-22 10:56:41 -04:00
|
|
|
2 head ${ KERNEL-ERROR ERROR-DATASTACK-UNDERFLOW } =
|
2014-06-04 10:51:26 -04:00
|
|
|
] must-fail-with
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ :c ] unit-test
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2014-06-04 10:51:26 -04:00
|
|
|
[
|
|
|
|
3 [ { } set-retainstack ] dip ]
|
2016-03-22 10:56:41 -04:00
|
|
|
[ 2 head ${ KERNEL-ERROR ERROR-RETAINSTACK-UNDERFLOW } =
|
2014-06-04 10:51:26 -04:00
|
|
|
] must-fail-with
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ :c ] unit-test
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2009-03-23 01:34:02 -04:00
|
|
|
: overflow-d ( -- ) 3 overflow-d ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-04-17 15:44:08 -04:00
|
|
|
: (overflow-d-alt) ( -- n ) 3 ;
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2009-03-23 01:34:02 -04:00
|
|
|
: overflow-d-alt ( -- ) (overflow-d-alt) overflow-d-alt ;
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2009-04-22 08:05:00 -04:00
|
|
|
: overflow-r ( -- ) 3 load-local overflow-r ;
|
|
|
|
|
|
|
|
<<
|
|
|
|
{ overflow-d (overflow-d-alt) overflow-d-alt overflow-r }
|
|
|
|
[ t "no-compile" set-word-prop ] each
|
|
|
|
>>
|
|
|
|
|
2014-06-04 10:51:26 -04:00
|
|
|
[ overflow-d ] [
|
2016-03-22 10:56:41 -04:00
|
|
|
2 head ${ KERNEL-ERROR ERROR-DATASTACK-OVERFLOW } =
|
2014-06-04 10:51:26 -04:00
|
|
|
] must-fail-with
|
2009-04-22 08:05:00 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ :c ] unit-test
|
2009-04-22 08:05:00 -04:00
|
|
|
|
2014-06-04 10:51:26 -04:00
|
|
|
[ overflow-d-alt ] [
|
2016-03-22 10:56:41 -04:00
|
|
|
2 head ${ KERNEL-ERROR ERROR-DATASTACK-OVERFLOW } =
|
2014-06-04 10:51:26 -04:00
|
|
|
] must-fail-with
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ [ :c ] with-string-writer drop ] unit-test
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2014-06-04 10:51:26 -04:00
|
|
|
[ overflow-r ] [
|
2016-03-22 10:56:41 -04:00
|
|
|
2 head ${ KERNEL-ERROR ERROR-RETAINSTACK-OVERFLOW } =
|
2014-06-04 10:51:26 -04:00
|
|
|
] must-fail-with
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ :c ] unit-test
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2008-02-06 14:47:19 -05:00
|
|
|
[ -7 <byte-array> ] must-fail
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 3 } [ t 3 and ] unit-test
|
|
|
|
{ f } [ f 3 and ] unit-test
|
|
|
|
{ f } [ 3 f and ] unit-test
|
|
|
|
{ 4 } [ 4 6 or ] unit-test
|
|
|
|
{ 6 } [ f 6 or ] unit-test
|
|
|
|
{ f } [ 1 2 xor ] unit-test
|
|
|
|
{ 1 } [ 1 f xor ] unit-test
|
|
|
|
{ 2 } [ f 2 xor ] unit-test
|
|
|
|
{ f } [ f f xor ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-05-10 18:03:41 -04:00
|
|
|
[ dip ] must-fail
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ :c ] unit-test
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2009-05-10 18:03:41 -04:00
|
|
|
[ 1 [ call ] dip ] must-fail
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ :c ] unit-test
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2009-05-10 18:03:41 -04:00
|
|
|
[ 1 2 [ call ] dip ] must-fail
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ :c ] unit-test
|
2007-10-07 00:12:02 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 5 } [ 1 [ 2 2 + ] dip + ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-06 14:47:19 -05:00
|
|
|
[ [ ] keep ] must-fail
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 6 } [ 2 [ sq ] keep + ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-06 14:47:19 -05:00
|
|
|
[ [ ] 2keep ] must-fail
|
|
|
|
[ 1 [ ] 2keep ] must-fail
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 3 1 2 } [ 1 2 [ 2drop 3 ] 2keep ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 0 } [ f [ sq ] [ 0 ] if* ] unit-test
|
|
|
|
{ 4 } [ 2 [ sq ] [ 0 ] if* ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 0 } [ f [ 0 ] unless* ] unit-test
|
|
|
|
{ t } [ t [ "Hello" ] unless* ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ "2\n" } [ [ 1 2 [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
|
|
|
|
{ "9\n" } [ [ 3 f [ . ] [ sq . ] ?if ] with-string-writer ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ f } [ f (clone) ] unit-test
|
|
|
|
{ -123 } [ -123 (clone) ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 6 2 } [ 1 2 [ 5 + ] dip ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-08-13 13:11:59 -04:00
|
|
|
{ } [ get-callstack set-callstack ] unit-test
|
2007-10-03 17:11:52 -04:00
|
|
|
|
2015-08-13 13:11:59 -04:00
|
|
|
[ 3drop get-datastack ] must-fail
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ :c ] unit-test
|
2007-12-24 20:56:23 -05:00
|
|
|
|
|
|
|
! Doesn't compile; important
|
2009-04-22 08:05:00 -04:00
|
|
|
: foo ( a -- b ) ;
|
|
|
|
|
|
|
|
<< \ foo t "no-compile" set-word-prop >>
|
2007-12-24 20:56:23 -05:00
|
|
|
|
2008-02-06 14:47:19 -05:00
|
|
|
[ drop foo ] must-fail
|
2015-07-02 20:28:17 -04:00
|
|
|
{ } [ :c ] unit-test
|
2008-01-13 18:52:14 -05:00
|
|
|
|
|
|
|
! Regression
|
|
|
|
: (loop) ( a b c d -- )
|
2008-11-23 03:44:56 -05:00
|
|
|
[ pick ] dip swap [ pick ] dip swap
|
2012-09-28 12:16:08 -04:00
|
|
|
< [ [ 1 + ] 3dip (loop) ] [ 4drop ] if ; inline recursive
|
2008-01-13 18:52:14 -05:00
|
|
|
|
2009-04-22 08:05:00 -04:00
|
|
|
: loop ( obj -- )
|
2009-10-30 14:36:15 -04:00
|
|
|
H{ } values swap [ dup length swap ] dip [ 0 ] 3dip (loop) ;
|
2008-01-13 18:52:14 -05:00
|
|
|
|
2008-02-06 14:47:19 -05:00
|
|
|
[ loop ] must-fail
|
2008-04-07 00:31:53 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 1 1 2 2 3 3 } [ 1 2 3 [ dup ] tri@ ] unit-test
|
|
|
|
{ 1 4 9 } [ 1 2 3 [ sq ] tri@ ] unit-test
|
2008-06-27 03:17:19 -04:00
|
|
|
[ [ sq ] tri@ ] must-infer
|
2008-09-10 02:45:16 -04:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 4 } [ 1 { [ 1 ] [ 2 ] } dispatch sq ] unit-test
|
2008-11-23 22:40:54 -05:00
|
|
|
|
|
|
|
! Test traceback accuracy
|
|
|
|
: last-frame ( -- pair )
|
2016-10-11 03:32:55 -04:00
|
|
|
6 9 error-continuation get call>> callstack>array subseq ;
|
2008-11-23 22:40:54 -05:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{
|
2010-02-01 15:41:13 -05:00
|
|
|
{ [ 1 2 [ 3 throw ] call 4 ] [ 1 2 [ 3 throw ] call 4 ] 3 }
|
2015-07-02 20:28:17 -04:00
|
|
|
} [
|
2008-11-23 22:40:54 -05:00
|
|
|
[ [ 1 2 [ 3 throw ] call 4 ] call ] ignore-errors
|
|
|
|
last-frame
|
|
|
|
] unit-test
|
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{
|
2010-02-01 15:41:13 -05:00
|
|
|
{ [ 1 2 [ 3 throw ] dip 4 ] [ 1 2 [ 3 throw ] dip 4 ] 3 }
|
2015-07-02 20:28:17 -04:00
|
|
|
} [
|
2008-11-23 22:40:54 -05:00
|
|
|
[ [ 1 2 [ 3 throw ] dip 4 ] call ] ignore-errors
|
|
|
|
last-frame
|
|
|
|
] unit-test
|
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{
|
2010-02-01 15:41:13 -05:00
|
|
|
{ [ 1 2 3 throw [ ] call 4 ] [ 1 2 3 throw [ ] call 4 ] 3 }
|
2015-07-02 20:28:17 -04:00
|
|
|
} [
|
2008-11-23 22:40:54 -05:00
|
|
|
[ [ 1 2 3 throw [ ] call 4 ] call ] ignore-errors
|
|
|
|
last-frame
|
|
|
|
] unit-test
|
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{
|
2010-02-01 15:41:13 -05:00
|
|
|
{ [ 1 2 3 throw [ ] dip 4 ] [ 1 2 3 throw [ ] dip 4 ] 3 }
|
2015-07-02 20:28:17 -04:00
|
|
|
} [
|
2008-11-23 22:40:54 -05:00
|
|
|
[ [ 1 2 3 throw [ ] dip 4 ] call ] ignore-errors
|
|
|
|
last-frame
|
|
|
|
] unit-test
|
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{
|
2010-02-01 15:41:13 -05:00
|
|
|
{ [ 1 2 3 throw [ ] [ ] if 4 ] [ 1 2 3 throw [ ] [ ] if 4 ] 3 }
|
2015-07-02 20:28:17 -04:00
|
|
|
} [
|
2008-11-23 22:40:54 -05:00
|
|
|
[ [ 1 2 3 throw [ ] [ ] if 4 ] call ] ignore-errors
|
|
|
|
last-frame
|
|
|
|
] unit-test
|
2009-01-05 19:12:34 -05:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 10 2 3 4 5 } [ 1 2 3 4 5 [ 10 * ] 4dip ] unit-test
|
2009-01-05 19:12:34 -05:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ 3 -1 5/6 } [ 1 2 3 4 5 6 [ + ] [ - ] [ / ] 2tri* ] unit-test
|
2009-01-05 19:12:34 -05:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ { 1 2 } { 3 4 } { 5 6 } } [ 1 2 3 4 5 6 [ 2array ] 2tri@ ] unit-test
|
2009-11-10 22:06:36 -05:00
|
|
|
|
2015-07-02 20:28:17 -04:00
|
|
|
{ t } [ { } identity-hashcode fixnum? ] unit-test
|
|
|
|
{ 123 } [ 123 identity-hashcode ] unit-test
|
|
|
|
{ t } [ f identity-hashcode fixnum? ] unit-test
|
2011-11-11 16:29:46 -05:00
|
|
|
|
|
|
|
! Make sure memory protection faults work
|
|
|
|
[ f 0 alien-unsigned-1 ] [ vm-error? ] must-fail-with
|
|
|
|
[ 1 <alien> 0 alien-unsigned-1 ] [ vm-error? ] must-fail-with
|
2012-09-28 12:16:08 -04:00
|
|
|
|
|
|
|
{ 1 2 3 1 2 3 } [ 1 2 3 3dup ] unit-test
|
|
|
|
{ 1 2 3 4 1 2 3 4 } [ 1 2 3 4 4dup ] unit-test
|