1 IN: stack-checker.transforms.tests
2 USING: sequences stack-checker.transforms tools.test math kernel
3 quotations stack-checker accessors combinators words arrays
4 classes classes.tuple ;
6 : compose-n-quot ( word -- quot' ) <repetition> >quotation ;
7 : compose-n ( quot -- ) compose-n-quot call ;
8 \ compose-n [ compose-n-quot ] 2 define-transform
9 : compose-n-test ( a b c -- x ) 2 \ + compose-n ;
11 [ 6 ] [ 1 2 3 compose-n-test ] unit-test
17 : cleave-test ( color -- r g b )
18 { [ r>> ] [ g>> ] [ b>> ] } cleave ;
20 { 1 3 } [ cleave-test ] must-infer-as
22 [ 1 2 3 ] [ 1 2 3 <color> cleave-test ] unit-test
24 [ 1 2 3 ] [ 1 2 3 <color> \ cleave-test def>> call ] unit-test
26 : 2cleave-test ( a b -- c d e ) { [ 2array ] [ + ] [ - ] } 2cleave ;
28 [ { 1 2 } 3 -1 ] [ 1 2 2cleave-test ] unit-test
30 [ { 1 2 } 3 -1 ] [ 1 2 \ 2cleave-test def>> call ] unit-test
32 : spread-test ( a b c -- d e f ) { [ sq ] [ neg ] [ recip ] } spread ;
34 [ 16 -3 1/6 ] [ 4 3 6 spread-test ] unit-test
36 [ 16 -3 1/6 ] [ 4 3 6 \ spread-test def>> call ] unit-test
38 [ fixnum instance? ] must-infer
40 : bad-new-test ( -- obj ) V{ } new ;
42 [ bad-new-test ] must-infer
44 [ bad-new-test ] must-fail
46 ! Corner case if macro expansion calls 'infer', found by Doug
47 DEFER: smart-combo ( quot -- )
49 \ smart-combo [ infer [ ] curry ] 1 define-transform
51 [ [ "a" "b" "c" ] smart-combo ] must-infer
53 [ [ [ "a" "b" ] smart-combo "c" ] smart-combo ] must-infer
55 : very-smart-combo ( quot -- ) smart-combo ; inline
57 [ [ "a" "b" "c" ] very-smart-combo ] must-infer
59 [ [ [ "a" "b" ] very-smart-combo "c" ] very-smart-combo ] must-infer
61 ! Caveat found by Doug
62 DEFER: curry-folding-test ( quot -- )
64 \ curry-folding-test [ length \ drop <repetition> >quotation ] 1 define-transform
66 { 3 0 } [ [ 1 2 3 ] curry-folding-test ] must-infer-as
67 { 3 0 } [ 1 [ 2 3 ] curry curry-folding-test ] must-infer-as
68 { 3 0 } [ [ 1 2 ] 3 [ ] curry compose curry-folding-test ] must-infer-as
70 [ t ] [ \ + (( a b -- c )) execute-effect-unsafe? ] unit-test
71 [ t ] [ \ + (( a b c -- d e )) execute-effect-unsafe? ] unit-test
72 [ f ] [ \ + (( a b c -- d )) execute-effect-unsafe? ] unit-test
73 [ f ] [ \ call (( x -- )) execute-effect-unsafe? ] unit-test