]> gitweb.factorcode.org Git - factor.git/blob - core/macros/macros-tests.factor
arm.64.factor: extra semicolon removed
[factor.git] / core / macros / macros-tests.factor
1 USING: tools.test macros math kernel arrays
2 vectors io.streams.string prettyprint parser eval see
3 stack-checker compiler.units definitions vocabs ;
4 IN: macros.tests
5
6 MACRO: see-test ( a b -- quot ) + ;
7
8 { t } [ \ see-test macro? ] unit-test
9
10 { "USING: math ;\nIN: macros.tests\nMACRO: see-test ( a b -- quot ) + ;\n" }
11 [ [ \ see-test see ] with-string-writer ]
12 unit-test
13
14 { t } [ \ see-test macro? ] unit-test
15
16 { t } [
17     "USING: math ;\nIN: macros.tests\n: see-test ( a b -- c ) - ;\n" dup eval( -- )
18     [ \ see-test see ] with-string-writer =
19 ] unit-test
20
21 { f } [ \ see-test macro? ] unit-test
22
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
25
26 { } [ [ "hanging-macro" forget-vocab ] with-compilation-unit ] unit-test
27
28 { } [ "IN: macros.tests MACRO: foo ( -- x ) [ ] ;" eval( -- ) ] unit-test
29     [ "IN: macros.tests MACRO: foo ( -- x ) [ ] ; inline" eval( -- ) ] must-fail
30
31 ! The macro expander code should infer
32 MACRO: bad-macro ( a -- b ) 1 2 3 [ ] ;
33
34 ! Must fail twice, and not memoize a bad result
35 [ [ 0 bad-macro ] call ] must-fail
36 [ [ 0 bad-macro ] call ] must-fail
37
38 [ [ 0 bad-macro ] infer ] must-fail
39
40 { } [ [ \ bad-macro forget ] with-compilation-unit ] unit-test