ParseTree 1.6.0 → 1.6.1

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.
@@ -1,3 +1,12 @@
1
+ *** 1.6.1 / 2006-11-11
2
+
3
+ + 2 minor enhancements:
4
+ + Have been going insane on the tests, expect more soon.
5
+ + Cleaned up using named nodes, now do: args = exp.scope.block.args(:delete).
6
+ + 2 bug fixes:
7
+ + Fixed #parse_tree to return superclass in :const node.
8
+ + Fixed while/until with no bodies (now nil).
9
+
1
10
  *** 1.6.0 / 2006-10-11
2
11
 
3
12
  + 2 major enhancements:
@@ -10,7 +19,7 @@
10
19
  + SexpProcessor's unsupported array now defaults to all the internal nodes.
11
20
  + Added Unique from ruby2c project.
12
21
  + something.rb got slimmed down to near nothing. About to be retired.
13
- + 7 bug fixes:
22
+ + 3 bug fixes:
14
23
  + Added changeset to Hoe spec.
15
24
  + Fixed up description to use paragraphs_of.
16
25
  + Fixed op_asgn1, alias, undef, dsym, match.
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ Hoe.new("ParseTree", ParseTree::VERSION) do |p|
12
12
  p.changes = p.paragraphs_of("History.txt", 1).join("\n\n")
13
13
  p.clean_globs << File.expand_path("~/.ruby_inline")
14
14
  p.extra_deps << ['RubyInline', '>= 3.2.0']
15
+ p.spec_extras[:require_paths] = proc { |paths| paths << 'test'; p paths }
15
16
  end
16
17
 
17
18
  desc 'Run against ruby 1.9 (from a multiruby install) with -d.'
@@ -25,7 +25,7 @@ require 'inline'
25
25
 
26
26
  class ParseTree
27
27
 
28
- VERSION = '1.6.0'
28
+ VERSION = '1.6.1'
29
29
 
30
30
  ##
31
31
  # Front end translation method.
@@ -82,7 +82,7 @@ class ParseTree
82
82
  code = if Class === klass then
83
83
  sc = klass.superclass
84
84
  sc_name = ((sc.nil? or sc.name.empty?) ? "nil" : sc.name).intern
85
- [:class, klassname, sc_name]
85
+ [:class, klassname, [:const, sc_name]]
86
86
  else
87
87
  [:module, klassname]
88
88
  end
@@ -399,7 +399,11 @@ again_no_block:
399
399
  case NODE_WHILE:
400
400
  case NODE_UNTIL:
401
401
  add_to_parse_tree(current, node->nd_cond, newlines, locals);
402
- add_to_parse_tree(current, node->nd_body, newlines, locals);
402
+ if (node->nd_body) {
403
+ add_to_parse_tree(current, node->nd_body, newlines, locals);
404
+ } else {
405
+ rb_ary_push(current, Qnil);
406
+ }
403
407
  rb_ary_push(current, node->nd_3rd == 0 ? Qfalse : Qtrue);
404
408
  break;
405
409
 
