ParseTree 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +15 -0
- data/Makefile +25 -0
- data/Manifest.txt +14 -0
- data/README.txt +104 -0
- data/composite_sexp_processor.rb +24 -0
- data/parse_tree.rb +545 -0
- data/parse_tree_abc +62 -0
- data/parse_tree_show +28 -0
- data/sexp_processor.rb +301 -0
- data/something.rb +162 -0
- data/test_all.rb +7 -0
- data/test_composite_sexp_processor.rb +69 -0
- data/test_parse_tree.rb +275 -0
- data/test_sexp_processor.rb +382 -0
- metadata +55 -0
data/test_all.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
$TESTING = true
|
4
|
+
|
5
|
+
require 'composite_sexp_processor'
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
class FakeProcessor1 < SexpProcessor # ZenTest SKIP
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
self.warn_on_default = false
|
13
|
+
self.default_method = :default_processor
|
14
|
+
self.expected = Array
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_processor(exp)
|
18
|
+
result = []
|
19
|
+
until exp.empty? do
|
20
|
+
result << exp.shift.to_s + " woot"
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class TestCompositeSexpProcessor < Test::Unit::TestCase
|
27
|
+
|
28
|
+
def setup
|
29
|
+
@p = CompositeSexpProcessor.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_process_default
|
33
|
+
data = [1, 2, 3]
|
34
|
+
result = @p.process(data.dup)
|
35
|
+
assert_equal(data.dup, result)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_process_fake1
|
39
|
+
data = [1, 2, 3]
|
40
|
+
@p << FakeProcessor1.new
|
41
|
+
result = @p.process(data.dup)
|
42
|
+
assert_equal(data.map {|x| "#{x} woot"}, result)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_process_fake1_twice
|
46
|
+
data = [1, 2, 3]
|
47
|
+
@p << FakeProcessor1.new
|
48
|
+
@p << FakeProcessor1.new
|
49
|
+
result = @p.process(data.dup)
|
50
|
+
assert_equal(data.map {|x| "#{x} woot woot"}, result)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_processors
|
54
|
+
# everything is tested by test_append
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_append
|
58
|
+
assert_equal([], @p.processors)
|
59
|
+
|
60
|
+
assert_raises(ArgumentError) do
|
61
|
+
@p << 42
|
62
|
+
end
|
63
|
+
|
64
|
+
fp1 = FakeProcessor1.new
|
65
|
+
@p << fp1
|
66
|
+
assert_equal([fp1], @p.processors)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/test_parse_tree.rb
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'parse_tree'
|
5
|
+
require 'something'
|
6
|
+
|
7
|
+
class TestParseTree < Test::Unit::TestCase
|
8
|
+
|
9
|
+
# TODO: need a test of interpolated strings
|
10
|
+
|
11
|
+
@@missing = [nil]
|
12
|
+
@@empty = [:defn, "empty",
|
13
|
+
[:scope,
|
14
|
+
[:args]]]
|
15
|
+
@@stupid = [:defn, "stupid",
|
16
|
+
[:scope,
|
17
|
+
[:block,
|
18
|
+
[:args],
|
19
|
+
[:return, [:nil]]]]]
|
20
|
+
@@simple = [:defn, "simple",
|
21
|
+
[:scope,
|
22
|
+
[:block,
|
23
|
+
[:args, "arg1"],
|
24
|
+
[:fcall, "print",
|
25
|
+
[:array, [:lvar, "arg1"]]],
|
26
|
+
[:fcall, "puts",
|
27
|
+
[:array,
|
28
|
+
[:call,
|
29
|
+
[:call,
|
30
|
+
[:lit, 4],
|
31
|
+
"+",
|
32
|
+
[:array, [:lit, 2]]],
|
33
|
+
"to_s"]]]]]]
|
34
|
+
@@global = [:defn, "global",
|
35
|
+
[:scope,
|
36
|
+
[:block,
|
37
|
+
[:args],
|
38
|
+
[:call,
|
39
|
+
[:gvar, "$stderr"],
|
40
|
+
"fputs",
|
41
|
+
[:array, [:str, "blah"]]]]]]
|
42
|
+
@@lasgn_call = [:defn, "lasgn_call",
|
43
|
+
[:scope,
|
44
|
+
[:block,
|
45
|
+
[:args],
|
46
|
+
[:lasgn, "c",
|
47
|
+
[:call,
|
48
|
+
[:lit, 2],
|
49
|
+
"+",
|
50
|
+
[:array, [:lit, 3]]]]]]]
|
51
|
+
@@conditional1 = [:defn, "conditional1",
|
52
|
+
[:scope,
|
53
|
+
[:block,
|
54
|
+
[:args, "arg1"],
|
55
|
+
[:if,
|
56
|
+
[:call,
|
57
|
+
[:lvar, "arg1"],
|
58
|
+
"==",
|
59
|
+
[:array, [:lit, 0]]],
|
60
|
+
[:return,
|
61
|
+
[:lit, 1]], nil]]]]
|
62
|
+
@@conditional2 = [:defn, "conditional2",
|
63
|
+
[:scope,
|
64
|
+
[:block,
|
65
|
+
[:args, "arg1"],
|
66
|
+
[:if,
|
67
|
+
[:call,
|
68
|
+
[:lvar, "arg1"],
|
69
|
+
"==",
|
70
|
+
[:array, [:lit, 0]]], nil,
|
71
|
+
[:return,
|
72
|
+
[:lit, 2]]]]]]
|
73
|
+
@@conditional3 = [:defn, "conditional3",
|
74
|
+
[:scope,
|
75
|
+
[:block,
|
76
|
+
[:args, "arg1"],
|
77
|
+
[:if,
|
78
|
+
[:call,
|
79
|
+
[:lvar, "arg1"],
|
80
|
+
"==",
|
81
|
+
[:array, [:lit, 0]]],
|
82
|
+
[:return,
|
83
|
+
[:lit, 3]],
|
84
|
+
[:return,
|
85
|
+
[:lit, 4]]]]]]
|
86
|
+
@@conditional4 = [:defn, "conditional4",
|
87
|
+
[:scope,
|
88
|
+
[:block,
|
89
|
+
[:args, "arg1"],
|
90
|
+
[:if,
|
91
|
+
[:call,
|
92
|
+
[:lvar, "arg1"],
|
93
|
+
"==",
|
94
|
+
[:array, [:lit, 0]]],
|
95
|
+
[:return, [:lit, 2]],
|
96
|
+
[:if,
|
97
|
+
[:call,
|
98
|
+
[:lvar, "arg1"],
|
99
|
+
"<",
|
100
|
+
[:array, [:lit, 0]]],
|
101
|
+
[:return, [:lit, 3]],
|
102
|
+
[:return, [:lit, 4]]]]]]]
|
103
|
+
@@iteration_body = [:scope,
|
104
|
+
[:block,
|
105
|
+
[:args],
|
106
|
+
[:lasgn, "array",
|
107
|
+
[:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
|
108
|
+
[:iter,
|
109
|
+
[:call,
|
110
|
+
[:lvar, "array"], "each"],
|
111
|
+
[:dasgn_curr, "x"],
|
112
|
+
[:fcall, "puts", [:array, [:call, [:dvar, "x"], "to_s"]]]]]]
|
113
|
+
@@iteration1 = [:defn, "iteration1", @@iteration_body]
|
114
|
+
@@iteration2 = [:defn, "iteration2", @@iteration_body]
|
115
|
+
@@iteration3 = [:defn, "iteration3",
|
116
|
+
[:scope,
|
117
|
+
[:block,
|
118
|
+
[:args],
|
119
|
+
[:lasgn, "array1",
|
120
|
+
[:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
|
121
|
+
[:lasgn, "array2",
|
122
|
+
[:array, [:lit, 4], [:lit, 5], [:lit, 6], [:lit, 7]]],
|
123
|
+
[:iter,
|
124
|
+
[:call,
|
125
|
+
[:lvar, "array1"], "each"],
|
126
|
+
[:dasgn_curr, "x"],
|
127
|
+
[:iter,
|
128
|
+
[:call,
|
129
|
+
[:lvar, "array2"], "each"],
|
130
|
+
[:dasgn_curr, "y"],
|
131
|
+
[:block,
|
132
|
+
[:fcall, "puts",
|
133
|
+
[:array, [:call, [:dvar, "x"], "to_s"]]],
|
134
|
+
[:fcall, "puts",
|
135
|
+
[:array, [:call, [:dvar, "y"], "to_s"]]]]]]]]]
|
136
|
+
@@iteration4 = [:defn,
|
137
|
+
"iteration4",
|
138
|
+
[:scope,
|
139
|
+
[:block,
|
140
|
+
[:args],
|
141
|
+
[:iter,
|
142
|
+
[:call, [:lit, 1], "upto", [:array, [:lit, 3]]],
|
143
|
+
[:dasgn_curr, "n"],
|
144
|
+
[:fcall, "puts", [:array, [:call, [:dvar, "n"], "to_s"]]]]]]]
|
145
|
+
@@iteration5 = [:defn,
|
146
|
+
"iteration5",
|
147
|
+
[:scope,
|
148
|
+
[:block,
|
149
|
+
[:args],
|
150
|
+
[:iter,
|
151
|
+
[:call, [:lit, 3], "downto", [:array, [:lit, 1]]],
|
152
|
+
[:dasgn_curr, "n"],
|
153
|
+
[:fcall, "puts", [:array, [:call, [:dvar, "n"], "to_s"]]]]]]]
|
154
|
+
@@iteration6 = [:defn,
|
155
|
+
"iteration6",
|
156
|
+
[:scope,
|
157
|
+
[:block,
|
158
|
+
[:args],
|
159
|
+
[:iter,
|
160
|
+
[:call, [:lit, 3], "downto", [:array, [:lit, 1]]],
|
161
|
+
nil,
|
162
|
+
[:fcall, "puts", [:array, [:str, "hello"]]]]]]]
|
163
|
+
@@multi_args = [:defn, "multi_args",
|
164
|
+
[:scope,
|
165
|
+
[:block,
|
166
|
+
[:args, "arg1", "arg2"],
|
167
|
+
[:lasgn, "arg3",
|
168
|
+
[:call,
|
169
|
+
[:call,
|
170
|
+
[:lvar, "arg1"],
|
171
|
+
"*",
|
172
|
+
[:array, [:lvar, "arg2"]]],
|
173
|
+
"*",
|
174
|
+
[:array, [:lit, 7]]]],
|
175
|
+
[:fcall, "puts", [:array, [:call, [:lvar, "arg3"], "to_s"]]],
|
176
|
+
[:return,
|
177
|
+
[:str, "foo"]]]]]
|
178
|
+
@@bools = [:defn, "bools",
|
179
|
+
[:scope,
|
180
|
+
[:block,
|
181
|
+
[:args, "arg1"],
|
182
|
+
[:if,
|
183
|
+
[:call,
|
184
|
+
[:lvar, "arg1"], "nil?"],
|
185
|
+
[:return,
|
186
|
+
[:false]],
|
187
|
+
[:return,
|
188
|
+
[:true]]]]]]
|
189
|
+
@@case_stmt = [:defn, "case_stmt",
|
190
|
+
[:scope,
|
191
|
+
[:block,
|
192
|
+
[:args],
|
193
|
+
[:lasgn, "var", [:lit, 2]],
|
194
|
+
[:lasgn, "result", [:str, ""]],
|
195
|
+
[:case,
|
196
|
+
[:lvar, "var"],
|
197
|
+
[:when,
|
198
|
+
[:array, [:lit, 1]],
|
199
|
+
[:block,
|
200
|
+
[:fcall, "puts", [:array, [:str, "something"]]],
|
201
|
+
[:lasgn, "result", [:str, "red"]]]],
|
202
|
+
[:when,
|
203
|
+
[:array, [:lit, 2], [:lit, 3]],
|
204
|
+
[:lasgn, "result", [:str, "yellow"]]],
|
205
|
+
[:when, [:array, [:lit, 4]], nil],
|
206
|
+
[:lasgn, "result", [:str, "green"]]],
|
207
|
+
[:case,
|
208
|
+
[:lvar, "result"],
|
209
|
+
[:when, [:array, [:str, "red"]], [:lasgn, "var", [:lit, 1]]],
|
210
|
+
[:when, [:array, [:str, "yellow"]], [:lasgn, "var", [:lit, 2]]],
|
211
|
+
[:when, [:array, [:str, "green"]], [:lasgn, "var", [:lit, 3]]],
|
212
|
+
nil],
|
213
|
+
[:return, [:lvar, "result"]]]]]
|
214
|
+
@@eric_is_stubborn = [:defn,
|
215
|
+
"eric_is_stubborn",
|
216
|
+
[:scope,
|
217
|
+
[:block,
|
218
|
+
[:args],
|
219
|
+
[:lasgn, "var", [:lit, 42]],
|
220
|
+
[:lasgn, "var2", [:call, [:lvar, "var"], "to_s"]],
|
221
|
+
[:call, [:gvar, "$stderr"], "fputs", [:array, [:lvar, "var2"]]],
|
222
|
+
[:return, [:lvar, "var2"]]]]]
|
223
|
+
@@interpolated = [:defn,
|
224
|
+
"interpolated",
|
225
|
+
[:scope,
|
226
|
+
[:block,
|
227
|
+
[:args],
|
228
|
+
[:lasgn, "var", [:lit, 14]],
|
229
|
+
[:lasgn, "var2", [:dstr, "var is ", [:lvar, "var"], [:str, ". So there."]]]]]]
|
230
|
+
@@unknown_args = [:defn, "unknown_args",
|
231
|
+
[:scope,
|
232
|
+
[:block,
|
233
|
+
[:args, "arg1", "arg2"],
|
234
|
+
[:return, [:lvar, "arg1"]]]]]
|
235
|
+
@@determine_args = [:defn, "determine_args",
|
236
|
+
[:scope,
|
237
|
+
[:block,
|
238
|
+
[:args],
|
239
|
+
[:call,
|
240
|
+
[:lit, 5],
|
241
|
+
"==",
|
242
|
+
[:array,
|
243
|
+
[:fcall,
|
244
|
+
"unknown_args",
|
245
|
+
[:array, [:lit, 4], [:str, "known"]]]]]]]]
|
246
|
+
|
247
|
+
@@__all = []
|
248
|
+
|
249
|
+
def setup
|
250
|
+
@thing = ParseTree.new
|
251
|
+
end
|
252
|
+
|
253
|
+
Something.instance_methods(false).sort.each do |meth|
|
254
|
+
if class_variables.include?("@@#{meth}") then
|
255
|
+
@@__all << eval("@@#{meth}")
|
256
|
+
eval "def test_#{meth}; assert_equal @@#{meth}, @thing.parse_tree(Something, :#{meth}); end"
|
257
|
+
else
|
258
|
+
eval "def test_#{meth}; flunk \"You haven't added @@#{meth} yet\"; end"
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_missing
|
263
|
+
assert_equal(@@missing,
|
264
|
+
@thing.parse_tree(Something, :missing),
|
265
|
+
"Must return -3 for missing methods")
|
266
|
+
end
|
267
|
+
|
268
|
+
def ztest_class
|
269
|
+
assert_equal(@@__all,
|
270
|
+
@thing.parse_tree(Something),
|
271
|
+
"Must return a lot of shit")
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
|
@@ -0,0 +1,382 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
$TESTING = true
|
4
|
+
|
5
|
+
require 'sexp_processor'
|
6
|
+
require 'stringio'
|
7
|
+
require 'test/unit'
|
8
|
+
require 'pp'
|
9
|
+
|
10
|
+
# Fake test classes:
|
11
|
+
|
12
|
+
class TestProcessor < SexpProcessor # ZenTest SKIP
|
13
|
+
attr_accessor :auto_shift_type
|
14
|
+
|
15
|
+
def process_acc1(exp)
|
16
|
+
out = self.expected.new(:acc2, exp.thing_three, exp.thing_two, exp.thing_one)
|
17
|
+
exp.clear
|
18
|
+
return out
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_acc2(exp)
|
22
|
+
out = []
|
23
|
+
out << exp.thing_one
|
24
|
+
end
|
25
|
+
|
26
|
+
def process_specific(exp)
|
27
|
+
result = exp[1..-1]
|
28
|
+
exp.clear
|
29
|
+
self.expected.new(*result)
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_strip(exp)
|
33
|
+
result = exp.deep_clone
|
34
|
+
exp.clear
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
def process_nonempty(exp)
|
39
|
+
exp
|
40
|
+
end
|
41
|
+
|
42
|
+
def process_broken(exp)
|
43
|
+
result = [*exp]
|
44
|
+
exp.clear
|
45
|
+
result
|
46
|
+
end
|
47
|
+
|
48
|
+
def process_expected(exp)
|
49
|
+
exp.clear
|
50
|
+
return {}
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_string(exp)
|
54
|
+
return exp.shift
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
class TestProcessorDefault < SexpProcessor # ZenTest SKIP
|
60
|
+
def initialize
|
61
|
+
super
|
62
|
+
self.default_method = :def_method
|
63
|
+
end
|
64
|
+
|
65
|
+
def def_method(exp)
|
66
|
+
exp.clear
|
67
|
+
self.expected.new(42)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Real test classes:
|
72
|
+
|
73
|
+
class TestSexp < Test::Unit::TestCase # ZenTest FULL
|
74
|
+
|
75
|
+
def util_sexp_class
|
76
|
+
Object.const_get(self.class.name[4..-1])
|
77
|
+
end
|
78
|
+
|
79
|
+
def setup
|
80
|
+
@sexp_class = util_sexp_class
|
81
|
+
@processor = SexpProcessor.new
|
82
|
+
@sexp = @sexp_class.new(1, 2, 3)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_new_nested
|
86
|
+
@sexp = Sexp.new(:lasgn, "var", Sexp.new(:str, "foo"))
|
87
|
+
assert_equal('Sexp.new(:lasgn, "var", Sexp.new(:str, "foo"))',
|
88
|
+
@sexp.inspect)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_equals_array
|
92
|
+
# can't use assert_equals because it uses array as receiver
|
93
|
+
assert_not_equal(@sexp, [1, 2, 3],
|
94
|
+
"Sexp must not be equal to equivalent array")
|
95
|
+
# both directions just in case
|
96
|
+
# HACK - not sure why it is failing now that we split out TypedSexp
|
97
|
+
# assert_not_equal([1, 2, 3], @sexp,
|
98
|
+
# "Sexp must not be equal to equivalent array")
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_equals_sexp
|
102
|
+
sexp2 = Sexp.new(1, 2, 3)
|
103
|
+
assert_equal(@sexp, sexp2)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_equals_not_body
|
107
|
+
sexp2 = Sexp.new(1, 2, 5)
|
108
|
+
assert_not_equal(@sexp, sexp2)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_to_a
|
112
|
+
assert_equal([1, 2, 3], @sexp.to_a)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_accessors=
|
116
|
+
a = s(:call, s(:lit, 1), "func", s(:array, s(:lit, 2)))
|
117
|
+
a.accessors = [:lhs, :name, :rhs]
|
118
|
+
|
119
|
+
assert_equal a.accessors, [:lhs, :name, :rhs]
|
120
|
+
|
121
|
+
assert_equal s(:lit, 1), a.lhs
|
122
|
+
assert_equal "func", a.name
|
123
|
+
assert_equal s(:array, s(:lit, 2)), a.rhs
|
124
|
+
|
125
|
+
a.accessors = []
|
126
|
+
|
127
|
+
assert_raises NoMethodError do
|
128
|
+
a.lhs
|
129
|
+
end
|
130
|
+
end
|
131
|
+
def test_accessors; end # handled
|
132
|
+
|
133
|
+
def test_sexp_body
|
134
|
+
assert_equal [2, 3], @sexp.sexp_body
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_array_type?
|
138
|
+
assert_equal false, @sexp.array_type?
|
139
|
+
@sexp.unshift :array
|
140
|
+
assert_equal true, @sexp.array_type?
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_each_of_type
|
144
|
+
# TODO: huh... this tests fails if top level sexp :b is removed
|
145
|
+
@sexp = s(:b, s(:a, s(:b, s(:a), :a, s(:b, :a), s(:b, s(:a)))))
|
146
|
+
count = 0
|
147
|
+
@sexp.each_of_type(:a) do |exp|
|
148
|
+
count += 1
|
149
|
+
end
|
150
|
+
assert_equal(3, count, "must find 3 a's in #{@sexp.inspect}")
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_find_and_replace_all
|
154
|
+
@sexp = s(:a, s(:b, s(:a), s(:b), s(:b, s(:a))))
|
155
|
+
expected = s(:a, s(:a, s(:a), s(:a), s(:a, s(:a))))
|
156
|
+
|
157
|
+
@sexp.find_and_replace_all(:b, :a)
|
158
|
+
|
159
|
+
assert_equal(expected, @sexp)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_inspect
|
163
|
+
k = @sexp_class
|
164
|
+
assert_equal("#{k}.new()",
|
165
|
+
k.new().inspect)
|
166
|
+
assert_equal("#{k}.new(:a)",
|
167
|
+
k.new(:a).inspect)
|
168
|
+
assert_equal("#{k}.new(:a, :b)",
|
169
|
+
k.new(:a, :b).inspect)
|
170
|
+
assert_equal("#{k}.new(:a, #{k}.new(:b))",
|
171
|
+
k.new(:a, k.new(:b)).inspect)
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_to_s
|
175
|
+
test_inspect
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_method_missing
|
179
|
+
assert_raises NoMethodError do
|
180
|
+
@sexp.no_such_method
|
181
|
+
end
|
182
|
+
|
183
|
+
@sexp.accessors = [:its_a_method_now]
|
184
|
+
|
185
|
+
assert_nothing_raised do
|
186
|
+
assert_equal 2, @sexp.its_a_method_now
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def util_pretty_print(expect, input)
|
191
|
+
io = StringIO.new
|
192
|
+
PP.pp(input, io)
|
193
|
+
io.rewind
|
194
|
+
assert_equal(expect, io.read.chomp)
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_pretty_print
|
198
|
+
util_pretty_print("s()",
|
199
|
+
s())
|
200
|
+
util_pretty_print("s(:a)",
|
201
|
+
s(:a))
|
202
|
+
util_pretty_print("s(:a, :b)",
|
203
|
+
s(:a, :b))
|
204
|
+
util_pretty_print("s(:a, s(:b))",
|
205
|
+
s(:a, s(:b)))
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_shift
|
209
|
+
assert_equal(1, @sexp.shift)
|
210
|
+
assert_equal(2, @sexp.shift)
|
211
|
+
assert_equal(3, @sexp.shift)
|
212
|
+
assert_nil(@sexp.shift)
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_unpack_equal
|
216
|
+
assert_equal false, @sexp.unpack
|
217
|
+
@sexp.unpack = true
|
218
|
+
assert_equal true, @sexp.unpack
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_unpack; end # handled
|
222
|
+
def test_unpack_q; end # handled
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
class TestSexpProcessor < Test::Unit::TestCase
|
227
|
+
|
228
|
+
def setup
|
229
|
+
@processor = TestProcessor.new
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_sexp_accessors
|
233
|
+
@processor.sexp_accessors = {
|
234
|
+
:acc1 => [:thing_one, :thing_two, :thing_three]
|
235
|
+
}
|
236
|
+
|
237
|
+
a = s(:acc1, 1, 2, 3)
|
238
|
+
|
239
|
+
assert_equal s(:acc2, 3, 2, 1), @processor.process(a)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_sexp_accessors_reset
|
243
|
+
@processor.sexp_accessors = {
|
244
|
+
:acc1 => [:thing_one, :thing_two, :thing_three]
|
245
|
+
}
|
246
|
+
|
247
|
+
a = s(:acc1, 1, 2, 3)
|
248
|
+
b = @processor.process(a)
|
249
|
+
|
250
|
+
assert_raises NoMethodError do
|
251
|
+
@processor.process(b)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
def test_sexp_accessors=; end # handled
|
255
|
+
|
256
|
+
def test_process_specific
|
257
|
+
a = [:specific, 1, 2, 3]
|
258
|
+
expected = a[1..-1]
|
259
|
+
assert_equal(expected, @processor.process(a))
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_process_general
|
263
|
+
a = [:blah, 1, 2, 3]
|
264
|
+
expected = a.deep_clone
|
265
|
+
assert_equal(expected, @processor.process(a))
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_process_default
|
269
|
+
@processor = TestProcessorDefault.new
|
270
|
+
@processor.warn_on_default = false
|
271
|
+
|
272
|
+
a = s(:blah, 1, 2, 3)
|
273
|
+
assert_equal(@processor.expected.new(42), @processor.process(a))
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_process_not_sexp
|
277
|
+
@processor = TestProcessor.new
|
278
|
+
@processor.warn_on_default = false
|
279
|
+
|
280
|
+
assert_raises(TypeError) do
|
281
|
+
@processor.process([:broken, 1, 2, 3])
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_exclude
|
286
|
+
@processor.exclude = [ :blah ]
|
287
|
+
assert_raise(SyntaxError) do
|
288
|
+
@processor.process([:blah, 1, 2, 3])
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_exclude=; end # Handled
|
293
|
+
|
294
|
+
def test_strict
|
295
|
+
@processor.strict = true
|
296
|
+
assert_raise(SyntaxError) do
|
297
|
+
@processor.process([:blah, 1, 2, 3])
|
298
|
+
end
|
299
|
+
end
|
300
|
+
def test_strict=; end #Handled
|
301
|
+
|
302
|
+
def test_require_empty_false
|
303
|
+
@processor.require_empty = false
|
304
|
+
@processor.expected = Object
|
305
|
+
|
306
|
+
assert_nothing_raised do
|
307
|
+
@processor.process([:nonempty, 1, 2, 3])
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_require_empty_true
|
312
|
+
assert_raise(TypeError) do
|
313
|
+
@processor.process([:nonempty, 1, 2, 3])
|
314
|
+
end
|
315
|
+
end
|
316
|
+
def test_require_empty=; end # handled
|
317
|
+
|
318
|
+
def test_process_strip
|
319
|
+
@processor.auto_shift_type = true
|
320
|
+
assert_equal([1, 2, 3], @processor.process(s(:strip, 1, 2, 3)))
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_assert_type_hit
|
324
|
+
assert_nothing_raised do
|
325
|
+
@processor.assert_type([:blah, 1, 2, 3], :blah)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_assert_type_miss
|
330
|
+
assert_raise(TypeError) do
|
331
|
+
@processor.assert_type([:thingy, 1, 2, 3], :blah)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_generate
|
336
|
+
# nothing to test at this time... soon.
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_auto_shift_type
|
340
|
+
@processor.auto_shift_type = false
|
341
|
+
assert_equal(false, @processor.auto_shift_type)
|
342
|
+
@processor.auto_shift_type = true
|
343
|
+
assert_equal(true, @processor.auto_shift_type)
|
344
|
+
end
|
345
|
+
def test_auto_shift_type_equal; end # handled
|
346
|
+
|
347
|
+
def test_default_method
|
348
|
+
# default functionality tested in process_default
|
349
|
+
assert_nil @processor.default_method
|
350
|
+
@processor.default_method = :something
|
351
|
+
assert_equal :something, @processor.default_method
|
352
|
+
end
|
353
|
+
def test_default_method=; end # handled
|
354
|
+
|
355
|
+
def test_expected
|
356
|
+
assert_equal Sexp, @processor.expected
|
357
|
+
assert_raises(TypeError) do
|
358
|
+
@processor.process([:expected]) # should raise
|
359
|
+
end
|
360
|
+
|
361
|
+
@processor.process(s(:str, "string")) # shouldn't raise
|
362
|
+
|
363
|
+
@processor.expected = Hash
|
364
|
+
assert_equal Hash, @processor.expected
|
365
|
+
assert !(Hash === Sexp.new()), "Hash === Sexp.new should not be true"
|
366
|
+
|
367
|
+
assert_raises(TypeError) do
|
368
|
+
@processor.process(s(:string, "string")) # should raise
|
369
|
+
end
|
370
|
+
|
371
|
+
@processor.process([:expected]) # shouldn't raise
|
372
|
+
end
|
373
|
+
def test_expected=; end # handled
|
374
|
+
|
375
|
+
# Not Testing:
|
376
|
+
def test_debug; end
|
377
|
+
def test_debug=; end
|
378
|
+
def test_warn_on_default; end
|
379
|
+
def test_warn_on_default=; end
|
380
|
+
|
381
|
+
end
|
382
|
+
|