1 USING: tools.test macros math kernel arrays
2 vectors io.streams.string prettyprint parser eval see
3 stack-checker compiler.units definitions vocabs ;
6 MACRO: see-test ( a b -- quot ) + ;
8 { t } [ \ see-test macro? ] unit-test
10 { "USING: math ;\nIN: macros.tests\nMACRO: see-test ( a b -- quot ) + ;\n" }
11 [ [ \ see-test see ] with-string-writer ]
14 { t } [ \ see-test macro? ] unit-test
17 "USING: math ;\nIN: macros.tests\n: see-test ( a b -- c ) - ;\n" dup eval( -- )
18 [ \ see-test see ] with-string-writer =
21 { f } [ \ see-test macro? ] unit-test
23 { } [ "USING: stack-checker kernel ; IN: hanging-macro MACRO: c ( quot -- quot ) infer drop [ ] ;" eval( -- ) ] unit-test
24 { } [ "USING: kernel ; IN: hanging-macro : a ( -- ) [ a ] c ;" eval( -- ) ] unit-test
26 { } [ [ "hanging-macro" forget-vocab ] with-compilation-unit ] unit-test
28 { } [ "IN: macros.tests MACRO: foo ( -- x ) [ ] ;" eval( -- ) ] unit-test
29 [ "IN: macros.tests MACRO: foo ( -- x ) [ ] ; inline" eval( -- ) ] must-fail
31 ! The macro expander code should infer
32 MACRO: bad-macro ( a -- b ) 1 2 3 [ ] ;
34 ! Must fail twice, and not memoize a bad result
35 [ [ 0 bad-macro ] call ] must-fail
36 [ [ 0 bad-macro ] call ] must-fail
38 [ [ 0 bad-macro ] infer ] must-fail
40 { } [ [ \ bad-macro forget ] with-compilation-unit ] unit-test