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
6 vocabs.parser words.symbol ;
13 [ "1\n[\n2\n[\n3\n]\n4\n]\n5" eval ]
21 [ "\"hello world\"" eval ]
25 [ "\"\\n\\r\\t\\\\\"" eval ]
30 "IN: parser.tests : hello \"hello world\" ;"
31 eval "USE: parser.tests hello" eval
35 [ "! This is a comment, people." eval ]
41 [ "\"\\u000020\"" eval ]
45 [ "\"\\u000027\"" eval ]
48 ! Test EOL comments in multiline strings.
49 [ "Hello" ] [ "#! This calls until-eol.\n\"Hello\"" eval ] unit-test
51 [ word ] [ \ f class ] unit-test
53 ! Test stack effect parsing
55 : effect-parsing-test ( a b -- c ) + ;
58 "effect-parsing-test" "parser.tests" lookup
59 \ effect-parsing-test eq?
62 [ T{ effect f { "a" "b" } { "c" } f } ]
63 [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
65 : baz ( a b -- * ) 2array throw ;
68 [ \ baz "declared-effect" word-prop terminated?>> ]
71 [ ] [ "IN: parser.tests USE: math : effect-parsing-test ( a b -- d ) - ;" eval ] unit-test
74 "effect-parsing-test" "parser.tests" lookup
75 \ effect-parsing-test eq?
78 [ T{ effect f { "a" "b" } { "d" } f } ]
79 [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
81 [ ] [ "IN: parser.tests : effect-parsing-test ;" eval ] unit-test
83 [ f ] [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
86 [ 2 ] [ "IN: parser.tests : \0. 2 ; \0." eval ] unit-test
88 [ "IN: parser.tests : missing-- ( a b ) ;" eval ] must-fail
90 ! These should throw errors
91 [ "HEX: zzz" eval ] must-fail
92 [ "OCT: 999" eval ] must-fail
93 [ "BIN: --0" eval ] must-fail
99 { "scratchpad" "arrays" } set-use
101 ! This shouldn't modify in/use in the outer scope!
104 use get { "scratchpad" "arrays" } set-use use get =
109 "IN: parser.tests USING: math prettyprint ; : foo 2 2 + . ; parsing" eval
111 [ ] [ "USE: parser.tests foo" eval ] unit-test
113 "IN: parser.tests USING: math prettyprint ; : foo 2 2 + . ;" eval
116 "USE: parser.tests \\ foo" eval
117 "foo" "parser.tests" lookup eq?
123 "IN: parser.tests : smudge-me ;" <string-reader> "foo"
126 "foo" source-file definitions>> first assoc-size
129 [ t ] [ "smudge-me" "parser.tests" lookup >boolean ] unit-test
132 "IN: parser.tests : smudge-me-more ;" <string-reader> "foo"
136 [ t ] [ "smudge-me-more" "parser.tests" lookup >boolean ] unit-test
137 [ f ] [ "smudge-me" "parser.tests" lookup >boolean ] unit-test
140 "IN: parser.tests USING: math strings ; GENERIC: smudge-me M: integer smudge-me ; M: string smudge-me ;" <string-reader> "foo"
143 "foo" source-file definitions>> first assoc-size
147 "IN: parser.tests USING: arrays ; M: array smudge-me ;" <string-reader> "bar"
150 "bar" source-file definitions>> first assoc-size
154 "IN: parser.tests USING: math strings ; GENERIC: smudge-me M: integer smudge-me ;" <string-reader> "foo"
157 "foo" source-file definitions>> first assoc-size
161 array "smudge-me" "parser.tests" lookup order memq?
165 integer "smudge-me" "parser.tests" lookup order memq?
169 string "smudge-me" "parser.tests" lookup order memq?
173 "IN: parser.tests USE: math 2 2 +" <string-reader> "a"
178 "a" <pathname> \ + usage member?
182 "IN: parser.tests USE: math 2 2 -" <string-reader> "a"
187 "a" <pathname> \ + usage member?
191 "a" source-files get delete-at
193 "IN: parser.tests DEFER: x : y x ; : x y ;"
194 <string-reader> "a" parse-stream drop
198 "a" source-files get delete-at
201 "IN: parser.tests : x ; : y 3 throw ; this is an error"
202 <string-reader> "a" parse-stream
203 ] [ source-file-error? ] must-fail-with
206 "y" "parser.tests" lookup >boolean
210 "IN: parser.tests : x ;"
211 <string-reader> "a" parse-stream drop
213 "y" "parser.tests" lookup
216 ! Test new forward definition logic
219 <string-reader> "axx" parse-stream drop
223 "USE: axx IN: bxx : bxx ; : cxx axx bxx ;"
224 <string-reader> "bxx" parse-stream drop
227 ! So we move the bxx word to axx...
229 "IN: axx : axx ; : bxx ;"
230 <string-reader> "axx" parse-stream drop
233 [ t ] [ "bxx" "axx" lookup >boolean ] unit-test
235 ! And reload the file that uses it...
237 "USE: axx IN: bxx : cxx axx bxx ;"
238 <string-reader> "bxx" parse-stream drop
241 ! And hope not to get a forward-error!
243 ! Turning a generic into a non-generic could cause all
246 "IN: ayy USE: kernel GENERIC: ayy M: object ayy ;"
247 <string-reader> "ayy" parse-stream drop
251 "IN: ayy USE: kernel : ayy ;"
252 <string-reader> "ayy" parse-stream drop
256 "IN: azz TUPLE: my-class ; GENERIC: a-generic"
257 <string-reader> "azz" parse-stream drop
261 "USE: azz M: my-class a-generic ;"
262 <string-reader> "azz-2" parse-stream drop
266 "IN: azz GENERIC: a-generic"
267 <string-reader> "azz" parse-stream drop
271 "USE: azz USE: math M: integer a-generic ;"
272 <string-reader> "azz-2" parse-stream drop
276 "IN: parser.tests : <bogus-error> ; : bogus <bogus-error> ;"
277 <string-reader> "bogus-error" parse-stream drop
281 "IN: parser.tests TUPLE: bogus-error ; C: <bogus-error> bogus-error : bogus <bogus-error> ;"
282 <string-reader> "bogus-error" parse-stream drop
285 ! Problems with class predicates -vs- ordinary words
287 "IN: parser.tests TUPLE: killer ;"
288 <string-reader> "removing-the-predicate" parse-stream drop
292 "IN: parser.tests GENERIC: killer? ( a -- b )"
293 <string-reader> "removing-the-predicate" parse-stream drop
297 "killer?" "parser.tests" lookup >boolean
301 "IN: parser.tests TUPLE: another-pred-test ; GENERIC: another-pred-test?"
302 <string-reader> "removing-the-predicate" parse-stream
303 ] [ error>> error>> error>> redefine-error? ] must-fail-with
306 "IN: parser.tests TUPLE: class-redef-test ; TUPLE: class-redef-test ;"
307 <string-reader> "redefining-a-class-1" parse-stream
308 ] [ error>> error>> error>> redefine-error? ] must-fail-with
311 "IN: parser.tests TUPLE: class-redef-test ; SYMBOL: class-redef-test"
312 <string-reader> "redefining-a-class-2" parse-stream drop
316 "IN: parser.tests TUPLE: class-redef-test ; SYMBOL: class-redef-test : class-redef-test ;"
317 <string-reader> "redefining-a-class-3" parse-stream drop
318 ] [ error>> error>> error>> redefine-error? ] must-fail-with
321 "IN: parser.tests TUPLE: class-fwd-test ;"
322 <string-reader> "redefining-a-class-3" parse-stream drop
326 "IN: parser.tests \\ class-fwd-test"
327 <string-reader> "redefining-a-class-3" parse-stream drop
328 ] [ error>> error>> error>> no-word-error? ] must-fail-with
331 "IN: parser.tests TUPLE: class-fwd-test ; SYMBOL: class-fwd-test"
332 <string-reader> "redefining-a-class-3" parse-stream drop
336 "IN: parser.tests \\ class-fwd-test"
337 <string-reader> "redefining-a-class-3" parse-stream drop
338 ] [ error>> error>> error>> no-word-error? ] must-fail-with
341 "IN: parser.tests : foo ; TUPLE: foo ;"
342 <string-reader> "redefining-a-class-4" parse-stream drop
343 ] [ error>> error>> error>> redefine-error? ] must-fail-with
346 "IN: parser.tests : foo ( x y -- z ) 1 2 ; : bar ( a -- b ) ;" eval
350 "IN: parser.tests : foo ( x y -- z) 1 2 ; : bar ( a -- b ) ;" eval
355 "IN: parser.tests USE: kernel PREDICATE: foo < object ( x -- y ) ;" eval
359 "foo?" "parser.tests" lookup word eq?
364 "redefining-a-class-5" forget-source
365 "redefining-a-class-6" forget-source
366 "redefining-a-class-7" forget-source
367 ] with-compilation-unit
372 "IN: parser.tests TUPLE: foo ; GENERIC: foo"
373 <string-reader> "redefining-a-class-5" parse-stream drop
377 "IN: parser.tests M: f foo ;"
378 <string-reader> "redefining-a-class-6" parse-stream drop
381 [ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
384 "IN: parser.tests TUPLE: foo ; GENERIC: foo"
385 <string-reader> "redefining-a-class-5" parse-stream drop
388 [ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
391 "IN: parser.tests TUPLE: foo ; GENERIC: foo"
392 <string-reader> "redefining-a-class-7" parse-stream drop
395 [ f ] [ f "foo" "parser.tests" lookup execute ] unit-test
398 "IN: parser.tests TUPLE: foo ;"
399 <string-reader> "redefining-a-class-7" parse-stream drop
402 [ t ] [ "foo" "parser.tests" lookup symbol? ] unit-test
405 [ "resource:core/parser/test/assert-depth.factor" run-file ]
406 [ got>> { 1 2 3 } sequence= ]
411 "IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
412 <string-reader> "d-f-s-test" parse-stream drop
416 "IN: parser.tests DEFER: d-f-s d-f-s FORGET: d-f-s SYMBOL: d-f-s d-f-s"
417 <string-reader> "d-f-s-test" parse-stream drop
421 "IN: parser.tests DEFER: d-f-s d-f-s SYMBOL: d-f-s d-f-s"
422 <string-reader> "d-f-s-test" parse-stream drop
427 [ "this-better-not-exist" forget-vocab ] with-compilation-unit
431 "USE: this-better-not-exist" eval
434 [ ": foo ;" eval ] [ error>> error>> no-current-vocab? ] must-fail-with
436 [ 92 ] [ "CHAR: \\" eval ] unit-test
437 [ 92 ] [ "CHAR: \\\\" eval ] unit-test
442 "USING: math arrays ;"
443 "GENERIC: change-combination"
444 "M: integer change-combination 1 ;"
445 "M: array change-combination 2 ;"
446 } "\n" join <string-reader> "change-combination-test" parse-stream drop
452 "USING: math arrays ;"
453 "GENERIC# change-combination 1"
454 "M: integer change-combination 1 ;"
455 "M: array change-combination 2 ;"
456 } "\n" join <string-reader> "change-combination-test" parse-stream drop
460 "change-combination" "parser.tests" lookup
461 "methods" word-prop assoc-size
466 "IN: parser.tests DEFER: twice-fails FORGET: twice-fails MIXIN: twice-fails"
467 <string-reader> "twice-fails-test" parse-stream drop
472 "IN: parser.tests : staging-problem-test-1 1 ; : staging-problem-test-2 staging-problem-test-1 ;"
473 <string-reader> "staging-problem-test" parse-stream
476 [ t ] [ "staging-problem-test-1" "parser.tests" lookup >boolean ] unit-test
478 [ t ] [ "staging-problem-test-2" "parser.tests" lookup >boolean ] unit-test
481 "IN: parser.tests << : staging-problem-test-1 1 ; >> : staging-problem-test-2 staging-problem-test-1 ;"
482 <string-reader> "staging-problem-test" parse-stream
485 [ t ] [ "staging-problem-test-1" "parser.tests" lookup >boolean ] unit-test
487 [ t ] [ "staging-problem-test-2" "parser.tests" lookup >boolean ] unit-test
489 [ "DEFER: blahy" eval ] [ error>> error>> no-current-vocab? ] must-fail-with
492 "IN: parser.tests : blahy ; parsing FORGET: blahy" eval
494 error>> staging-violation?
497 ! Bogus error message
500 [ "IN: parser.tests USE: kernel TUPLE: blahy < tuple ; : blahy ; TUPLE: blahy < tuple ; : blahy ;" eval ]
501 [ error>> error>> def>> \ blahy eq? ] must-fail-with
503 [ ] [ f lexer set f file set "Hello world" note. ] unit-test
505 [ "CHAR: \\u9999999999999" eval ] must-fail
509 [ a ] [ a ] unit-test
510 [ b ] [ b ] unit-test
511 [ c ] [ c ] unit-test
515 [ ] [ "IN: parser.tests GENERIC: blah" eval ] unit-test
516 [ ] [ "IN: parser.tests SYMBOLS: blah ;" eval ] unit-test
518 [ f ] [ \ blah generic? ] unit-test
519 [ t ] [ \ blah symbol? ] unit-test
523 [ "IN: parser.tests SINGLETONS: blah1 blah1 blah1 ;" eval ]
524 [ error>> error>> def>> \ blah1 eq? ]
527 IN: qualified.tests.foo
530 IN: qualified.tests.bar
533 IN: qualified.tests.baz
536 QUALIFIED: qualified.tests.foo
537 QUALIFIED: qualified.tests.bar
538 [ 1 2 3 ] [ qualified.tests.foo:x qualified.tests.bar:x x ] unit-test
540 QUALIFIED-WITH: qualified.tests.bar p
541 [ 2 ] [ p:x ] unit-test
543 RENAME: x qualified.tests.baz => y
544 [ 3 ] [ y ] unit-test
546 FROM: qualified.tests.baz => x ;
547 [ 3 ] [ x ] unit-test
548 [ 3 ] [ y ] unit-test
550 EXCLUDE: qualified.tests.bar => x ;
551 [ 3 ] [ x ] unit-test
552 [ 4 ] [ y ] unit-test
554 [ "IN: qualified.tests FROM: qualified.tests => doesnotexist ;" eval ]
555 [ error>> no-word-error? ] must-fail-with
557 [ "IN: qualified.tests RENAME: doesnotexist qualified.tests => blahx" eval ]
558 [ error>> no-word-error? ] must-fail-with