rubyjs 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/examples/client_server/README +18 -0
  2. data/examples/client_server/Rakefile +5 -0
  3. data/examples/client_server/client.js +749 -0
  4. data/examples/client_server/client.rb +12 -0
  5. data/examples/client_server/index.html +7 -0
  6. data/examples/client_server/server.rb +17 -0
  7. data/examples/hw/hw.js +234 -216
  8. data/rubyjs.gemspec +2 -2
  9. data/src/rubyjs.rb +0 -1
  10. data/src/rubyjs/compiler.rb +21 -8
  11. data/src/rubyjs/debug_name_generator.rb +23 -6
  12. data/src/rubyjs/model.rb +14 -8
  13. data/test/browser.test.html +1 -1
  14. data/test/browser.test.js +2337 -1992
  15. data/test/test_yield.rb +2 -0
  16. metadata +108 -158
  17. data/patches/parse_tree.rb.diff +0 -34
  18. data/vendor/ParseTree-1.7.1-patched/History.txt +0 -217
  19. data/vendor/ParseTree-1.7.1-patched/Manifest.txt +0 -22
  20. data/vendor/ParseTree-1.7.1-patched/README.txt +0 -110
  21. data/vendor/ParseTree-1.7.1-patched/Rakefile +0 -41
  22. data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_abc +0 -89
  23. data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_audit +0 -28
  24. data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_deps +0 -62
  25. data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_show +0 -49
  26. data/vendor/ParseTree-1.7.1-patched/demo/printer.rb +0 -20
  27. data/vendor/ParseTree-1.7.1-patched/lib/composite_sexp_processor.rb +0 -49
  28. data/vendor/ParseTree-1.7.1-patched/lib/parse_tree.rb +0 -1013
  29. data/vendor/ParseTree-1.7.1-patched/lib/sexp.rb +0 -235
  30. data/vendor/ParseTree-1.7.1-patched/lib/sexp_processor.rb +0 -330
  31. data/vendor/ParseTree-1.7.1-patched/lib/unique.rb +0 -15
  32. data/vendor/ParseTree-1.7.1-patched/test/pt_testcase.rb +0 -1221
  33. data/vendor/ParseTree-1.7.1-patched/test/something.rb +0 -53
  34. data/vendor/ParseTree-1.7.1-patched/test/test_all.rb +0 -13
  35. data/vendor/ParseTree-1.7.1-patched/test/test_composite_sexp_processor.rb +0 -69
  36. data/vendor/ParseTree-1.7.1-patched/test/test_parse_tree.rb +0 -216
  37. data/vendor/ParseTree-1.7.1-patched/test/test_sexp.rb +0 -291
  38. data/vendor/ParseTree-1.7.1-patched/test/test_sexp_processor.rb +0 -244
  39. data/vendor/ParseTree-1.7.1-patched/validate.sh +0 -31
  40. data/vendor/ParseTree-1.7.1/History.txt +0 -217
  41. data/vendor/ParseTree-1.7.1/Manifest.txt +0 -22
  42. data/vendor/ParseTree-1.7.1/README.txt +0 -110
  43. data/vendor/ParseTree-1.7.1/Rakefile +0 -41
  44. data/vendor/ParseTree-1.7.1/bin/parse_tree_abc +0 -89
  45. data/vendor/ParseTree-1.7.1/bin/parse_tree_audit +0 -28
  46. data/vendor/ParseTree-1.7.1/bin/parse_tree_deps +0 -62
  47. data/vendor/ParseTree-1.7.1/bin/parse_tree_show +0 -49
  48. data/vendor/ParseTree-1.7.1/demo/printer.rb +0 -20
  49. data/vendor/ParseTree-1.7.1/lib/composite_sexp_processor.rb +0 -49
  50. data/vendor/ParseTree-1.7.1/lib/parse_tree.rb +0 -1004
  51. data/vendor/ParseTree-1.7.1/lib/sexp.rb +0 -235
  52. data/vendor/ParseTree-1.7.1/lib/sexp_processor.rb +0 -330
  53. data/vendor/ParseTree-1.7.1/lib/unique.rb +0 -15
  54. data/vendor/ParseTree-1.7.1/test/pt_testcase.rb +0 -1221
  55. data/vendor/ParseTree-1.7.1/test/something.rb +0 -53
  56. data/vendor/ParseTree-1.7.1/test/test_all.rb +0 -13
  57. data/vendor/ParseTree-1.7.1/test/test_composite_sexp_processor.rb +0 -69
  58. data/vendor/ParseTree-1.7.1/test/test_parse_tree.rb +0 -216
  59. data/vendor/ParseTree-1.7.1/test/test_sexp.rb +0 -291
  60. data/vendor/ParseTree-1.7.1/test/test_sexp_processor.rb +0 -244
  61. data/vendor/ParseTree-1.7.1/validate.sh +0 -31