@@ -865,10 +869,10 @@ static VALUE parse_tree_for_meth(VALUE klass, VALUE method, VALUE newlines, VALU
865
869
  NODE *node = NULL;
866
870
  ID id;
867
871
  VALUE result = rb_ary_new();
872
+ VALUE version = rb_const_get_at(rb_cObject,rb_intern("RUBY_VERSION"));
868
873
 
869
874
  (void) self; // quell warnings
870
875
 
871
- VALUE version = rb_const_get_at(rb_cObject,rb_intern("RUBY_VERSION"));
872
876
  if (strcmp(StringValuePtr(version), #{RUBY_VERSION.inspect})) {
873
877
  rb_fatal("bad version, %s != #{RUBY_VERSION}\\n", StringValuePtr(version));
874
878
  }
@@ -10,16 +10,10 @@ class Sexp < Array # ZenTest FULL
10
10
 
11
11
  @@array_types = [ :array, :args, ]
12
12
 
13
- ##
14
- # Named positional parameters.
15
- # Use with +SexpProcessor.require_empty=false+.
16
- attr_accessor :accessors
17
-
18
13
  ##
19
14
  # Create a new Sexp containing +args+.
20
15
 
21
16
  def initialize(*args)
22
- @accessors = []
23
17
  super(args)
24
18
  end
25
19
 
@@ -123,35 +117,19 @@ class Sexp < Array # ZenTest FULL
123
117
  return "s(#{sexp_str})"
124
118
  end
125
119
 
126
- ##
127
- # Fancy-Schmancy method used to implement named positional accessors
128
- # via +accessors+.
129
- #
130
- # Example:
131
- #
132
- # class MyProcessor < SexpProcessor
133
- # def initialize
134
- # super
135
- # self.require_empty = false
136
- # self.sexp_accessors = {
137
- # :call => [:lhs, :name, :rhs]
138
- # }
139
- # ...
140
- # end
141
- #
142
- # def process_call(exp)
143
- # lhs = exp.lhs
144
- # name = exp.name
145
- # rhs = exp.rhs
146
- # ...
147
- # end
148
- # end
149
-
150
- def method_missing(meth, *a, &b)
151
- super unless @accessors.include? meth
152
-
153
- index = @accessors.index(meth) + 1 # skip type
154
- return self.at(index)
120
+ def method_missing(meth, delete=false)
121
+ matches = find_all { | sexp | Sexp === sexp and sexp.first == meth }
122
+
123
+ case matches.size
124
+ when 0 then
125
+ nil
126
+ when 1 then
127
+ match = matches.first
128
+ delete match if delete
129
+ match
130
+ else
131
+ raise NoMethodError, "multiple nodes for #{meth} were found in #{inspect}"
132
+ end
155
133
  end
156
134
 
157
135
  def pretty_print(q) # :nodoc:
@@ -121,11 +121,6 @@ class SexpProcessor
121
121
 
122
122
  attr_accessor :require_empty
123
123
 
124
- ##
125
- # Adds accessor methods to the Sexp
126
-
127
- attr_accessor :sexp_accessors
128
-
129
124
  ##
130
125
  # Creates a new SexpProcessor. Use super to invoke this
131
126
  # initializer from SexpProcessor subclasses, then use the
@@ -142,7 +137,6 @@ class SexpProcessor
142
137
  @debug = {}
143
138
  @expected = Sexp
144
139
  @require_empty = true
145
- @sexp_accessors = {}
146
140
  @exceptions = {}
147
141
 
148
142
  # we do this on an instance basis so we can subclass it for
@@ -189,14 +183,6 @@ class SexpProcessor
189
183
  exp_orig = exp.deep_clone if $DEBUG or
190
184
  @debug.has_key? type or @exceptions.has_key?(type)
191
185
 
192
- if Sexp === exp then
193
- if @sexp_accessors.include? type then
194
- exp.accessors = @sexp_accessors[type]
195
- else
196
- exp.accessors = [] # clean out accessor list in case it changed
197
- end
198
- end
199
-
200
186
  raise UnsupportedNodeError, "'#{type}' is not a supported node type" if @unsupported.include? type
201
187
 
202
188
  # do a pass through the rewriter first, if any, reassign back to exp
@@ -36,6 +36,26 @@ class ParseTreeTestCase < Test::Unit::TestCase
36
36
  Unique.reset
37
37
  end
38
38
 
39
+ def self.add_test name, data, klass = self.name[4..-1]
40
+ name = name.to_s
41
+ klass = klass.to_s
42
+ if testcases.has_key? name then
43
+ if testcases[name].has_key? klass then
44
+ warn "testcase #{klass}##{name} already has data"
45
+ else
46
+ testcases[name][klass] = data
47
+ end
48
+ else
49
+ warn "testcase #{name} does not exist"
50
+ end
51
+ end
52
+
53
+ def self.unsupported_tests *tests
54
+ tests.flatten.each do |name|
55
+ add_test name, :unsupported
56
+ end
57
+ end
58
+
39
59
  @@testcase_order = %w(Ruby ParseTree)
40
60
 
41
61
  @@testcases = {
@@ -44,7 +64,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
44
64
  "Ruby" => "class X\n alias :y :x\nend",
45
65
  "ParseTree" => [:class, :X, nil,
46
66
  [:scope, [:alias, [:lit, :y], [:lit, :x]]]],
47
- "Ruby2Ruby" => "class X\n alias_method :y, :x\n \nend", # FIX dbl \n
67
+ "Ruby2Ruby" => "class X\n alias_method :y, :x\nend", # FIX dbl \n
48
68
  },
49
69
 
50
70
  "and" => {
@@ -52,19 +72,6 @@ class ParseTreeTestCase < Test::Unit::TestCase
52
72
  "ParseTree" => [:and, [:vcall, :a], [:vcall, :b]],
53
73
  },
54
74
 
55
- "args" => {
56
- "Ruby" => "def x(a, b = 42, \*c, &d)\n p(a, b, c, d)\nend",
57
- "ParseTree" => [:defn, :x,
58
- [:scope,
59
- [:block,
60
- [:args, :a, :b, "*c".intern, # s->e
61
- [:block, [:lasgn, :b, [:lit, 42]]]],
62
- [:block_arg, :d],
63
- [:fcall, :p,
64
- [:array, [:lvar, :a], [:lvar, :b],
65
- [:lvar, :c], [:lvar, :d]]]]]]
66
- },
67
-
68
75
  "argscat" => {
69
76
  "Ruby" => "a = b, c, *d",
70
77
  "ParseTree" => [:lasgn, :a,
@@ -186,32 +193,44 @@ class ParseTreeTestCase < Test::Unit::TestCase
186
193
  "ParseTree" => [:cdecl, :X, [:lit, 42]],
187
194
  },
188
195
 
189
- "class" => {
190
- "Ruby" => "class X < Array\n def blah\n puts(\"hello\")\n end\n \nend",
196
+ "class_plain" => {
197
+ "Ruby" => "class X\n puts((1 + 1))\n def blah\n puts(\"hello\")\n end\nend",
191
198
  "ParseTree" => [:class,
192
199
  :X,
193
- [:const, :Array],
200
+ nil,
194
201
  [:scope,
195
- [:defn,
196
- :blah,
197
- [:scope,
198
- [:block,
199
- [:args],
200
- [:fcall, :puts, [:array, [:str, "hello"]]]]]]]],
202
+ [:block,
203
+ [:fcall, :puts, [:array, [:call, [:lit, 1], :+, [:array, [:lit, 1]]]]],
204
+ [:defn,
205
+ :blah,
206
+ [:scope,
207
+ [:block,
208
+ [:args],
209
+ [:fcall, :puts, [:array, [:str, "hello"]]]]]]]]],
201
210
  },
202
211
 
203
- "class_obj" => {
204
- "Ruby" => "class X\n def blah\n puts(\"hello\")\n end\n \nend",
212
+ "class_super_object" => {
213
+ "Ruby" => "class X < Object\nend",
205
214
  "ParseTree" => [:class,
206
215
  :X,
207
- nil,
208
- [:scope,
209
- [:defn,
210
- :blah,
211
- [:scope,
212
- [:block,
213
- [:args],
214
- [:fcall, :puts, [:array, [:str, "hello"]]]]]]]],
216
+ [:const, :Object],
217
+ [:scope]],
218
+ },
219
+
220
+ "class_super_array" => {
221
+ "Ruby" => "class X < Array\nend",
222
+ "ParseTree" => [:class,
223
+ :X,
224
+ [:const, :Array],
225
+ [:scope]],
226
+ },
227
+
228
+ "class_super_expr" => {
229
+ "Ruby" => "class X < expr\nend",
230
+ "ParseTree" => [:class,
231
+ :X,
232
+ [:vcall, :expr],
233
+ [:scope]],
215
234
  },
216
235
 
217
236
  "colon2" => {
@@ -256,6 +275,12 @@ class ParseTreeTestCase < Test::Unit::TestCase
256
275
  [:call, [:lit, 42], :<, [:array, [:lit, 0]]],
257
276
  [:return, [:lit, 3]],
258
277
  [:return, [:lit, 4]]]],
278
+ "Ruby2Ruby" => "if (42 == 0) then\n return 2\nelse\n if (42 < 0) then\n return 3\n else\n return 4\n end\nend",
279
+ },
280
+
281
+ "conditional5" => {
282
+ "Ruby" => "unless true then\n if false then\n return\n end\nend",
283
+ "ParseTree" => [:if, [:true], nil, [:if, [:false], [:return], nil]],
259
284
  },
