18 "Namespace tests." print
20 [ t ] [ global [ "global" get ] bind global ] [ = ] test-word
21 [ [ 1 0 0 0 ] ] [ [ >n ] ] [ balance>list ] test-word
22 [ [ 1 1 0 0 ] ] [ [ get ] ] [ balance>list ] test-word
23 [ [ 2 0 0 0 ] ] [ [ set ] ] [ balance>list ] test-word
24 [ [ 0 1 0 0 ] ] [ [ namestack* ] ] [ balance>list ] test-word
25 [ [ 0 1 0 0 ] ] [ [ namestack ] ] [ balance>list ] test-word
26 [ [ 1 0 0 0 ] ] [ [ set-namestack* ] ] [ balance>list ] test-word
27 [ [ 1 0 0 0 ] ] [ [ set-namestack ] ] [ balance>list ] test-word
28 [ [ 0 1 0 0 ] ] [ [ n> ] ] [ balance>list ] test-word
30 <namespace> "test-namespace" set
32 : test-namespace ( -- )
33 <namespace> dup [ namespace = ] bind ;
36 <namespace> dup [ this = ] bind ;
39 interpreter dup [ this = ] bind ;
41 [ t ] [ ] [ test-namespace ] test-word
42 [ t ] [ ] [ test-this-1 ] test-word
43 [ t ] [ ] [ test-this-2 ] test-word
45 ! These stress-test a lot of code.
47 "vocabularies" get describe
49 : namespace-compile ( x -- x )
50 <namespace> [ "x" set ] extend [ "x" get ] bind ; word must-compile
52 [ 12 ] [ 12 ] [ namespace-compile ] test-word
54 ! A compiler bug in tailcalls that manifests with the namestack
56 : namespace-tail-call-bug ( x -- x )
60 pred <namespace> [ dup "x" set namespace-tail-call-bug ] bind
61 ] ifte ; word must-compile
63 [ f ] [ ] [ 10 namespace-tail-call-bug "x" get 0 = ] test-word
65 ! Object paths should not resolve further up in the namestack.
67 <namespace> "test-namespace" set
69 [ [ "test-namespace" "test-namespace" ] ]
74 [ [ "alalal" "boobobo" "bah" ] ]
84 [ "test-word" intern [ "global" "vocabularies" "test" "test-word" ] ]
91 [ <namespace> [ f "some-global" set "some-global" get ] bind ]
94 ! I did a n> in extend and forgot the obvious case
95 [ t ] [ "dup" intern dup ] [ [ ] extend = ] test-word
97 "Namespace tests passed." print