@@ -1,53 +0,0 @@
1
-
2
- class Something
3
-
4
- def self.classmethod
5
- 1 + 1
6
- end
7
-
8
- # Other edge cases:
9
-
10
- def opt_args(arg1, arg2 = 42, *args)
11
- arg3 = arg1 * arg2 * 7
12
- puts(arg3.to_s)
13
- return "foo"
14
- end
15
-
16
- def multi_args(arg1, arg2)
17
- arg3 = arg1 * arg2 * 7
18
- puts(arg3.to_s)
19
- return "foo"
20
- end
21
-
22
- def unknown_args(arg1, arg2)
23
- # does nothing
24
- return arg1
25
- end
26
-
27
- def determine_args
28
- 5 == unknown_args(4, "known")
29
- end
30
-
31
- # TODO: sort list
32
- def bbegin
33
- begin
34
- 1
35
- rescue SyntaxError => e1
36
- 2
37
- rescue Exception => e2
38
- 3
39
- else
40
- 4
41
- ensure
42
- 5
43
- end
44
- end
45
-
46
- def bbegin_no_exception
47
- begin
48
- 5
49
- rescue
50
- 6
51
- end
52
- end
53
- end
@@ -1,13 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- pat = "test_*.rb"
4
- if File.basename(Dir.pwd) != "test" then
5
- $: << "test"
6
- pat = File.join("test", pat)
7
- end
8
-
9
- Dir.glob(pat).each do |f|
10
- require f
11
- end
12
-
13
- require 'test/unit'
@@ -1,69 +0,0 @@
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
@@ -1,216 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- dir = File.expand_path "~/.ruby_inline"
4
- if test ?d, dir then
5
- require 'fileutils'
6
- puts "nuking #{dir}"
7
- FileUtils.rm_r dir
8
- end
9
-
10
- require 'test/unit'
11
- require 'parse_tree'
12
- require 'pt_testcase'
13
- require 'test/something'
14
-
15
- class SomethingWithInitialize
16
- def initialize; end # this method is private
17
- protected
18
- def protected_meth; end
19
- end
20
-
21
- class ParseTree
22
- def process(input) # makes it play with with ParseTreeTestCase (FIX?)
23
- # um. kinda stupid, but cleaner
24
- case input
25
- when Array then
26
- ParseTree.translate(*input)
27
- else
28
- ParseTree.translate(input)
29
- end
30
- end
31
- end
32
-
33
- class TestParseTree < ParseTreeTestCase
34
- def setup
35
- super
36
- @processor = ParseTree.new(false)
37
- end
38
-
39
- def test_class_initialize
40
- expected = [[:class, :SomethingWithInitialize, [:const, :Object],
41
- [:defn, :initialize, [:scope, [:block, [:args], [:nil]]]],
42
- [:defn, :protected_meth, [:scope, [:block, [:args], [:nil]]]],
43
- ]]
44
- tree = @processor.parse_tree SomethingWithInitialize
45
- assert_equal expected, tree
46
- end
47
-
48
- def test_class_translate_string
49
- str = "class A; def a; end; end"
50
-
51
- sexp = ParseTree.translate str
52
-
53
- expected = [:class, :A, nil,
54
- [:scope,
55
- [:defn, :a, [:scope, [:block, [:args], [:nil]]]]]]
56
-
57
- assert_equal expected, sexp
58
- end
59
-
60
- def test_class_translate_string_method
61
- str = "class A; def a; end; def b; end; end"
62
-
63
- sexp = ParseTree.translate str, :a
64
-
65
- expected = [:defn, :a, [:scope, [:block, [:args], [:nil]]]]
66
-
67
- assert_equal expected, sexp
68
- end
69
-
70
- def test_parse_tree_for_string
71
- actual = @processor.parse_tree_for_string '1 + nil', '(string)', 1, false
72
- expected = [[:call, [:lit, 1], :+, [:array, [:nil]]]]
73
-
74
- assert_equal expected, actual
75
- end
76
-
77
- def test_parse_tree_for_string_with_newlines
78
- actual = @processor.parse_tree_for_string "1 +\n nil", 'test.rb', 5, true
79
- expected = [[:newline, 6, "test.rb"],
80
- [:call, [:lit, 1], :+, [:array, [:nil]]]]
81
-
82
- assert_equal expected, actual
83
- end
84
-
85
- def test_parse_tree_for_str
86
- actual = @processor.parse_tree_for_str '1 + nil', '(string)', 1, false
87
- expected = [[:call, [:lit, 1], :+, [:array, [:nil]]]]
88
-
89
- assert_equal expected, actual
90
- end
91
-
92
- @@self_classmethod = [:defn, :"self.classmethod",
93
- [:scope,
94
- [:block,
95
- [:args],
96
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]]]]]
97
-
98
- @@missing = [nil]
99
-
100
- @@opt_args = [:defn, :opt_args,
101
- [:scope,
102
- [:block,
103
- [:args, :arg1, :arg2, :"*args", [:block, [:lasgn, :arg2, [:lit, 42]]]],
104
- [:lasgn, :arg3,
105
- [:call,
106
- [:call,
107
- [:lvar, :arg1],
108
- :*,
109
- [:array, [:lvar, :arg2]]],
110
- :*,
111
- [:array, [:lit, 7]]]],
112
- [:fcall, :puts, [:array, [:call, [:lvar, :arg3], :to_s]]],
113
- [:return,
114
- [:str, "foo"]]]]]
115
- @@multi_args = [:defn, :multi_args,
116
- [:scope,
117
- [:block,
118
- [:args, :arg1, :arg2],
119
- [:lasgn, :arg3,
120
- [:call,
121
- [:call,
122
- [:lvar, :arg1],
123
- :*,
124
- [:array, [:lvar, :arg2]]],
125
- :*,
126
- [:array, [:lit, 7]]]],
127
- [:fcall, :puts, [:array, [:call, [:lvar, :arg3], :to_s]]],
128
- [:return,
129
- [:str, "foo"]]]]]
130
- @@unknown_args = [:defn, :unknown_args,
131
- [:scope,
132
- [:block,
133
- [:args, :arg1, :arg2],
134
- [:return, [:lvar, :arg1]]]]]
135
- @@bbegin = [:defn, :bbegin,
136
- [:scope,
137
- [:block,
138
- [:args],
139
- [:begin,
140
- [:ensure,
141
- [:rescue,
142
- [:lit, 1],
143
- [:resbody,
144
- [:array, [:const, :SyntaxError]],
145
- [:block, [:lasgn, :e1, [:gvar, :$!]], [:lit, 2]],
146
- [:resbody,
147
- [:array, [:const, :Exception]],
148
- [:block, [:lasgn, :e2, [:gvar, :$!]], [:lit, 3]]]],
149
- [:lit, 4]],
150
- [:lit, 5]]]]]]
151
- @@bbegin_no_exception = [:defn, :bbegin_no_exception,
152
- [:scope,
153
- [:block,
154
- [:args],
155
- [:begin,
156
- [:rescue,
157
- [:lit, 5],
158
- [:resbody, nil, [:lit, 6]]]]]]]
159
-
160
- @@determine_args = [:defn, :determine_args,
161
- [:scope,
162
- [:block,
163
- [:args],
164
- [:call,
165
- [:lit, 5],
166
- :==,
167
- [:array,
168
- [:fcall,
169
- :unknown_args,
170
- [:array, [:lit, 4], [:str, "known"]]]]]]]]
171
-
172
-
173
- @@attrasgn = [:defn,
174
- :attrasgn,
175
- [:scope,
176
- [:block,
177
- [:args],
178
- [:attrasgn, [:lit, 42], :method=, [:array, [:vcall, :y]]],
179
- [:attrasgn,
180
- [:self],
181
- :type=,
182
- [:array, [:call, [:vcall, :other], :type]]]]]]
183
-
184
- @@__all = [:class, :Something, [:const, :Object]]
185
-
186
- Something.instance_methods(false).sort.each do |meth|
187
- if class_variables.include?("@@#{meth}") then
188
- @@__all << eval("@@#{meth}")
189
- eval "def test_#{meth}; assert_equal @@#{meth}, @processor.parse_tree_for_method(Something, :#{meth}); end"
190
- else
191
- eval "def test_#{meth}; flunk \"You haven't added @@#{meth} yet\"; end"
192
- end
193
- end
194
-
195
- Something.singleton_methods.sort.each do |meth|
196
- next if meth =~ /yaml/ # rubygems introduced a bug
197
- if class_variables.include?("@@self_#{meth}") then
198
- @@__all << eval("@@self_#{meth}")
199
- eval "def test_self_#{meth}; assert_equal @@self_#{meth}, @processor.parse_tree_for_method(Something, :#{meth}, true); end"
200
- else
201
- eval "def test_self_#{meth}; flunk \"You haven't added @@self_#{meth} yet\"; end"
202
- end
203
- end
204
-
205
- def test_missing
206
- assert_equal(@@missing,
207
- @processor.parse_tree_for_method(Something, :missing),
208
- "Must return -3 for missing methods")
209
- end
210
-
211
- def test_whole_class
212
- assert_equal([@@__all],
213
- @processor.parse_tree(Something),
214
- "Must return a lot of shit")
215
- end
216
- end
@@ -1,291 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- $TESTING = true
4
-
5
- require 'test/unit' if $0 == __FILE__ unless defined? $ZENTEST and $ZENTEST
6
- require 'test/unit/testcase'
7
- require 'sexp_processor'
8
- require 'stringio'
9
- require 'pp'
10
-
11
- class SexpTestCase < Test::Unit::TestCase
12
-
13
- # KEY for regex tests
14
- # :a == no change
15
- # :b == will change (but sometimes ONLY once)
16
- # :c == change to
17
-
18
- include SexpMatchSpecials
19
-
20
- def util_equals3(x, y)
21
- result = x === y
22
- assert_not_nil result, "#{x.inspect} does not === #{y.inspect}"
23
- end
24
-
25
- def setup
26
- @any = ANY()
27
- end
28
-
29
- def test_stupid
30
- # shuts up test/unit
31
- end
32
- end
33
-
34
- class TestSexp < SexpTestCase # ZenTest FULL
35
-
36
- def util_pretty_print(expect, input)
37
- io = StringIO.new
38
- PP.pp(input, io)
39
- io.rewind
40
- assert_equal(expect, io.read.chomp)
41
- end
42
-
43
- def setup
44
- super
45
- @sexp_class = Object.const_get(self.class.name[4..-1])
46
- @processor = SexpProcessor.new
47
- @sexp = @sexp_class.new(1, 2, 3)
48
- @basic_sexp = s(:lasgn, :var, s(:lit, 42))
49
- @re = s(:lit, 42)
50
- @bad1 = s(:lit, 24)
51
- @bad1 = s(:blah, 42)
52
- end
53
-
54
- def test_class_from_array
55
- # raise NotImplementedError, 'Need to write test_class_from_array'
56
- end
57
-
58
- def test_class_index
59
- # raise NotImplementedError, 'Need to write test_class_index'
60
- end
61
-
62
- def test_array_type_eh
63
- assert_equal false, @sexp.array_type?
64
- @sexp.unshift :array
65
- assert_equal true, @sexp.array_type?
66
- end
67
-
68
- def test_each_of_type
69
- # TODO: huh... this tests fails if top level sexp :b is removed
70
- @sexp = s(:b, s(:a, s(:b, s(:a), :a, s(:b, :a), s(:b, s(:a)))))
71
- count = 0
72
- @sexp.each_of_type(:a) do |exp|
73
- count += 1
74
- end
75
- assert_equal(3, count, "must find 3 a's in #{@sexp.inspect}")
76
- end
77
-
78
- def test_equals2_array
79
- # can't use assert_equals because it uses array as receiver
80
- assert_not_equal(@sexp, [1, 2, 3],
81
- "Sexp must not be equal to equivalent array")
82
- # both directions just in case
83
- # HACK - this seems to be a bug in ruby as far as I'm concerned
84
- # assert_not_equal([1, 2, 3], @sexp,
85
- # "Sexp must not be equal to equivalent array")
86
- end
87
-
88
- def test_equals2_not_body
89
- sexp2 = s(1, 2, 5)
90
- assert_not_equal(@sexp, sexp2)
91
- end
92
-
93
- def test_equals2_sexp
94
- sexp2 = s(1, 2, 3)
95
- if @sexp.class == Sexp then
96
- # sexp3 = t(1, 2, 3, Type.str)
97
- # case @sexp
98
- # when TypedSexp
99
- # assert_equal(@sexp, sexp3)
100
- # assert_not_equal(@sexp, sexp2)
101
- # when Sexp
102
- assert_equal(@sexp, sexp2)
103
- # assert_not_equal(@sexp, sexp3)
104
- else
105
- assert_not_equal(@sexp, sexp2)
106
- # else
107
- # flunk "unknown type"
108
- end
109
- end
110
-
111
- def test_equals3_any
112
- util_equals3 @any, s()
113
- util_equals3 @any, s(:a)
114
- util_equals3 @any, s(:a, :b, s(:c))
115
- end
116
-
117
- def test_equals3_full_match
118
- util_equals3 s(), s() # 0
119
- util_equals3 s(:blah), s(:blah) # 1
120
- util_equals3 s(:a, :b), s(:a, :b) # 2
121
- util_equals3 @basic_sexp, @basic_sexp.dup # deeper structure
122
- end
123
-
124
- def test_equals3_mismatch
125
- assert_nil s() === s(:a)
126
- assert_nil s(:a) === s()
127
- assert_nil s(:blah1) === s(:blah2)
128
- assert_nil s(:a) === s(:a, :b)
129
- assert_nil s(:a, :b) === s(:a)
130
- assert_nil s(:a1, :b) === s(:a2, :b)
131
- assert_nil s(:a, :b1) === s(:a, :b2)
132
- assert_nil @basic_sexp === @basic_sexp.dup.push(42)
133
- assert_nil @basic_sexp.dup.push(42) === @basic_sexp
134
- end
135
-
136
- def test_equals3_subset_match
137
- util_equals3 s(:a), s(s(:a), s(:b)) # left
138
- util_equals3 s(:a), s(:blah, s(:a ), s(:b)) # mid 1
139
- util_equals3 s(:a, 1), s(:blah, s(:a, 1), s(:b)) # mid 2
140
- util_equals3 @basic_sexp, s(:blah, @basic_sexp.dup, s(:b)) # mid deeper
141
- util_equals3 @basic_sexp, s(@basic_sexp.dup, s(:a), s(:b)) # left deeper
142
-
143
- util_equals3 s(:a), s(:blah, s(:blah, s(:a))) # left deeper
144
- end
145
-
146
- # def test_equalstilde_any
147
- # result = @basic_sexp =~ s(:lit, ANY())
148
- # p result
149
- # assert result
150
- # end
151
-
152
- def test_equalstilde_fancy
153
- assert_nil s(:b) =~ s(:a, s(:b), :c)
154
- assert_not_nil s(:a, s(:b), :c) =~ s(:b)
155
- end
156
-
157
- def test_equalstilde_plain
158
- result = @basic_sexp =~ @re
159
- assert result
160
- end
161
-
162
- def test_find_and_replace_all
163
- @sexp = s(:a, s(:b, s(:a), s(:b), s(:b, s(:a))))
164
- expected = s(:a, s(:a, s(:a), s(:a), s(:a, s(:a))))
165
-
166
- @sexp.find_and_replace_all(:b, :a)
167
-
168
- assert_equal(expected, @sexp)
169
- end
170
-
171
- def test_gsub
172
- assert_equal s(:c), s().gsub(s(), s(:c))
173
- assert_equal s(:c), s(:b).gsub(s(:b), s(:c))
174
- assert_equal s(:a), s(:a).gsub(s(:b), s(:c))
175
- assert_equal s(:a, s(:c)), s(:a, s(:b)).gsub(s(:b), s(:c))
176
-
177
- assert_equal(s(:a, s(:c), s(:c)),
178
- s(:a, s(:b), s(:b)).gsub(s(:b), s(:c)))
179
- assert_equal(s(:a, s(:c), s(:a, s(:c))),
180
- s(:a, s(:b), s(:a, s(:b))).gsub(s(:b), s(:c)))
181
- end
182
-
183
- def test_inspect
184
- k = @sexp_class
185
- n = k.name[0].chr.downcase
186
- assert_equal("#{n}()",
187
- k.new().inspect)
188
- assert_equal("#{n}(:a)",
189
- k.new(:a).inspect)
190
- assert_equal("#{n}(:a, :b)",
191
- k.new(:a, :b).inspect)
192
- assert_equal("#{n}(:a, #{n}(:b))",
193
- k.new(:a, k.new(:b)).inspect)
194
- end
195
-
196
- def test_method_missing
197
- assert_nil @sexp.not_there
198
- assert_equal s(:lit, 42), @basic_sexp.lit
199
- end
200
-
201
- def test_method_missing_ambigious
202
- assert_raises NoMethodError do
203
- pirate = s(:says, s(:arrr!), s(:arrr!), s(:arrr!))
204
- pirate.arrr!
205
- end
206
- end
207
-
208
- def test_method_missing_deep
209
- sexp = s(:blah, s(:a, s(:b, s(:c, :yay!))))
210
- assert_equal(s(:c, :yay!), sexp.a.b.c)
211
- end
212
-
213
- def test_method_missing_delete
214
- sexp = s(:blah, s(:a, s(:b, s(:c, :yay!))))
215
-
216
- assert_equal(s(:c, :yay!), sexp.a.b.c(true))
217
- assert_equal(s(:blah, s(:a, s(:b))), sexp)
218
- end
219
-
220
- def test_pretty_print
221
- util_pretty_print("s()",
222
- s())
223
- util_pretty_print("s(:a)",
224
- s(:a))
225
- util_pretty_print("s(:a, :b)",
226
- s(:a, :b))
227
- util_pretty_print("s(:a, s(:b))",
228
- s(:a, s(:b)))
229
- end
230
-
231
- def test_sexp_body
232
- assert_equal [2, 3], @sexp.sexp_body
233
- end
234
-
235
- def test_shift
236
- assert_equal(1, @sexp.shift)
237
- assert_equal(2, @sexp.shift)
238
- assert_equal(3, @sexp.shift)
239
-
240
- assert_raise(RuntimeError) do
241
- @sexp.shift
242
- end
243
- end
244
-
245
- def test_structure
246
- @sexp = s(:a, 1, 2, s(:b, 3, 4), 5, 6)
247
- expected = s(:a, s(:b))
248
-
249
- assert_equal(expected, @sexp.structure)
250
- end
251
-
252
- def test_sub
253
- assert_equal s(:c), s().sub(s(), s(:c))
254
- assert_equal s(:c), s(:b).sub(s(:b), s(:c))
255
- assert_equal s(:a), s(:a).sub(s(:b), s(:c))
256
- assert_equal s(:a, s(:c)), s(:a, s(:c)).sub(s(:b), s(:c))
257
-
258
- assert_equal s(:a, s(:c), s(:b)), s(:a, s(:b), s(:b)).sub(s(:b), s(:c))
259
-
260
- assert_equal(s(:a, s(:c), s(:a)),
261
- s(:a, s(:b), s(:a)).sub(s(:b), s(:c)))
262
- assert_equal(s(:a, s(:c), s(:a, s(:a))),
263
- s(:a, s(:b), s(:a, s(:a))).sub(s(:b), s(:c)))
264
- assert_equal(s(:a, s(:a), s(:a, s(:c), s(:b))),
265
- s(:a, s(:a), s(:a, s(:b), s(:b))).sub(s(:b), s(:c)))
266
- assert_equal(s(:a, s(:c, s(:b))),
267
- s(:a, s(:b)).sub(s(:b), s(:c, s(:b))))
268
- end
269
-
270
- def test_to_a
271
- assert_equal([1, 2, 3], @sexp.to_a)
272
- end
273
-
274
- def test_to_s
275
- test_inspect
276
- end
277
- end
278
-
279
- class TestSexpAny < SexpTestCase
280
-
281
- def setup
282
- super
283
- end
284
-
285
- def test_equals3
286
- util_equals3 @any, s()
287
- util_equals3 @any, s(:a)
288
- util_equals3 @any, s(:a, :b, s(:c))
289
- end
290
-
291
- end