]> gitweb.factorcode.org Git - factor.git/blob - library/test/reader.factor
5c8bbb677b10505118d61786ab155cfc2d657890
[factor.git] / library / test / reader.factor
1 IN: scratchpad
2 USE: parser
3 USE: stdio
4 USE: test
5 USE: unparser
6
7 "Reader tests" print
8
9 ![ [ one [ two [ three ] four ] five ] ]
10 ![ "one [ two [ three ] four ] five" ]
11 ![ parse ]
12 !test-word
13
14 [ [ 1 [ 2 [ 3 ] 4 ] 5 ] ]
15 [ "1\n[\n2\n[\n3\n]\n4\n]\n5" ]
16 [ parse ]
17 test-word
18
19 [ [ t t f f ] ]
20 [ "t t f f" ]
21 [ parse ]
22 test-word
23
24 ![ [ "hello world" ] ]
25 ![ "\"hello world\"" ]
26 ![ parse ]
27 !test-word
28
29 [ [ "\n\r\t\\" ] ]
30 [ "\"\\n\\r\\t\\\\\"" ]
31 [ parse ]
32 test-word
33
34 ![ [ "hello\nworld" x y z ] ]
35 ![ "\"hello\\nworld\" x y z" ]
36 ![ parse ]
37 !test-word
38
39 [ "hello world" ]
40 [ "IN: scratchpad : hello \"hello world\" ;" ]
41 [ parse call "USE: scratchpad hello" eval ]
42 test-word
43
44 [ 1 2 ]
45 [ "IN: scratchpad ~<< my-swap a b -- b a >>~" ]
46 [ parse call 2 1 "USE: scratchpad my-swap" eval ]
47 test-word
48
49 [ ]
50 [ "! This is a comment, people." ]
51 [ parse call ]
52 test-word
53
54 [ ]
55 [ "( This is a comment, people. )" ]
56 [ parse call ]
57 test-word
58
59 [ "\"hello\\\\backslash\"" ]
60 [ "hello\\backslash" ]
61 [ unparse ]
62 test-word
63
64 ! Make sure parseObject() preserves doc comments.
65 [ "( this is a comment )\n" ]
66 [ "( this is a comment )" ]
67 [
68     interpreter
69     [ "java.lang.String" "factor.FactorInterpreter" ]
70     "factor.FactorReader" "parseObject"
71     jinvoke-static
72     unparse
73 ] test-word
74
75 ! Test escapes
76
77 [ [ " " ] ]
78 [ "\"\\u0020\"" ]
79 [ parse ]
80 test-word
81
82 [ [ "'" ] ]
83 [ "\"\\u0027\"" ]
84 [ parse ]
85 test-word
86
87 [ "\"\\u1234\"" ]
88 [ "\u1234" ]
89 [ unparse ]
90 test-word
91
92 [ "\"\\e\"" ]
93 [ "\e" ]
94 [ unparse ]
95 test-word
96
97 "Reader tests done" print