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