260
285
 
261
286
  "const" => {
@@ -276,7 +301,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
276
301
  },
277
302
 
278
303
  "cvdecl" => {
279
- "Ruby" => "class X\n @@blah = 1\n \nend",
304
+ "Ruby" => "class X\n @@blah = 1\nend",
280
305
  "ParseTree" => [:class, :X, nil,
281
306
  [:scope, [:cvdecl, :@@blah, [:lit, 1]]]],
282
307
  },
@@ -298,6 +323,19 @@ class ParseTreeTestCase < Test::Unit::TestCase
298
323
  "ParseTree" => [:defined, [:gvar, :$x]],
299
324
  },
300
325
 
326
+ "defn_args" => {
327
+ "Ruby" => "def x(a, b = 42, \*c, &d)\n p(a, b, c, d)\nend",
328
+ "ParseTree" => [:defn, :x,
329
+ [:scope,
330
+ [:block,
331
+ [:args, :a, :b, "*c".intern, # s->e
332
+ [:block, [:lasgn, :b, [:lit, 42]]]],
333
+ [:block_arg, :d],
334
+ [:fcall, :p,
335
+ [:array, [:lvar, :a], [:lvar, :b],
336
+ [:lvar, :c], [:lvar, :d]]]]]]
337
+ },
338
+
301
339
  "defn_empty" => {
302
340
  "Ruby" => "def empty\n # do nothing\nend",
303
341
  "ParseTree" => [:defn, :empty, [:scope, [:block, [:args], [:nil]]]],
@@ -308,14 +346,23 @@ class ParseTreeTestCase < Test::Unit::TestCase
308
346
  "ParseTree" => [:defn, :something?, [:scope, [:block, [:args], [:nil]]]],
309
347
  },
