1 USING: arrays math parser tools.test kernel generic words
2 io.streams.string namespaces classes effects source-files
3 assocs sequences strings io.files definitions continuations
4 sorting classes.tuple compiler.units debugger vocabs
5 vocabs.loader accessors eval combinators ;
10 [ "1\n[\n2\n[\n3\n]\n4\n]\n5" eval ]
18 [ "\"hello world\"" eval ]
22 [ "\"\\n\\r\\t\\\\\"" eval ]
27 "IN: parser.tests : hello \"hello world\" ;"
28 eval "USE: parser.tests hello" eval
32 [ "! This is a comment, people." eval ]
38 [ "\"\\u000020\"" eval ]
42 [ "\"\\u000027\"" eval ]
45 ! Test EOL comments in multiline strings.
46 [ "Hello" ] [ "#! This calls until-eol.\n\"Hello\"" eval ] unit-test
48 [ word ] [ \ f class ] unit-test
50 ! Test stack effect parsing
52 : effect-parsing-test ( a b -- c ) + ;
55 "effect-parsing-test" "parser.tests" lookup
56 \ effect-parsing-test eq?
59 [ T{ effect f { "a" "b" } { "c" } f } ]
60 [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
62 : baz ( a b -- * ) 2array throw ;
65 [ \ baz "declared-effect" word-prop terminated?>> ]
68 [ ] [ "IN: parser.tests USE: math : effect-parsing-test ( a b -- d ) - ;" eval ] unit-test
71 "effect-parsing-test" "parser.tests" lookup
72 \ effect-parsing-test eq?
75 [ T{ effect f { "a" "b" } { "d" } f } ]
76 [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
78 [ ] [ "IN: parser.tests : effect-parsing-test ;" eval ] unit-test
80 [ f ] [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
83 [ 2 ] [ "IN: parser.tests : \0. 2 ; \0." eval ] unit-test
85 [ "IN: parser.tests : missing-- ( a b ) ;" eval ] must-fail
87 ! These should throw errors
88 [ "HEX: zzz" eval ] must-fail
89 [ "OCT: 999" eval ] must-fail
90 [ "BIN: --0" eval ] must-fail
96 { "scratchpad" "arrays" } set-use
98 ! This shouldn't modify in/use in the outer scope!
101 use get { "scratchpad" "arrays" } set-use use get =
106 "IN: parser.tests USING: math prettyprint ; : foo 2 2 + . ; parsing" eval
108 [ ] [ "USE: parser.tests foo" eval ] unit-test
110 "IN: parser.tests USING: math prettyprint ; : foo 2 2 + . ;" eval
113 "USE: parser.tests \\ foo" eval
114 "foo" "parser.tests" lookup eq?
120 "IN: parser.tests : smudge-me ;" <string-reader> "foo"
123 "foo" source-file definitions>> first assoc-size
126 [ t ] [ "smudge-me" "parser.tests" lookup >boolean ] unit-test
129 "IN: parser.tests : smudge-me-more ;" <string-reader> "foo"
133 [ t ] [ "smudge-me-more" "parser.tests" lookup >boolean ] unit-test
134 [ f ] [ "smudge-me" "parser.tests" lookup >boolean ] unit-test
137 "IN: parser.tests USING: math strings ; GENERIC: smudge-me M: integer smudge-me ; M: string smudge-me ;" <string-reader> "foo"
140 "foo" source-file definitions>> first assoc-size
144 "IN: parser.tests USING: arrays ; M: array smudge-me ;" <string-reader> "bar"
147 "bar" source-file definitions>> first assoc-size
151 "IN: parser.tests USING: math strings ; GENERIC: smudge-me M: integer smudge-me ;" <string-reader> "foo"
154 "foo" source-file definitions>> first assoc-size
158 array "smudge-me" "parser.tests" lookup order memq?
162 integer "smudge-me" "parser.tests" lookup order memq?
166 string "smudge-me" "parser.tests" lookup order memq?
170 "IN: parser.tests USE: math 2 2 +" <string-reader> "a"
175 "a" <pathname> \ + usage member?
179 "IN: parser.tests USE: math 2 2 -" <string-reader> "a"
184 "a" <pathname> \ + usage member?
188 "a" source-files get delete-at
190 "IN: parser.tests DEFER: x : y x ; : x y ;"
191 <string-reader> "a" parse-stream drop
195 "a" source-files get delete-at
198 "IN: parser.tests : x ; : y 3 throw ; this is an error"
199 <string-reader> "a" parse-stream
200 ] [ source-file-error? ] must-fail-with
203 "y" "parser.tests" lookup >boolean
207 "IN: parser.tests : x ;"
208 <string-reader> "a" parse-stream drop
210 "y" "parser.tests" lookup
213 ! Test new forward definition logic
216 <string-reader> "axx" parse-stream drop
220 "USE: axx IN: bxx : bxx ; : cxx axx bxx ;"
221 <string-reader> "bxx" parse-stream drop
224 ! So we move the bxx word to axx...
226 "IN: axx : axx ; : bxx ;"
227 <string-reader> "axx" parse-stream drop
230 [ t ] [ "bxx" "axx" lookup >boolean ] unit-test
232 ! And reload the file that uses it...
234 "USE: axx IN: bxx : cxx axx bxx ;"
235 <string-reader> "bxx" parse-stream drop
238 ! And hope not to get a forward-error!
240 ! Turning a generic into a non-generic could cause all
243 "IN: ayy USE: kernel GENERIC: ayy M: object ayy ;"
244 <string-reader> "ayy" parse-stream drop
248 "IN: ayy USE: kernel : ayy ;"
249 <string-reader> "ayy" parse-stream drop
253 "IN: azz TUPLE: my-class ; GENERIC: a-generic"
254 <string-reader> "azz" parse-stream drop
258 "USE: azz M: my-class a-generic ;"
259 <string-reader> "azz-2" parse-stream drop
263 "IN: azz GENERIC: a-generic"
264 <string-reader> "azz" parse-stream drop
268 "USE: azz USE: math M: integer a-generic ;"
269 <string-reader> "azz-2" parse-stream drop
273 "IN: parser.tests : <bogus-error> ; : bogus <bogus-error> ;"
274 <string-reader> "bogus-error" parse-stream drop
278 "IN: parser.tests TUPLE: bogus-error ; C: <bogus-error> bogus-error : bogus <bogus-error> ;"
279 <string-reader> "bogus-error" parse-stream drop
282 ! Problems with class predicates -vs- ordinary words
284 "IN: parser.tests TUPLE: killer ;"
285 <string-reader> "removing-the-predicate" parse-stream drop
289 "IN: parser.tests GENERIC: killer? ( a -- b )"
290 <string-reader> "removing-the-predicate" parse-stream drop
294 "killer?" "parser.tests" lookup >boolean
298 "IN: parser.tests TUPLE: another-pred-test ; GENERIC: another-pred-test?"
299 <string-reader> "removing-the-predicate" parse-stream
300 ] [ error>> error>> error>> redefine-error? ] must-fail-with
303 "IN: parser.tests TUPLE: class-redef-test ; TUPLE: class-redef-test ;"
304 <string-reader> "redefining-a-class-1" parse-stream
305 ] [ error>> error>> error>> redefine-error? ] must-fail-with
308 "IN: parser.tests TUPLE: class-redef-test ; SYMBOL: class-redef-test"
309 <string-reader> "redefining-a-class-2" parse-stream drop
313 "IN: parser.tests TUPLE: class-redef-test ; SYMBOL: class-redef-test : class-redef-test ;"
314 <string-reader> "redefining-a-class-3" parse-stream drop
315 ] [ error>> error>> error>> redefine-error? ] must-fail-with
318 "IN: parser.tests TUPLE: class-fwd-test ;"
319 <string-reader> "redefining-a-class-3" parse-stream drop
323 "IN: parser.tests \\ class-fwd-test"
324 <string-reader> "redefining-a-class-3" parse-stream drop
325 ] [ error>> error>> error>> no-word-error? ] must-fail-with
328 "IN: parser.tests TUPLE: class-fwd-test ; SYMBOL: class-fwd-test"
329 <string-reader> "redefining-a-class-3" parse-stream drop
333 "IN: parser.tests \\ class-fwd-test"
334 <string-reader> "redefining-a-class-3" parse-stream drop
335 ] [ error>> error>> error>> no-word-error? ] must-fail-with
338 "IN: parser.tests : foo ; TUPLE: foo ;"
339 <string-reader> "redefining-a-class-4" parse-stream drop
340 ] [ error>> error>> error>> redefine-error? ] must-fail-with
343 "IN: parser.tests : foo ( x y -- z ) 1 2 ; : bar ( a -- b ) ;" eval
347 "IN: parser.tests : foo ( x y -- z) 1 2 ; : bar ( a -- b ) ;" eval
352 "IN: parser.tests USE: kernel PREDICATE: foo < object ( x -- y ) ;" eval
356 "foo?" "parser.tests" lookup word eq?
361 "redefining-a-class-5" forget-source
362 "redefining-a-class-6" forget-source
363 "redefining-a-class-7" forget-source
364 ] with-compilation-unit
369 "IN: parser.tests TUPLE: foo ; GENERIC: foo"
370 <string-reader> "redefining-a-class-5" parse-stream drop
374 "IN: parser.tests M: f foo ;"
375 <string-reader> "redefining-a-class-6" parse-stream drop
378 [ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
381 "IN: parser.tests TUPLE: foo ; GENERIC: foo"
382 <string-reader> "redefining-a-class-5" parse-stream drop
385 [ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
388 "IN: parser.tests TUPLE: foo ; GENERIC: foo"
389 <string-reader> "redefining-a-class-7" parse-stream drop
392 [ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
395 "IN: parser.tests TUPLE: foo ;"
396 <string-reader> "redefining-a-class-7" parse-stream drop
399 [ t ] [ "foo" "parser.tests" lookup symbol? ] unit-test
402 [ "resource:core/parser/test/assert-depth.factor" run-file ]
403 [ stack>> { 1 2 3 } sequence= ]
408 "IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
409 <string-reader> "d-f-s-test" parse-stream drop
413 "IN: parser.tests DEFER: d-f-s d-f-s FORGET: d-f-s SYMBOL: d-f-s d-f-s"
414 <string-reader> "d-f-s-test" parse-stream drop
418 "IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
419 <string-reader> "d-f-s-test" parse-stream drop
424 [ "this-better-not-exist" forget-vocab ] with-compilation-unit
428 "USE: this-better-not-exist" eval
431 [ ": foo ;" eval ] [ error>> no-current-vocab? ] must-fail-with
433 [ 92 ] [ "CHAR: \\" eval ] unit-test
434 [ 92 ] [ "CHAR: \\\\" eval ] unit-test
439 "USING: math arrays ;"
440 "GENERIC: change-combination"
441 "M: integer change-combination 1 ;"
442 "M: array change-combination 2 ;"
443 } "\n" join <string-reader> "change-combination-test" parse-stream drop
449 "USING: math arrays ;"
450 "GENERIC# change-combination 1"
451 "M: integer change-combination 1 ;"
452 "M: array change-combination 2 ;"
453 } "\n" join <string-reader> "change-combination-test" parse-stream drop
457 "change-combination" "parser.tests" lookup
458 "methods" word-prop assoc-size
463 "IN: parser.tests DEFER: twice-fails FORGET: twice-fails MIXIN: twice-fails"
464 <string-reader> "twice-fails-test" parse-stream drop
469 "IN: parser.tests : staging-problem-test-1 1 ; : staging-problem-test-2 staging-problem-test-1 ;"
470 <string-reader> "staging-problem-test" parse-stream
473 [ t ] [ "staging-problem-test-1" "parser.tests" lookup >boolean ] unit-test
475 [ t ] [ "staging-problem-test-2" "parser.tests" lookup >boolean ] unit-test
478 "IN: parser.tests << : staging-problem-test-1 1 ; >> : staging-problem-test-2 staging-problem-test-1 ;"
479 <string-reader> "staging-problem-test" parse-stream
482 [ t ] [ "staging-problem-test-1" "parser.tests" lookup >boolean ] unit-test
484 [ t ] [ "staging-problem-test-2" "parser.tests" lookup >boolean ] unit-test
486 [ "DEFER: blah" eval ] [ error>> no-current-vocab? ] must-fail-with
489 "IN: parser.tests : blah ; parsing FORGET: blah" eval
491 error>> staging-violation?