1 USING: arrays math parser tools.test kernel generic words
2 io.streams.string namespaces classes effects source-files assocs
3 sequences strings io.files io.pathnames definitions
4 continuations sorting classes.tuple compiler.units debugger
5 vocabs vocabs.loader accessors eval combinators lexer ;
12 [ "1\n[\n2\n[\n3\n]\n4\n]\n5" eval ]
20 [ "\"hello world\"" eval ]
24 [ "\"\\n\\r\\t\\\\\"" eval ]
29 "IN: parser.tests : hello \"hello world\" ;"
30 eval "USE: parser.tests hello" eval
34 [ "! This is a comment, people." eval ]
40 [ "\"\\u000020\"" eval ]
44 [ "\"\\u000027\"" eval ]
47 ! Test EOL comments in multiline strings.
48 [ "Hello" ] [ "#! This calls until-eol.\n\"Hello\"" eval ] unit-test
50 [ word ] [ \ f class ] unit-test
52 ! Test stack effect parsing
54 : effect-parsing-test ( a b -- c ) + ;
57 "effect-parsing-test" "parser.tests" lookup
58 \ effect-parsing-test eq?
61 [ T{ effect f { "a" "b" } { "c" } f } ]
62 [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
64 : baz ( a b -- * ) 2array throw ;
67 [ \ baz "declared-effect" word-prop terminated?>> ]
70 [ ] [ "IN: parser.tests USE: math : effect-parsing-test ( a b -- d ) - ;" eval ] unit-test
73 "effect-parsing-test" "parser.tests" lookup
74 \ effect-parsing-test eq?
77 [ T{ effect f { "a" "b" } { "d" } f } ]
78 [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
80 [ ] [ "IN: parser.tests : effect-parsing-test ;" eval ] unit-test
82 [ f ] [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
85 [ 2 ] [ "IN: parser.tests : \0. 2 ; \0." eval ] unit-test
87 [ "IN: parser.tests : missing-- ( a b ) ;" eval ] must-fail
89 ! These should throw errors
90 [ "HEX: zzz" eval ] must-fail
91 [ "OCT: 999" eval ] must-fail
92 [ "BIN: --0" eval ] must-fail
98 { "scratchpad" "arrays" } set-use
100 ! This shouldn't modify in/use in the outer scope!
103 use get { "scratchpad" "arrays" } set-use use get =
108 "IN: parser.tests USING: math prettyprint ; : foo 2 2 + . ; parsing" eval
110 [ ] [ "USE: parser.tests foo" eval ] unit-test
112 "IN: parser.tests USING: math prettyprint ; : foo 2 2 + . ;" eval
115 "USE: parser.tests \\ foo" eval
116 "foo" "parser.tests" lookup eq?
122 "IN: parser.tests : smudge-me ;" <string-reader> "foo"
125 "foo" source-file definitions>> first assoc-size
128 [ t ] [ "smudge-me" "parser.tests" lookup >boolean ] unit-test
131 "IN: parser.tests : smudge-me-more ;" <string-reader> "foo"
135 [ t ] [ "smudge-me-more" "parser.tests" lookup >boolean ] unit-test
136 [ f ] [ "smudge-me" "parser.tests" lookup >boolean ] unit-test
139 "IN: parser.tests USING: math strings ; GENERIC: smudge-me M: integer smudge-me ; M: string smudge-me ;" <string-reader> "foo"
142 "foo" source-file definitions>> first assoc-size
146 "IN: parser.tests USING: arrays ; M: array smudge-me ;" <string-reader> "bar"
149 "bar" source-file definitions>> first assoc-size
153 "IN: parser.tests USING: math strings ; GENERIC: smudge-me M: integer smudge-me ;" <string-reader> "foo"
156 "foo" source-file definitions>> first assoc-size
160 array "smudge-me" "parser.tests" lookup order memq?
164 integer "smudge-me" "parser.tests" lookup order memq?
168 string "smudge-me" "parser.tests" lookup order memq?
172 "IN: parser.tests USE: math 2 2 +" <string-reader> "a"
177 "a" <pathname> \ + usage member?
181 "IN: parser.tests USE: math 2 2 -" <string-reader> "a"
186 "a" <pathname> \ + usage member?
190 "a" source-files get delete-at
192 "IN: parser.tests DEFER: x : y x ; : x y ;"
193 <string-reader> "a" parse-stream drop
197 "a" source-files get delete-at
200 "IN: parser.tests : x ; : y 3 throw ; this is an error"
201 <string-reader> "a" parse-stream
202 ] [ source-file-error? ] must-fail-with
205 "y" "parser.tests" lookup >boolean
209 "IN: parser.tests : x ;"
210 <string-reader> "a" parse-stream drop
212 "y" "parser.tests" lookup
215 ! Test new forward definition logic
218 <string-reader> "axx" parse-stream drop
222 "USE: axx IN: bxx : bxx ; : cxx axx bxx ;"
223 <string-reader> "bxx" parse-stream drop
226 ! So we move the bxx word to axx...
228 "IN: axx : axx ; : bxx ;"
229 <string-reader> "axx" parse-stream drop
232 [ t ] [ "bxx" "axx" lookup >boolean ] unit-test
234 ! And reload the file that uses it...
236 "USE: axx IN: bxx : cxx axx bxx ;"
237 <string-reader> "bxx" parse-stream drop
240 ! And hope not to get a forward-error!
242 ! Turning a generic into a non-generic could cause all
245 "IN: ayy USE: kernel GENERIC: ayy M: object ayy ;"
246 <string-reader> "ayy" parse-stream drop
250 "IN: ayy USE: kernel : ayy ;"
251 <string-reader> "ayy" parse-stream drop
255 "IN: azz TUPLE: my-class ; GENERIC: a-generic"
256 <string-reader> "azz" parse-stream drop
260 "USE: azz M: my-class a-generic ;"
261 <string-reader> "azz-2" parse-stream drop
265 "IN: azz GENERIC: a-generic"
266 <string-reader> "azz" parse-stream drop
270 "USE: azz USE: math M: integer a-generic ;"
271 <string-reader> "azz-2" parse-stream drop
275 "IN: parser.tests : <bogus-error> ; : bogus <bogus-error> ;"
276 <string-reader> "bogus-error" parse-stream drop
280 "IN: parser.tests TUPLE: bogus-error ; C: <bogus-error> bogus-error : bogus <bogus-error> ;"
281 <string-reader> "bogus-error" parse-stream drop
284 ! Problems with class predicates -vs- ordinary words
286 "IN: parser.tests TUPLE: killer ;"
287 <string-reader> "removing-the-predicate" parse-stream drop
291 "IN: parser.tests GENERIC: killer? ( a -- b )"
292 <string-reader> "removing-the-predicate" parse-stream drop
296 "killer?" "parser.tests" lookup >boolean
300 "IN: parser.tests TUPLE: another-pred-test ; GENERIC: another-pred-test?"
301 <string-reader> "removing-the-predicate" parse-stream
302 ] [ error>> error>> error>> redefine-error? ] must-fail-with
305 "IN: parser.tests TUPLE: class-redef-test ; TUPLE: class-redef-test ;"
306 <string-reader> "redefining-a-class-1" parse-stream
307 ] [ error>> error>> error>> redefine-error? ] must-fail-with
310 "IN: parser.tests TUPLE: class-redef-test ; SYMBOL: class-redef-test"
311 <string-reader> "redefining-a-class-2" parse-stream drop
315 "IN: parser.tests TUPLE: class-redef-test ; SYMBOL: class-redef-test : class-redef-test ;"
316 <string-reader> "redefining-a-class-3" parse-stream drop
317 ] [ error>> error>> error>> redefine-error? ] must-fail-with
320 "IN: parser.tests TUPLE: class-fwd-test ;"
321 <string-reader> "redefining-a-class-3" parse-stream drop
325 "IN: parser.tests \\ class-fwd-test"
326 <string-reader> "redefining-a-class-3" parse-stream drop
327 ] [ error>> error>> error>> no-word-error? ] must-fail-with
330 "IN: parser.tests TUPLE: class-fwd-test ; SYMBOL: class-fwd-test"
331 <string-reader> "redefining-a-class-3" parse-stream drop
335 "IN: parser.tests \\ class-fwd-test"
336 <string-reader> "redefining-a-class-3" parse-stream drop
337 ] [ error>> error>> error>> no-word-error? ] must-fail-with
340 "IN: parser.tests : foo ; TUPLE: foo ;"
341 <string-reader> "redefining-a-class-4" parse-stream drop
342 ] [ error>> error>> error>> redefine-error? ] must-fail-with
345 "IN: parser.tests : foo ( x y -- z ) 1 2 ; : bar ( a -- b ) ;" eval
349 "IN: parser.tests : foo ( x y -- z) 1 2 ; : bar ( a -- b ) ;" eval
354 "IN: parser.tests USE: kernel PREDICATE: foo < object ( x -- y ) ;" eval
358 "foo?" "parser.tests" lookup word eq?
363 "redefining-a-class-5" forget-source
364 "redefining-a-class-6" forget-source
365 "redefining-a-class-7" forget-source
366 ] with-compilation-unit
371 "IN: parser.tests TUPLE: foo ; GENERIC: foo"
372 <string-reader> "redefining-a-class-5" parse-stream drop
376 "IN: parser.tests M: f foo ;"
377 <string-reader> "redefining-a-class-6" parse-stream drop
380 [ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
383 "IN: parser.tests TUPLE: foo ; GENERIC: foo"
384 <string-reader> "redefining-a-class-5" parse-stream drop
387 [ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
390 "IN: parser.tests TUPLE: foo ; GENERIC: foo"
391 <string-reader> "redefining-a-class-7" parse-stream drop
394 [ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
397 "IN: parser.tests TUPLE: foo ;"
398 <string-reader> "redefining-a-class-7" parse-stream drop
401 [ t ] [ "foo" "parser.tests" lookup symbol? ] unit-test
404 [ "resource:core/parser/test/assert-depth.factor" run-file ]
405 [ got>> { 1 2 3 } sequence= ]
410 "IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
411 <string-reader> "d-f-s-test" parse-stream drop
415 "IN: parser.tests DEFER: d-f-s d-f-s FORGET: d-f-s SYMBOL: d-f-s d-f-s"
416 <string-reader> "d-f-s-test" parse-stream drop
420 "IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
421 <string-reader> "d-f-s-test" parse-stream drop
426 [ "this-better-not-exist" forget-vocab ] with-compilation-unit
430 "USE: this-better-not-exist" eval
433 [ ": foo ;" eval ] [ error>> error>> no-current-vocab? ] must-fail-with
435 [ 92 ] [ "CHAR: \\" eval ] unit-test
436 [ 92 ] [ "CHAR: \\\\" eval ] unit-test
441 "USING: math arrays ;"
442 "GENERIC: change-combination"
443 "M: integer change-combination 1 ;"
444 "M: array change-combination 2 ;"
445 } "\n" join <string-reader> "change-combination-test" parse-stream drop
451 "USING: math arrays ;"
452 "GENERIC# change-combination 1"
453 "M: integer change-combination 1 ;"
454 "M: array change-combination 2 ;"
455 } "\n" join <string-reader> "change-combination-test" parse-stream drop
459 "change-combination" "parser.tests" lookup
460 "methods" word-prop assoc-size
465 "IN: parser.tests DEFER: twice-fails FORGET: twice-fails MIXIN: twice-fails"
466 <string-reader> "twice-fails-test" parse-stream drop
471 "IN: parser.tests : staging-problem-test-1 1 ; : staging-problem-test-2 staging-problem-test-1 ;"
472 <string-reader> "staging-problem-test" parse-stream
475 [ t ] [ "staging-problem-test-1" "parser.tests" lookup >boolean ] unit-test
477 [ t ] [ "staging-problem-test-2" "parser.tests" lookup >boolean ] unit-test
480 "IN: parser.tests << : staging-problem-test-1 1 ; >> : staging-problem-test-2 staging-problem-test-1 ;"
481 <string-reader> "staging-problem-test" parse-stream
484 [ t ] [ "staging-problem-test-1" "parser.tests" lookup >boolean ] unit-test
486 [ t ] [ "staging-problem-test-2" "parser.tests" lookup >boolean ] unit-test
488 [ "DEFER: blah" eval ] [ error>> error>> no-current-vocab? ] must-fail-with
491 "IN: parser.tests : blah ; parsing FORGET: blah" eval
493 error>> staging-violation?
496 ! Bogus error message
499 [ "IN: parser.tests USE: kernel TUPLE: blah < tuple ; : blah ; TUPLE: blah < tuple ; : blah ;" eval ]
500 [ error>> error>> def>> \ blah eq? ] must-fail-with
502 [ ] [ f lexer set f file set "Hello world" note. ] unit-test
504 [ "CHAR: \\u9999999999999" eval ] must-fail