310
348
 
349
+ # TODO:
350
+ # add_test("defn_optargs",
351
+ # s(:defn, :x,
352
+ # s(:args, :a, "*args".intern),
353
+ # s(:scope,
354
+ # s(:block,
355
+ # s(:call, nil, :p,
356
+ # s(:arglist, s(:lvar, :a), s(:lvar, :args)))))))
357
+
311
358
  "defn_or" => {
312
- "Ruby" => "def |\n # do nothing\nend",
313
- "ParseTree" => [:defn, :|, [:scope, [:block, [:args], [:nil]]]],
359
+ "Ruby" => "def |(o)\n # do nothing\nend",
360
+ "ParseTree" => [:defn, :|, [:scope, [:block, [:args, :o], [:nil]]]],
314
361
  },
315
362
 
316
363
  "defn_zarray" => { # tests memory allocation for returns
317
- "Ruby" => "def empty\n a = []\n return a\nend",
318
- "ParseTree" => [:defn, :empty,
364
+ "Ruby" => "def zarray\n a = []\n return a\nend",
365
+ "ParseTree" => [:defn, :zarray,
319
366
  [:scope,
320
367
  [:block, [:args],
321
368
  [:lasgn, :a, [:zarray]], [:return, [:lvar, :a]]]]],
@@ -391,23 +438,29 @@ class ParseTreeTestCase < Test::Unit::TestCase
391
438
  },
392
439
 
393
440
  "ensure" => {
394
- "Ruby" => "def bbegin\n begin\n (1 + 1)\n rescue SyntaxError => e1\n 2\n rescue Exception => e2\n 3\n else\n 4\n ensure\n 5\n end\nend",
395
- "ParseTree" => [:defn, :bbegin,
396
- [:scope,
397
- [:block,
398
- [:args],
399
- [:begin,
400
- [:ensure,
401
- [:rescue,
402
- [:call, [:lit, 1], :+, [:array, [:lit, 1]]],
403
- [:resbody,
404
- [:array, [:const, :SyntaxError]],
405
- [:block, [:lasgn, :e1, [:gvar, :$!]], [:lit, 2]],
406
- [:resbody,
407
- [:array, [:const, :Exception]],
408
- [:block, [:lasgn, :e2, [:gvar, :$!]], [:lit, 3]]]],
409
- [:lit, 4]],
410
- [:lit, 5]]]]]],
441
+ "Ruby" => "begin
442
+ (1 + 1)
443
+ rescue SyntaxError => e1
444
+ 2
445
+ rescue Exception => e2
446
+ 3
447
+ else
448
+ 4
449
+ ensure
450
+ 5
451
+ end",
452
+ "ParseTree" => [:begin,
453
+ [:ensure,
454
+ [:rescue,
455
+ [:call, [:lit, 1], :+, [:array, [:lit, 1]]],
456
+ [:resbody,
457
+ [:array, [:const, :SyntaxError]],
458
+ [:block, [:lasgn, :e1, [:gvar, :$!]], [:lit, 2]],
459
+ [:resbody,
460
+ [:array, [:const, :Exception]],
461
+ [:block, [:lasgn, :e2, [:gvar, :$!]], [:lit, 3]]]],
462
+ [:lit, 4]],
463
+ [:lit, 5]]],
411
464
  },
412
465
 
413
466
  "false" => {
@@ -652,7 +705,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
652
705
  },
653
706
 
654
707
  "module" => {
655
- "Ruby" => "module X\n def y\n # do nothing\n end\n \nend",
708
+ "Ruby" => "module X\n def y\n # do nothing\n end\nend",
656
709
  "ParseTree" => [:module, :X,
657
710
  [:scope,
658
711
  [:defn, :y, [:scope, [:block, [:args], [:nil]]]]]],
@@ -739,16 +792,21 @@ class ParseTreeTestCase < Test::Unit::TestCase
739
792
  [:fcall, :loop], nil, [:if, [:false], [:redo], nil]],
740
793
  },
