]> gitweb.factorcode.org Git - factor.git/blob - core/test/parser.factor
2f96bae8dcde9b9b8e208fd23ca056abff7acefe
[factor.git] / core / test / parser.factor
1 USING: arrays errors math parser test kernel generic words io
2 listener namespaces ;
3 IN: temporary
4
5 [ 1 CHAR: a ]
6 [ 0 "abcd" next-char ] unit-test
7
8 [ 6 CHAR: \s ]
9 [ 1 "\\u0020hello" next-escape ] unit-test
10
11 [ 2 CHAR: \n ]
12 [ 1 "\\nhello" next-escape ] unit-test
13
14 [ 6 CHAR: \s ]
15 [ 0 "\\u0020hello" next-char ] unit-test
16
17 [ [ 1 [ 2 [ 3 ] 4 ] 5 ] ]
18 [ "1\n[\n2\n[\n3\n]\n4\n]\n5" parse ]
19 unit-test
20
21 [ [ t t f f ] ]
22 [ "t t f f" parse ]
23 unit-test
24
25 [ [ "hello world" ] ]
26 [ "\"hello world\"" parse ]
27 unit-test
28
29 [ [ "\n\r\t\\" ] ]
30 [ "\"\\n\\r\\t\\\\\"" parse ]
31 unit-test
32
33 [ "hello world" ]
34 [
35     "IN: temporary : hello \"hello world\" ;"
36     parse call "USE: scratchpad hello" eval
37 ] unit-test
38
39 [ ]
40 [ "! This is a comment, people." parse call ]
41 unit-test
42
43 ! Test escapes
44
45 [ [ " " ] ]
46 [ "\"\\u0020\"" parse ]
47 unit-test
48
49 [ [ "'" ] ]
50 [ "\"\\u0027\"" parse ]
51 unit-test
52
53 [ "\\u123" parse ] unit-test-fails
54
55 ! Test EOL comments in multiline strings.
56 [ [ "Hello" ] ] [ "#! This calls until-eol.\n\"Hello\"" parse ] unit-test 
57
58 [ word ] [ \ f class ] unit-test
59
60 ! Test stack effect parsing
61
62 : foo ( a b -- c ) + ;
63
64 [ T{ effect f { "a" "b" } { "c" } f } ]
65 [ \ foo "declared-effect" word-prop ] unit-test
66
67 [ t ] [ 1 1 <effect> 2 2 <effect> effect<= ] unit-test
68 [ f ] [ 1 0 <effect> 2 2 <effect> effect<= ] unit-test
69 [ t ] [ 2 2 <effect> 2 2 <effect> effect<= ] unit-test
70 [ f ] [ 3 3 <effect> 2 2 <effect> effect<= ] unit-test
71 [ f ] [ 2 3 <effect> 2 2 <effect> effect<= ] unit-test
72
73 : baz ( a b -- * ) 2array throw ;
74
75 [ t ]
76 [ \ baz "declared-effect" word-prop effect-terminated? ]
77 unit-test
78
79 [ [ ] ] [ "IN: temporary : foo ( a b -- c ) + ;" parse ] unit-test
80 [ [ ] ] [ "IN: temporary : foo ;" parse ] unit-test
81 [ f ] [ \ foo "declared-effect" word-prop ] unit-test
82
83 ! Funny bug
84 [ 2 ] [ "IN: temporary : \0. 2 ; \0." eval ] unit-test
85
86 [ "IN: temporary : missing-- ( a b ) ;" eval ] unit-test-fails
87
88 ! Test interactive parsing, restarts
89 [
90     file-vocabs
91     "errors" use+
92
93     [ [ + 1 2 3 4 ] ]
94     [
95         [
96             "cont" set
97             [
98                 "\ + 1 2 3 4" 
99                 <string-reader>
100                 parse-interactive "cont" get continue-with
101             ] catch
102             "0 :res" eval
103         ] callcc1
104     ] unit-test
105 ] with-scope