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
11 [ 0 "abcd" next-char ] unit-test
14 [ 1 "\\u0020hello" next-escape ] unit-test
17 [ 1 "\\nhello" next-escape ] unit-test
20 [ 0 "\\u0020hello" next-char ] unit-test
22 [ [ 1 [ 2 [ 3 ] 4 ] 5 ] ]
23 [ "1\n[\n2\n[\n3\n]\n4\n]\n5" parse ]
31 [ "\"hello world\"" parse ]
35 [ "\"\\n\\r\\t\\\\\"" parse ]
40 "IN: temporary : hello \"hello world\" ;"
41 parse call "USE: scratchpad hello" eval
45 [ "! This is a comment, people." parse call ]
51 [ "\"\\u0020\"" parse ]
55 [ "\"\\u0027\"" parse ]
58 [ "\\u123" parse ] unit-test-fails
60 ! Test EOL comments in multiline strings.
61 [ [ "Hello" ] ] [ "#! This calls until-eol.\n\"Hello\"" parse ] unit-test
63 [ word ] [ \ f class ] unit-test
65 ! Test stack effect parsing
67 : effect-parsing-test ( a b -- c ) + ;
70 "effect-parsing-test" "temporary" lookup
71 \ effect-parsing-test eq?
74 [ T{ effect f { "a" "b" } { "c" } f } ]
75 [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
77 : baz ( a b -- * ) 2array throw ;
80 [ \ baz "declared-effect" word-prop effect-terminated? ]
83 [ [ ] ] [ "IN: temporary USE: math : effect-parsing-test ( a b -- d ) - ;" parse ] unit-test
86 "effect-parsing-test" "temporary" lookup
87 \ effect-parsing-test eq?
90 [ T{ effect f { "a" "b" } { "d" } f } ]
91 [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
93 [ [ ] ] [ "IN: temporary : effect-parsing-test ;" parse ] unit-test
95 [ f ] [ \ effect-parsing-test "declared-effect" word-prop ] unit-test
98 [ 2 ] [ "IN: temporary : \0. 2 ; \0." eval ] unit-test
100 [ "IN: temporary : missing-- ( a b ) ;" eval ] unit-test-fails
102 ! These should throw errors
103 [ "HEX: zzz" parse ] unit-test-fails
104 [ "OCT: 999" parse ] unit-test-fails
105 [ "BIN: --0" parse ] unit-test-fails
108 "IN: temporary : foo ; TUPLE: foo ;" parse drop
109 "foo" "temporary" lookup symbol?
116 { "scratchpad" "arrays" } set-use
118 ! This shouldn't modify in/use in the outer scope!
122 use get { "scratchpad" "arrays" } set-use use get =
127 "IN: temporary USING: math prettyprint ; : foo 2 2 + . ; parsing" eval
129 [ [ ] ] [ "USE: temporary foo" parse ] unit-test
131 "IN: temporary USING: math prettyprint ; : foo 2 2 + . ;" eval
134 "USE: temporary foo" parse
135 first "foo" "temporary" lookup eq?
141 "IN: temporary : smudge-me ;" <string-reader> "foo"
144 "foo" source-file source-file-definitions assoc-size
147 [ t ] [ "smudge-me" "temporary" lookup >boolean ] unit-test
150 "IN: temporary : smudge-me-more ;" <string-reader> "foo"
154 [ t ] [ "smudge-me-more" "temporary" lookup >boolean ] unit-test
155 [ f ] [ "smudge-me" "temporary" lookup >boolean ] unit-test
158 "IN: temporary USING: math strings ; GENERIC: smudge-me M: integer smudge-me ; M: string smudge-me ;" <string-reader> "foo"
161 "foo" source-file source-file-definitions assoc-size
165 "IN: temporary USING: arrays ; M: array smudge-me ;" <string-reader> "bar"
168 "bar" source-file source-file-definitions assoc-size
172 "IN: temporary USING: math strings ; GENERIC: smudge-me M: integer smudge-me ;" <string-reader> "foo"
175 "foo" source-file source-file-definitions assoc-size
179 array "smudge-me" "temporary" lookup order memq?
183 integer "smudge-me" "temporary" lookup order memq?
187 string "smudge-me" "temporary" lookup order memq?
191 "IN: temporary USE: math 2 2 +" <string-reader> "a"
196 "a" <pathname> \ + usage member?
200 "IN: temporary USE: math 2 2 -" <string-reader> "a"
205 "a" <pathname> \ + usage member?
209 "a" source-files get delete-at
211 "IN: temporary DEFER: x : y x ; : x y ;"
212 <string-reader> "a" parse-stream drop
216 "a" source-files get delete-at
220 "IN: temporary : x ; : y 3 throw ; parsing y"
221 <string-reader> "a" parse-stream
226 "y" "temporary" lookup >boolean
230 "IN: temporary : x ;"
231 <string-reader> "a" parse-stream drop
233 "y" "temporary" lookup
236 ! Test new forward definition logic
239 <string-reader> "axx" parse-stream drop
243 "USE: axx IN: bxx : bxx ; : cxx axx bxx ;"
244 <string-reader> "bxx" parse-stream drop
247 ! So we move the bxx word to axx...
249 "IN: axx : axx ; : bxx ;"
250 <string-reader> "axx" parse-stream drop
253 [ t ] [ "bxx" "axx" lookup >boolean ] unit-test
255 ! And reload the file that uses it...
257 "USE: axx IN: bxx : cxx axx bxx ;"
258 <string-reader> "bxx" parse-stream drop
261 ! And hope not to get a forward-error!
263 ! Turning a generic into a non-generic could cause all
266 "IN: ayy USE: kernel GENERIC: ayy M: object ayy ;"
267 <string-reader> "ayy" parse-stream drop
271 "IN: ayy USE: kernel : ayy ;"
272 <string-reader> "ayy" parse-stream drop
276 "IN: azz TUPLE: my-class ; GENERIC: a-generic"
277 <string-reader> "azz" parse-stream drop
281 "USE: azz M: my-class a-generic ;"
282 <string-reader> "azz-2" parse-stream drop
286 "IN: azz GENERIC: a-generic"
287 <string-reader> "azz" parse-stream drop
291 "USE: azz USE: math M: integer a-generic ;"
292 <string-reader> "azz-2" parse-stream drop
296 "IN: temporary : <bogus-error> ; : bogus <bogus-error> ;"
297 <string-reader> "bogus-error" parse-stream drop
301 "IN: temporary TUPLE: bogus-error ; C: <bogus-error> bogus-error : bogus <bogus-error> ;"
302 <string-reader> "bogus-error" parse-stream drop
305 ! Problems with class predicates -vs- ordinary words
307 "IN: temporary TUPLE: killer ;"
308 <string-reader> "removing-the-predicate" parse-stream drop
312 "IN: temporary GENERIC: killer?"
313 <string-reader> "removing-the-predicate" parse-stream drop
317 "killer?" "temporary" lookup >boolean
322 "IN: temporary TUPLE: another-pred-test ; GENERIC: another-pred-test?"
323 <string-reader> "removing-the-predicate" parse-stream
324 ] catch [ redefine-error? ] is?
329 : FILE file get parsed ; parsing
338 H{ { ~a ~a } { ~c ~c } { ~d ~d } } old-definitions set
340 H{ { ~d ~d } } new-definitions set
342 [ V{ ~b } { ~a } { ~a ~c } ] [