]> gitweb.factorcode.org Git - factor.git/blob - core/locals/parser/parser-tests.factor
df0466b8bc6877806b6500af942c3a2fd8e8909e
[factor.git] / core / locals / parser / parser-tests.factor
1 USING: accessors assocs compiler.units kernel lexer locals.backend
2 locals.parser namespaces parser prettyprint sequences sorting
3 tools.test vocabs vocabs.parser ;
4 IN: locals.parser.tests
5
6 ! XXX: remove the << and >> below and make test-all pass
7
8 <<
9 ! (::)
10 {
11     "dobiedoo"
12     [ load-local 1 drop-locals ]
13     ( x -- y )
14 } [
15     [
16         { "dobiedoo ( x -- y ) ;" } <lexer> [ (::) ] with-lexer
17     ] with-compilation-unit
18     [ name>> ] 2dip
19 ] unit-test
20
21 {
22     "dobiedoo"
23     [ 2 load-locals 2 drop-locals ]
24     ( x y -- z )
25 } [
26     [
27         { "dobiedoo ( x y -- z ) ;" } <lexer> [ (::) ] with-lexer
28     ] with-compilation-unit
29     [ name>> ] 2dip
30 ] unit-test
31
32 ! parse-def
33 { "um" t } [
34     [
35         "um" parse-def
36         local>> name>>
37         qualified-vocabs last words>> keys "um" swap member?
38     ] with-compilation-unit
39 ] unit-test
40 >>
41
42 ! check-local-name
43 { "hello" } [
44     "hello" check-local-name
45 ] unit-test
46
47 ! make-locals
48 { { "a" "b" "c" } } [
49     [ { "a" "b" "c" } make-locals ] with-compilation-unit
50     nip values [ name>> ] map
51 ] unit-test
52
53 ! parse-local-defs
54 { { "tok1" "tok2" } } [
55     [
56         { "tok1 tok2 |" } <lexer> [ parse-local-defs ] with-lexer
57     ] with-compilation-unit
58     nip values [ name>> ] map
59 ] unit-test
60
61 ! parse-multi-def
62 {
63     { "tok1" "tok2" }
64     { "tok1" "tok2" }
65 } [
66     [
67         { "tok1 tok2 )" } <lexer> [ parse-multi-def ] with-lexer
68     ] with-compilation-unit
69     [ locals>> [ name>> ] map ] [ keys ] bi*
70 ] unit-test
71
72 <<
73 {
74     "V{ 99 :> kkk kkk }"
75 } [
76     [
77         "locals" use-vocab
78         { "99 :> kkk kkk ;" } <lexer> [
79             H{ } clone [ \ ; parse-until ] with-lambda-scope
80         ] with-lexer
81     ] with-compilation-unit unparse
82 ] unit-test
83 >>