741
794
 
742
- # "rescue" => { # TODO: expression style rescues
743
- # "Ruby" => "blah rescue nil",
744
- # "ParseTree" => [:rescue, [:vcall, :blah], [:resbody, nil, [:nil]]],
745
- # },
795
+ "rescue" => {
796
+ "Ruby" => "blah rescue nil",
797
+ "ParseTree" => [:rescue, [:vcall, :blah], [:resbody, nil, [:nil]]],
798
+ },
746
799
 
747
- "rescue_block" => {
800
+ "rescue_block_nada" => {
748
801
  "Ruby" => "begin\n blah\nrescue\n # do nothing\nend\n",
749
802
  "ParseTree" => [:begin, [:rescue, [:vcall, :blah], [:resbody, nil]]]
750
803
  },
751
804
 
805
+ "rescue_block_body" => {
806
+ "Ruby" => "begin\n blah\nrescue\n nil\nend\n",
807
+ "ParseTree" => [:begin, [:rescue, [:vcall, :blah], [:resbody, nil, [:nil]]]],
808
+ },
809
+
752
810
  "rescue_exceptions" => {
753
811
  "Ruby" => "begin\n blah\nrescue RuntimeError => r\n # do nothing\nend\n",
754
812
  "ParseTree" => [:begin,
@@ -774,6 +832,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
774
832
  "ParseTree" => [:fcall, :a, [:splat, [:vcall, :b]]],
775
833
  },
776
834
 
835
+ # TODO: all supers need to pass args
777
836
  "super" => {
778
837
  "Ruby" => "def x\n super(4)\nend",
779
838
  "ParseTree" => [:defn, :x,
@@ -823,12 +882,18 @@ class ParseTreeTestCase < Test::Unit::TestCase
823
882
  "Ruby2Ruby" => "undef :x\nundef :y\nundef :z\n",
824
883
  },
825
884
 
826
- "until" => {
885
+ "until_pre" => {
827
886
  "Ruby" => "until false do\n (1 + 1)\nend",
828
887
  "ParseTree" => [:until, [:false],
829
888
  [:call, [:lit, 1], :+, [:array, [:lit, 1]]], true],
830
889
  },
831
890
 
891
+ "until_post" => {
892
+ "Ruby" => "begin\n (1 + 1)\nend until false",
893
+ "ParseTree" => [:until, [:false],
894
+ [:call, [:lit, 1], :+, [:array, [:lit, 1]]], false],
895
+ },
896
+
832
897
  "valias" => {
833
898
  "Ruby" => "alias $y $x",
834
899
  "ParseTree" => [:valias, :$y, :$x],
@@ -839,17 +904,21 @@ class ParseTreeTestCase < Test::Unit::TestCase
839
904
  "ParseTree" => [:vcall, :method],
840
905
  },
841
906
 
842
- "whiles" => {
843
- "Ruby" => "def whiles\n while false do\n puts(\"false\")\n end\n begin\n puts(\"true\")\n end while false\nend",
844
- "ParseTree" => [:defn,
845
- :whiles,
846
- [:scope,
847
- [:block,
848
- [:args],
849
- [:while, [:false],
850
- [:fcall, :puts, [:array, [:str, "false"]]], true],
851
- [:while, [:false],
852
- [:fcall, :puts, [:array, [:str, "true"]]], false]]]],
907
+ "while_pre" => {
908
+ "Ruby" => "while false do\n (1 + 1)\nend",
909
+ "ParseTree" => [:while, [:false],
910
+ [:call, [:lit, 1], :+, [:array, [:lit, 1]]], true],
911
+ },
912
+
913
+ "while_pre_nil" => {
914
+ "Ruby" => "while false do\nend",
915
+ "ParseTree" => [:while, [:false], nil, true],
916
+ },
917
+
918
+ "while_post" => {
919
+ "Ruby" => "begin\n (1 + 1)\nend while false",
920
+ "ParseTree" => [:while, [:false],
921
+ [:call, [:lit, 1], :+, [:array, [:lit, 1]]], false],
853
922
  },
854
923
 
855
924
  "xstr" => {
@@ -912,8 +981,8 @@ class ParseTreeTestCase < Test::Unit::TestCase
912
981
  # flunk
913
982
  # end
914
983
 
915
- def self.previous(key)
916
- idx = @@testcase_order.index(key)-1
984
+ def self.previous(key, extra=0)
985
+ idx = @@testcase_order.index(key)-1-extra
917
986
  case key
918
987
  when "RubyToRubyC" then
919
988
  idx -= 1
@@ -921,36 +990,42 @@ class ParseTreeTestCase < Test::Unit::TestCase
921
990
  @@testcase_order[idx]
922
991
  end
923
992
 
924
- # lets us used unprocessed :self outside of tests, called when subclassed
925
- def self.clone_same
926
- @@testcases.each do |node, data|
927
- data.each do |key, val|
928
- if val == :same then
929
- prev_key = self.previous(key)
930
- data[key] = data[prev_key].deep_clone
931
- end
932
- end
933
- end
934
- end
993
+ # # lets us used unprocessed :self outside of tests, called when subclassed
994
+ # def self.clone_same
995
+ # @@testcases.each do |node, data|
996
+ # data.each do |key, val|
997
+ # if val == :same then
998
+ # prev_key = self.previous(key)
999
+ # data[key] = data[prev_key].deep_clone
1000
+ # end
1001
+ # end
1002
+ # end
1003
+ # end
935
1004
 
936
1005
  def self.inherited(c)
937
- self.clone_same
938
-
939
1006
  output_name = c.name.to_s.sub(/^Test/, '')
940
1007
  raise "Unknown class #{c}" unless @@testcase_order.include? output_name
941
1008
 
942
1009
  input_name = self.previous(output_name)
943
1010
 
944
1011
  @@testcases.each do |node, data|
945
- next if data[input_name] == :skip
1012
+ next if [:skip, :unsupported].include? data[input_name]
946
1013
  next if data[output_name] == :skip
947
1014
 
948
1015
  c.send(:define_method, "test_#{node}".intern) do
949
1016
  flunk "Processor is nil" if processor.nil?
950
1017
  assert data.has_key?(input_name), "Unknown input data"
1018
+ unless data.has_key?(output_name) then
1019
+ $stderr.puts "add_test(#{node.inspect}, :same)"
1020
+ end
951
1021
  assert data.has_key?(output_name), "Unknown expected data"
952
1022
  input = data[input_name].deep_clone
953
- expected = data[output_name].deep_clone
1023
+
1024
+ expected = if data[output_name] == :same then
1025
+ input
1026
+ else
1027
+ data[output_name]
1028
+ end.deep_clone
954
1029
 
955
1030
  case expected
956
1031
  when :unsupported then
@@ -964,7 +1039,8 @@ class ParseTreeTestCase < Test::Unit::TestCase
964
1039
  _, expected, extra_expected = *expected if Array === expected and expected.first == :defx
965
1040
  _, input, extra_input = *input if Array === input and input.first == :defx
966
1041
 
967
- assert_equal expected, processor.process(input)
1042
+ debug = input.deep_clone
1043
+ assert_equal expected, processor.process(input), "failed on input: #{debug.inspect}"
968
1044
  extra_input.each do |input| processor.process(input) end
969
1045
  extra = processor.extra_methods rescue []
970
1046
  assert_equal extra_expected, extra
@@ -28,11 +28,6 @@ class Something
28
28
  5 == unknown_args(4, "known")
29
29
  end
30
30
 
31
- def attrasgn
32
- 42.method = y
33
- self.type = other.type
34
- end
35
-
36
31
  # TODO: sort list
37
32
  def bbegin
38
33
  begin
@@ -37,7 +37,7 @@ class TestParseTree < ParseTreeTestCase
37
37
  end
38
38
 
39
39
  def test_class_initialize
40
- expected = [[:class, :SomethingWithInitialize, :Object,
40
+ expected = [[:class, :SomethingWithInitialize, [:const, :Object],
41
41
  [:defn, :initialize, [:scope, [:block, [:args], [:nil]]]],
42
42
  [:defn, :protected_meth, [:scope, [:block, [:args], [:nil]]]],
43
43
  ]]
@@ -159,7 +159,7 @@ class TestParseTree < ParseTreeTestCase
159
159
  :type=,
160
160
  [:array, [:call, [:vcall, :other], :type]]]]]]
161
161
 
162
- @@__all = [:class, :Something, :Object]
162
+ @@__all = [:class, :Something, [:const, :Object]]
163
163
 
164
164
  Something.instance_methods(false).sort.each do |meth|
165
165
  if class_variables.include?("@@#{meth}") then
@@ -59,25 +59,6 @@ class TestSexp < SexpTestCase # ZenTest FULL
59
59
  # raise NotImplementedError, 'Need to write test_class_index'
60
60
  end
61
61
 
62
- def test_accessors; end # handled
63
-
64
- def test_accessors_equals
65
- a = s(:call, s(:lit, 1), "func", s(:array, s(:lit, 2)))
66
- a.accessors = [:lhs, :name, :rhs]
67
-
68
- assert_equal a.accessors, [:lhs, :name, :rhs]
69
-
70
- assert_equal s(:lit, 1), a.lhs
71
- assert_equal "func", a.name
72
- assert_equal s(:array, s(:lit, 2)), a.rhs
73
-
74
- a.accessors = []
75
-
76
- assert_raises NoMethodError do
77
- a.lhs
78
- end
79
- end
80
-
81
62
  def test_array_type_eh
82
63
  assert_equal false, @sexp.array_type?
83
64
  @sexp.unshift :array
@@ -213,15 +194,27 @@ class TestSexp < SexpTestCase # ZenTest FULL
213
194
  end
214
195
 
215
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
216
202
  assert_raises NoMethodError do
217
- @sexp.no_such_method
203
+ pirate = s(:says, s(:arrr!), s(:arrr!), s(:arrr!))
204
+ pirate.arrr!
218
205
  end
206
+ end
219
207
 
220
- @sexp.accessors = [:its_a_method_now]
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
221
212
 
222
- assert_nothing_raised do
223
- assert_equal 2, @sexp.its_a_method_now
224
- end
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)
225
218
  end
226
219
 
227
220
  def test_pretty_print
@@ -84,30 +84,6 @@ class TestSexpProcessor < Test::Unit::TestCase
84
84
  @processor = TestProcessor.new
85
85
  end
86
86
 
87
- def test_sexp_accessors
88
- @processor.sexp_accessors = {
89
- :acc1 => [:thing_one, :thing_two, :thing_three]
90
- }
91
-
92
- a = s(:acc1, 1, 2, 3)
93
-
94
- assert_equal s(:acc2, 3, 2, 1), @processor.process(a)
95
- end
96
-
97
- def test_sexp_accessors_reset
98
- @processor.sexp_accessors = {
99
- :acc1 => [:thing_one, :thing_two, :thing_three]
100
- }
101
-
102
- a = s(:acc1, 1, 2, 3)
103
- b = @processor.process(a)
104
-
105
- assert_raises NoMethodError do
106
- @processor.process(b)
107
- end
108
- end
109
- def test_sexp_accessors=; end # handled
110
-
111
87
  def test_process_specific
112
88
  a = [:specific, 1, 2, 3]
113
89
  expected = a[1..-1]
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: ParseTree
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.6.0
7
- date: 2006-10-11 00:00:00 -07:00
6
+ version: 1.6.1
7
+ date: 2006-11-13 00:00:00 -05:00
8
8
  summary: Extract and enumerate ruby parse trees.
9
9
  require_paths:
10
10
  - lib
@@ -75,7 +75,7 @@ dependencies:
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: 1.1.1
78
+ version: 1.1.3
79
79
  version:
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: RubyInline