ruby-internal 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +59 -0
- data/LGPL +515 -0
- data/LICENSE +9 -0
- data/README +31 -0
- data/Rakefile +20 -0
- data/TODO +9 -0
- data/example/README +5 -0
- data/example/simple_client.rb +12 -0
- data/example/simple_server.rb +11 -0
- data/example/triangle_client.rb +7 -0
- data/example/triangle_server.rb +24 -0
- data/ext/cached/ruby-1.8.0/internal/binding/block.h +37 -0
- data/ext/cached/ruby-1.8.0/internal/method/method.h +19 -0
- data/ext/cached/ruby-1.8.0/internal/module/classpath.c +27 -0
- data/ext/cached/ruby-1.8.0/internal/module/classpath.h +14 -0
- data/ext/cached/ruby-1.8.0/internal/node/block.h +37 -0
- data/ext/cached/ruby-1.8.0/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.0/internal/node/node_type_descrip.c +155 -0
- data/ext/cached/ruby-1.8.0/internal/node/nodeinfo.c +5741 -0
- data/ext/cached/ruby-1.8.0/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.0/internal/proc/block.h +37 -0
- data/ext/cached/ruby-1.8.0/internal/tag/tag.h +15 -0
- data/ext/cached/ruby-1.8.0/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.0/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.0/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.1/internal/binding/block.h +31 -0
- data/ext/cached/ruby-1.8.1/internal/method/method.h +19 -0
- data/ext/cached/ruby-1.8.1/internal/module/classpath.c +27 -0
- data/ext/cached/ruby-1.8.1/internal/module/classpath.h +14 -0
- data/ext/cached/ruby-1.8.1/internal/node/block.h +31 -0
- data/ext/cached/ruby-1.8.1/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.1/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.1/internal/node/nodeinfo.c +5733 -0
- data/ext/cached/ruby-1.8.1/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.1/internal/proc/block.h +31 -0
- data/ext/cached/ruby-1.8.1/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.1/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.1/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.1/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.2/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.2/internal/method/method.h +19 -0
- data/ext/cached/ruby-1.8.2/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.2/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.2/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.2/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.2/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.2/internal/node/nodeinfo.c +5733 -0
- data/ext/cached/ruby-1.8.2/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.2/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.2/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.2/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.2/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.2/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.3/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.3/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.3/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.3/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.3/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.3/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.3/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.3/internal/node/nodeinfo.c +5733 -0
- data/ext/cached/ruby-1.8.3/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.3/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.3/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.3/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.3/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.3/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.4/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.4/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.4/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.4/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.4/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.4/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.4/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.4/internal/node/nodeinfo.c +5733 -0
- data/ext/cached/ruby-1.8.4/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.4/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.4/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.4/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.4/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.4/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.5/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.5/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.5/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.5/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.5/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.5/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.5/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.5/internal/node/nodeinfo.c +5732 -0
- data/ext/cached/ruby-1.8.5/internal/node/nodeinfo.h +67 -0
- data/ext/cached/ruby-1.8.5/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.5/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.5/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.5/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.5/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.6/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.6/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.6/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.6/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.6/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.6/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.6/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.6/internal/node/nodeinfo.c +5732 -0
- data/ext/cached/ruby-1.8.6/internal/node/nodeinfo.h +67 -0
- data/ext/cached/ruby-1.8.6/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.6/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.6/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.6/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.6/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.7/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.7/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.7/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.7/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.7/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.7/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.7/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.7/internal/node/nodeinfo.c +5732 -0
- data/ext/cached/ruby-1.8.7/internal/node/nodeinfo.h +67 -0
- data/ext/cached/ruby-1.8.7/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.7/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.7/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.7/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.7/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.9.0/internal/binding/block.h +12 -0
- data/ext/cached/ruby-1.9.0/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.9.0/internal/module/classpath.c +42 -0
- data/ext/cached/ruby-1.9.0/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.9.0/internal/node/block.h +12 -0
- data/ext/cached/ruby-1.9.0/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.9.0/internal/node/node_type_descrip.c +149 -0
- data/ext/cached/ruby-1.9.0/internal/node/nodeinfo.c +5579 -0
- data/ext/cached/ruby-1.9.0/internal/node/nodeinfo.h +70 -0
- data/ext/cached/ruby-1.9.0/internal/proc/block.h +12 -0
- data/ext/cached/ruby-1.9.0/internal/tag/tag.h +6 -0
- data/ext/cached/ruby-1.9.0/internal/vm/instruction/insns_info.c +5936 -0
- data/ext/cached/ruby-1.9.0/internal/vm/instruction/insns_info.h +891 -0
- data/ext/cached/ruby-1.9.0/internal/vm/iseq/insns_info.inc +700 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/debug.h +36 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/dln.h +41 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/encdb.h +147 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/eval_intern.h +221 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/gc.h +75 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/id.h +83 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/iseq.h +94 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/node.h +516 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/parse.h +303 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/regenc.h +207 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/regint.h +842 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/regparse.h +351 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/revision.h +1 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/thread_pthread.h +24 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/thread_win32.h +33 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/transcode_data.h +99 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/transdb.h +67 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/version.h +57 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_core.h +663 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_exec.h +187 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_insnhelper.h +191 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_opts.h +51 -0
- data/ext/cached/ruby-1.9.1/internal/binding/block.h +12 -0
- data/ext/cached/ruby-1.9.1/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.9.1/internal/module/classpath.c +42 -0
- data/ext/cached/ruby-1.9.1/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.9.1/internal/node/block.h +12 -0
- data/ext/cached/ruby-1.9.1/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.9.1/internal/node/node_type_descrip.c +149 -0
- data/ext/cached/ruby-1.9.1/internal/node/nodeinfo.c +5579 -0
- data/ext/cached/ruby-1.9.1/internal/node/nodeinfo.h +70 -0
- data/ext/cached/ruby-1.9.1/internal/proc/block.h +12 -0
- data/ext/cached/ruby-1.9.1/internal/tag/tag.h +6 -0
- data/ext/cached/ruby-1.9.1/internal/vm/instruction/insns_info.c +5936 -0
- data/ext/cached/ruby-1.9.1/internal/vm/instruction/insns_info.h +891 -0
- data/ext/cached/ruby-1.9.1/internal/vm/iseq/insns_info.inc +700 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/debug.h +36 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/dln.h +41 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/encdb.h +147 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/eval_intern.h +209 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/gc.h +75 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/id.h +184 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/iseq.h +94 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/node.h +516 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/parse.h +303 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/regenc.h +207 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/regint.h +842 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/regparse.h +351 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/revision.h +1 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/thread_pthread.h +24 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/thread_win32.h +33 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/transcode_data.h +99 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/transdb.h +85 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/version.h +60 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_core.h +655 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_exec.h +187 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_insnhelper.h +194 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_opts.h +51 -0
- data/ext/internal/binding/binding.c +45 -0
- data/ext/internal/binding/block.h.rpp +44 -0
- data/ext/internal/binding/extconf.rb +6 -0
- data/ext/internal/method/extconf.rb +8 -0
- data/ext/internal/method/method.c +269 -0
- data/ext/internal/method/method.h.rpp +58 -0
- data/ext/internal/module/classpath.c.rpp +29 -0
- data/ext/internal/module/classpath.h.rpp +36 -0
- data/ext/internal/module/extconf.rb +11 -0
- data/ext/internal/module/module.c +797 -0
- data/ext/internal/module/module.h +7 -0
- data/ext/internal/node/block.h.rpp +44 -0
- data/ext/internal/node/builtins.h +41 -0
- data/ext/internal/node/extconf.rb +66 -0
- data/ext/internal/node/global_entry.h.rpp +26 -0
- data/ext/internal/node/node.c +1147 -0
- data/ext/internal/node/node_type_descrip.c.rpp +72 -0
- data/ext/internal/node/node_type_descrip.h +17 -0
- data/ext/internal/node/node_type_descrip.rb +39 -0
- data/ext/internal/node/nodeinfo.c.rpp +587 -0
- data/ext/internal/node/nodeinfo.h.rpp +30 -0
- data/ext/internal/node/nodes.rb +78 -0
- data/ext/internal/node/read_node_h.rb +34 -0
- data/ext/internal/node/ruby_internal_node.h +31 -0
- data/ext/internal/noex/extconf.rb +6 -0
- data/ext/internal/noex/noex.c +44 -0
- data/ext/internal/object/extconf.rb +4 -0
- data/ext/internal/object/object.c +75 -0
- data/ext/internal/proc/block.h.rpp +44 -0
- data/ext/internal/proc/extconf.rb +9 -0
- data/ext/internal/proc/proc.c +331 -0
- data/ext/internal/tag/extconf.rb +3 -0
- data/ext/internal/tag/tag.c +17 -0
- data/ext/internal/tag/tag.h.rpp +22 -0
- data/ext/internal/thread/extconf.rb +3 -0
- data/ext/internal/thread/thread.c +107 -0
- data/ext/internal/vm/constants/constants.c +33 -0
- data/ext/internal/vm/constants/extconf.rb +3 -0
- data/ext/internal/vm/control_frame/control_frame.c +185 -0
- data/ext/internal/vm/control_frame/control_frame.h +18 -0
- data/ext/internal/vm/control_frame/extconf.rb +3 -0
- data/ext/internal/vm/extconf.rb +3 -0
- data/ext/internal/vm/inline_cache/extconf.rb +6 -0
- data/ext/internal/vm/inline_cache/inline_cache.c +79 -0
- data/ext/internal/vm/instruction/extconf.rb +6 -0
- data/ext/internal/vm/instruction/insns_info.c.rpp +213 -0
- data/ext/internal/vm/instruction/insns_info.h.rpp +53 -0
- data/ext/internal/vm/instruction/instruction.c +78 -0
- data/ext/internal/vm/instruction/instruction.h +10 -0
- data/ext/internal/vm/iseq/extconf.rb +7 -0
- data/ext/internal/vm/iseq/insns_info.inc.rpp +30 -0
- data/ext/internal/vm/iseq/internal_iseq.h +9 -0
- data/ext/internal/vm/iseq/iseq.c +555 -0
- data/ext/internal/vm/vm.c +55 -0
- data/ext/mkmf-ruby-internal.rb +111 -0
- data/ext/ruby_source_dir.rb +24 -0
- data/ext/rubypp.rb +97 -0
- data/generate_rdoc.rb +33 -0
- data/lib/internal/binding.rb +1 -0
- data/lib/internal/classtree.rb +55 -0
- data/lib/internal/debug.rb +16 -0
- data/lib/internal/method.rb +1 -0
- data/lib/internal/method/as_code.rb +33 -0
- data/lib/internal/method/as_expression.rb +34 -0
- data/lib/internal/method/signature.rb +442 -0
- data/lib/internal/module.rb +1 -0
- data/lib/internal/module/as_code.rb +45 -0
- data/lib/internal/node.rb +3 -0
- data/lib/internal/node/as_code.rb +233 -0
- data/lib/internal/node/as_expression.rb +619 -0
- data/lib/internal/node/dump.rb +53 -0
- data/lib/internal/node/pp.rb +72 -0
- data/lib/internal/node/to_a.rb +52 -0
- data/lib/internal/noex.rb +1 -0
- data/lib/internal/obfusc.rb +57 -0
- data/lib/internal/object.rb +1 -0
- data/lib/internal/object/as_code.rb +10 -0
- data/lib/internal/proc.rb +1 -0
- data/lib/internal/proc/as_code.rb +21 -0
- data/lib/internal/proc/as_expression.rb +14 -0
- data/lib/internal/proc/signature.rb +184 -0
- data/lib/internal/tag.rb +1 -0
- data/lib/internal/thread.rb +1 -0
- data/lib/internal/vm.rb +1 -0
- data/lib/internal/vm/bytedecoder.rb +866 -0
- data/lib/internal/vm/constants.rb +1 -0
- data/lib/internal/vm/control_frame.rb +1 -0
- data/lib/internal/vm/inline_cache.rb +1 -0
- data/lib/internal/vm/instruction.rb +1 -0
- data/lib/internal/vm/iseq.rb +1 -0
- data/lib/internal/vm/iseq/as_code.rb +27 -0
- data/lib/internal/vm/iseq/as_expression.rb +26 -0
- data/metaconfig +19 -0
- data/post-config.rb +1 -0
- data/post-install.rb +4 -0
- data/post-setup.rb +7 -0
- data/pre-config.rb +96 -0
- data/pre-install.rb +13 -0
- data/pre-setup.rb +8 -0
- data/run_tests.rb +26 -0
- data/setup.rb +1599 -0
- data/test/expression_samples.rb +160 -0
- data/test/node_samples.rb +122 -0
- data/test/test_as_code.rb +261 -0
- data/test/test_as_expression.rb +229 -0
- data/test/test_dump_class.rb +187 -0
- data/test/test_dump_method.rb +144 -0
- data/test/test_dump_proc.rb +118 -0
- data/test/test_helpers.rb +61 -0
- data/test/test_method.rb +72 -0
- data/test/test_methodsig.rb +267 -0
- data/test/test_module.rb +49 -0
- data/test/test_node.rb +77 -0
- data/test/test_proc.rb +47 -0
- metadata +377 -0
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
dir = File.dirname(__FILE__)
|
5
|
+
$:.unshift(dir) if not $:.include?(dir)
|
6
|
+
$:.unshift("#{dir}/../lib") if not $:.include?("#{dir}/../lib")
|
7
|
+
$:.unshift("#{dir}/../ext") if not $:.include?("#{dir}/../ext")
|
8
|
+
|
9
|
+
require 'internal/node/as_expression'
|
10
|
+
require 'internal/method/as_expression'
|
11
|
+
require 'internal/proc/as_expression'
|
12
|
+
|
13
|
+
require 'expression_samples'
|
14
|
+
|
15
|
+
$stdout.sync = true
|
16
|
+
$stderr.sync = true
|
17
|
+
|
18
|
+
class TC_As_Expression < Test::Unit::TestCase
|
19
|
+
extend Test::Unit::Assertions
|
20
|
+
|
21
|
+
# Some of the samples use this
|
22
|
+
def foo(*a, &b)
|
23
|
+
return b.call(1, 2) if b
|
24
|
+
return a
|
25
|
+
end
|
26
|
+
|
27
|
+
EXPRESSION_SAMPLES.each do |name, code|
|
28
|
+
p = proc {
|
29
|
+
p_orig = eval("proc { #{code} }")
|
30
|
+
code_new = p_orig.body.as_expression
|
31
|
+
# p code, code_new
|
32
|
+
p_new = eval("proc { #{code_new} }")
|
33
|
+
result_orig = result_new = nil
|
34
|
+
exc_orig = exc_new = nil
|
35
|
+
timeout(1) { begin; result_orig = p_orig.call; rescue; exc_orig = $!; end }
|
36
|
+
timeout(1) { begin; result_new = p_new.call; rescue; exc_new = $!; end }
|
37
|
+
assert_equal(result_orig, result_new)
|
38
|
+
assert_equal(exc_orig.class, exc_new.class)
|
39
|
+
if exc_orig and exc_new then
|
40
|
+
assert_equal(exc_orig.message, exc_new.message)
|
41
|
+
end
|
42
|
+
}
|
43
|
+
define_method "test_#{name}", p
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize(test_method_name)
|
47
|
+
# TODO: This seems to be the only way to get tests defined with #
|
48
|
+
# define_method to run on 1.8.1 and earlier.
|
49
|
+
catch(:invalid_test) { super(test_method_name) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def method_no_args
|
53
|
+
42
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_method_no_args_as_expression
|
57
|
+
m = method(:method_no_args)
|
58
|
+
assert_equal 'def method_no_args(); 42; end', m.as_expression
|
59
|
+
end
|
60
|
+
|
61
|
+
def method_one_arg(a)
|
62
|
+
42
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_method_one_arg_as_expression
|
66
|
+
m = method(:method_one_arg)
|
67
|
+
assert_equal 'def method_one_arg(a); 42; end', m.as_expression
|
68
|
+
end
|
69
|
+
|
70
|
+
def method_two_args(a, b)
|
71
|
+
42
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_method_two_args_as_expression
|
75
|
+
m = method(:method_two_args)
|
76
|
+
assert_equal 'def method_two_args(a, b); 42; end', m.as_expression
|
77
|
+
end
|
78
|
+
|
79
|
+
def method_rest_arg(*rest)
|
80
|
+
42
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_method_rest_arg_as_expression
|
84
|
+
m = method(:method_rest_arg)
|
85
|
+
assert_equal 'def method_rest_arg(*rest); 42; end', m.as_expression
|
86
|
+
end
|
87
|
+
|
88
|
+
def method_block_arg(&block)
|
89
|
+
42
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_method_block_arg_as_expression
|
93
|
+
m = method(:method_block_arg)
|
94
|
+
assert_equal 'def method_block_arg(&block); 42; end', m.as_expression
|
95
|
+
end
|
96
|
+
|
97
|
+
def method_rest_and_block_arg(*rest, &block)
|
98
|
+
42
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_method_rest_and_block_arg_as_expression
|
102
|
+
m = method(:method_rest_and_block_arg)
|
103
|
+
assert_equal 'def method_rest_and_block_arg(*rest, &block); 42; end', m.as_expression
|
104
|
+
end
|
105
|
+
|
106
|
+
def method_two_args_and_rest_and_block_arg(a, b, *rest, &block)
|
107
|
+
42
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_method_two_args_and_rest_and_block_arg_as_expression
|
111
|
+
m = method(:method_two_args_and_rest_and_block_arg)
|
112
|
+
assert_equal 'def method_two_args_and_rest_and_block_arg(a, b, *rest, &block); 42; end', m.as_expression
|
113
|
+
end
|
114
|
+
|
115
|
+
def method_two_default_args(a = 1, b = 2)
|
116
|
+
42
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_method_two_default_args_as_expression
|
120
|
+
m = method(:method_two_default_args)
|
121
|
+
assert_equal('def method_two_default_args(a=1, b=2); 42; end', m.as_expression)
|
122
|
+
end
|
123
|
+
|
124
|
+
def method_with_body(a, b)
|
125
|
+
a + b
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_method_with_body_as_expression
|
129
|
+
m = method(:method_with_body)
|
130
|
+
assert_equal 'def method_with_body(a, b); a + b; end', m.as_expression
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_proc_no_args_as_expression
|
134
|
+
p = proc { }
|
135
|
+
assert_equal 'proc { }', p.as_expression
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_proc_empty_args_as_expression
|
139
|
+
if not defined?(RubyVM) then
|
140
|
+
# indistinguishable from proc { } on YARV
|
141
|
+
p = proc { || }
|
142
|
+
assert_equal 'proc { || }', p.as_expression
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_proc_one_arg_as_expression
|
147
|
+
p = proc { |a| }
|
148
|
+
assert_equal 'proc { |a| }', p.as_expression
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_proc_one_array_arg_as_expression
|
152
|
+
p = proc { |a,| }
|
153
|
+
assert_equal 'proc { |a,| }', p.as_expression
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_proc_two_args_as_expression
|
157
|
+
p = proc { |a, b| }
|
158
|
+
assert_equal 'proc { |a, b| }', p.as_expression
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_proc_rest_arg_as_expression
|
162
|
+
p = proc { |*rest| }
|
163
|
+
assert_equal 'proc { |*rest| }', p.as_expression
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_proc_two_args_and_rest_arg_as_expression
|
167
|
+
p = proc { |a, b, *rest| }
|
168
|
+
assert_equal 'proc { |a, b, *rest| }', p.as_expression
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_proc_with_body_as_expression
|
172
|
+
p = proc { |a, b| a + b }
|
173
|
+
assert_equal 'proc { |a, b| a + b }', p.as_expression
|
174
|
+
end
|
175
|
+
|
176
|
+
def setup
|
177
|
+
@foo = 42
|
178
|
+
end
|
179
|
+
|
180
|
+
# 1.7 and later
|
181
|
+
def foo(*args)
|
182
|
+
return args
|
183
|
+
end
|
184
|
+
|
185
|
+
def remove_foo
|
186
|
+
self.class.remove_foo
|
187
|
+
end
|
188
|
+
|
189
|
+
# 1.6
|
190
|
+
def self.foo(*args)
|
191
|
+
return args
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.remove_foo
|
195
|
+
self.class_eval { remove_const(:FOO) if const_defined?(:FOO) }
|
196
|
+
end
|
197
|
+
|
198
|
+
@@foo = 10
|
199
|
+
|
200
|
+
FOO = 57
|
201
|
+
|
202
|
+
class ObjectWithFooAccessor
|
203
|
+
attr_accessor :foo
|
204
|
+
end
|
205
|
+
|
206
|
+
OWFA = ObjectWithFooAccessor.new
|
207
|
+
end
|
208
|
+
|
209
|
+
if __FILE__ == $0 then
|
210
|
+
require 'test/unit/ui/console/testrunner'
|
211
|
+
|
212
|
+
if Test::Unit.const_defined?(:AutoRunner) then
|
213
|
+
exit Test::Unit::AutoRunner.run
|
214
|
+
else
|
215
|
+
if ARGV.empty? then
|
216
|
+
suite = TC_As_Expression.suite
|
217
|
+
else
|
218
|
+
suite = Test::Unit::TestSuite.new('TC_As_Expression')
|
219
|
+
TC_As_Expression.suite.tests.each do |test|
|
220
|
+
ARGV.each do |arg|
|
221
|
+
suite << test if /#{arg}/ =~ test.name
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
result = Test::Unit::UI::Console::TestRunner.run(suite)
|
226
|
+
exit(result.error_count + result.failure_count)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
dir = File.dirname(__FILE__)
|
5
|
+
$:.unshift(dir) if not $:.include?(dir)
|
6
|
+
$:.unshift("#{dir}/../lib") if not $:.include?("#{dir}/../lib")
|
7
|
+
$:.unshift("#{dir}/../ext") if not $:.include?("#{dir}/../ext")
|
8
|
+
|
9
|
+
require 'internal/module'
|
10
|
+
require 'internal/object'
|
11
|
+
|
12
|
+
$stdout.sync = true
|
13
|
+
$stderr.sync = true
|
14
|
+
|
15
|
+
# Instance methods defined in Class get returned by
|
16
|
+
# rb_class_instance_methods, though they are not in the class's method
|
17
|
+
# table. Having this here ensures that we don't accidentally try to
|
18
|
+
# dump methods that aren't in the class we are trying to dump.
|
19
|
+
class Class
|
20
|
+
def xyzzy
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class TC_Dump_Class < Test::Unit::TestCase
|
25
|
+
module Foo
|
26
|
+
def foo(n=1)
|
27
|
+
# A fancy way to return 42
|
28
|
+
if false then
|
29
|
+
answer = 0
|
30
|
+
else
|
31
|
+
answer = 0
|
32
|
+
(1..42).each do |i|
|
33
|
+
answer += (i / i)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
return n * answer
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Tmp_Foo = nil
|
41
|
+
|
42
|
+
class TestClassBase
|
43
|
+
# for testing super()
|
44
|
+
def foo
|
45
|
+
return 42
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class TestClass < TestClassBase
|
50
|
+
include Foo
|
51
|
+
FOO = 1
|
52
|
+
@foo = 2
|
53
|
+
@@foo = 3
|
54
|
+
|
55
|
+
# Make sure we have enough instance variables to exceed
|
56
|
+
# ROBJECT_EMBED_LEN_MAX
|
57
|
+
@bar1 = 1
|
58
|
+
@bar2 = 2
|
59
|
+
@bar3 = 3
|
60
|
+
|
61
|
+
class << self
|
62
|
+
FOO = 4
|
63
|
+
@foo = 5
|
64
|
+
end
|
65
|
+
|
66
|
+
# for testing cvar
|
67
|
+
# (can't be in base class due to change in 1.9 of class var lookup)
|
68
|
+
@@a = 42
|
69
|
+
end
|
70
|
+
|
71
|
+
@@test_class = TestClass
|
72
|
+
|
73
|
+
def setup
|
74
|
+
self.class.instance_eval do
|
75
|
+
remove_const :TestClass if defined?(TestClass)
|
76
|
+
const_set :TestClass, @@test_class
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_marshal_class
|
81
|
+
begin
|
82
|
+
assert_equal 5, TestClass.singleton_class.instance_eval('@foo')
|
83
|
+
assert_equal 2, TestClass.instance_eval('@foo')
|
84
|
+
|
85
|
+
d = Marshal.dump(TestClass)
|
86
|
+
|
87
|
+
# Thread critical should have been reset by the class restorer
|
88
|
+
if not defined?(RubyVM) then
|
89
|
+
assert_equal false, Thread.critical
|
90
|
+
end
|
91
|
+
|
92
|
+
# Make sure the class instance variables are still set
|
93
|
+
assert_equal 5, TestClass.singleton_class.instance_eval('@foo')
|
94
|
+
assert_equal 2, TestClass.instance_eval('@foo')
|
95
|
+
|
96
|
+
orig_test_class = TestClass
|
97
|
+
orig_test_class_iv = TestClass.instance_variables
|
98
|
+
self.class.instance_eval { remove_const :TestClass }
|
99
|
+
|
100
|
+
c = Marshal.load(d)
|
101
|
+
assert_equal(TestClass, c)
|
102
|
+
assert_not_equal(orig_test_class, c)
|
103
|
+
assert_equal Class, c.class
|
104
|
+
|
105
|
+
a = c.ancestors
|
106
|
+
assert a.include?(Object)
|
107
|
+
assert a.include?(Kernel)
|
108
|
+
assert a.include?(Foo)
|
109
|
+
assert a.include?(c)
|
110
|
+
|
111
|
+
# Class instance variables
|
112
|
+
assert_equal orig_test_class_iv.sort, c.instance_variables.sort
|
113
|
+
result = c.instance_eval do
|
114
|
+
@foo
|
115
|
+
end
|
116
|
+
assert_equal 2, result
|
117
|
+
|
118
|
+
# Constant lookup (constants are really just special instance
|
119
|
+
# variables)
|
120
|
+
assert_equal 1, c::FOO
|
121
|
+
|
122
|
+
# Constant lookup in singleton class
|
123
|
+
result = class << c
|
124
|
+
FOO
|
125
|
+
end
|
126
|
+
assert_equal 4, result
|
127
|
+
|
128
|
+
# Singleton class instance variable lookup
|
129
|
+
result = class << c
|
130
|
+
@foo
|
131
|
+
end
|
132
|
+
assert_equal 5, result
|
133
|
+
|
134
|
+
# Class variable lookup
|
135
|
+
# This is a little bit messy, but it was the only way I could figure
|
136
|
+
# to get at @@foo
|
137
|
+
self.class.instance_eval do
|
138
|
+
remove_const :Tmp_Foo
|
139
|
+
const_set :Tmp_Foo, c
|
140
|
+
end
|
141
|
+
eval "class Tmp_Foo; $at_at_foo = @@foo; end"
|
142
|
+
result = $at_at_foo
|
143
|
+
assert_equal 3, result
|
144
|
+
|
145
|
+
# Test method call
|
146
|
+
f = c.new
|
147
|
+
assert_equal 42, f.foo()
|
148
|
+
assert_equal 42*42, f.foo(42)
|
149
|
+
|
150
|
+
# Thread critical should have been reset by the class restorer
|
151
|
+
if not defined?(RubyVM) then
|
152
|
+
assert_equal false, Thread.critical
|
153
|
+
end
|
154
|
+
|
155
|
+
# Also make sure the class instance variables are still set
|
156
|
+
assert_equal 5, TestClass.singleton_class.instance_eval('@foo')
|
157
|
+
assert_equal 2, TestClass.instance_eval('@foo')
|
158
|
+
|
159
|
+
ensure
|
160
|
+
if not defined?(RubyVM) then
|
161
|
+
Thread.critical = false
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
if __FILE__ == $0 then
|
168
|
+
require 'test/unit/ui/console/testrunner'
|
169
|
+
|
170
|
+
if Test::Unit.const_defined?(:AutoRunner) then
|
171
|
+
exit Test::Unit::AutoRunner.run
|
172
|
+
else
|
173
|
+
if ARGV.empty? then
|
174
|
+
suite = TC_Dump_Class.suite
|
175
|
+
else
|
176
|
+
suite = Test::Unit::TestSuite.new('TC_Dump_Class')
|
177
|
+
TC_Dump_Class.suite.tests.each do |test|
|
178
|
+
ARGV.each do |arg|
|
179
|
+
suite << test if /#{arg}/ =~ test.name
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
result = Test::Unit::UI::Console::TestRunner.run(suite)
|
184
|
+
exit(result.error_count + result.failure_count)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
dir = File.dirname(__FILE__)
|
5
|
+
$:.unshift(dir) if not $:.include?(dir)
|
6
|
+
$:.unshift("#{dir}/../lib") if not $:.include?("#{dir}/../lib")
|
7
|
+
$:.unshift("#{dir}/../ext") if not $:.include?("#{dir}/../ext")
|
8
|
+
|
9
|
+
require 'internal/method'
|
10
|
+
require 'internal/noex'
|
11
|
+
require 'internal/module'
|
12
|
+
|
13
|
+
require 'node_samples'
|
14
|
+
|
15
|
+
$stdout.sync = true
|
16
|
+
$stderr.sync = true
|
17
|
+
|
18
|
+
class TC_Dump_Module < Test::Unit::TestCase
|
19
|
+
module Foo
|
20
|
+
def foo(n=1)
|
21
|
+
# A fancy way to return 42
|
22
|
+
if false then
|
23
|
+
answer = 0
|
24
|
+
else
|
25
|
+
answer = 0
|
26
|
+
(1..42).each do |i|
|
27
|
+
answer += (i / i)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
return n * answer
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
include Foo
|
35
|
+
|
36
|
+
Tmp_Foo = nil
|
37
|
+
|
38
|
+
class TestClassBase
|
39
|
+
# for testing super()
|
40
|
+
def foo
|
41
|
+
return 42
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class TestClass < TestClassBase
|
46
|
+
include Foo
|
47
|
+
FOO = 1
|
48
|
+
@foo = 2
|
49
|
+
@@foo = 3
|
50
|
+
|
51
|
+
# Make sure we have enough instance variables to exceed
|
52
|
+
# ROBJECT_EMBED_LEN_MAX
|
53
|
+
@bar1 = 1
|
54
|
+
@bar2 = 2
|
55
|
+
@bar3 = 3
|
56
|
+
|
57
|
+
class << self
|
58
|
+
FOO = 4
|
59
|
+
@foo = 5
|
60
|
+
end
|
61
|
+
|
62
|
+
# for testing cvar
|
63
|
+
# (can't be in base class due to change in 1.9 of class var lookup)
|
64
|
+
@@a = 42
|
65
|
+
end
|
66
|
+
|
67
|
+
@@test_class = TestClass
|
68
|
+
|
69
|
+
def initialize(test_method_name)
|
70
|
+
# TODO: This seems to be the only way to get tests defined with #
|
71
|
+
# define_method to run on 1.8.1 and earlier.
|
72
|
+
catch(:invalid_test) { super(test_method_name) }
|
73
|
+
end
|
74
|
+
|
75
|
+
extend Test::Unit::Assertions
|
76
|
+
|
77
|
+
Method_Node_Samples.each do |node_name, sample_code|
|
78
|
+
p = proc {
|
79
|
+
c = TestClass.dup
|
80
|
+
c.class_eval <<-END_DEF
|
81
|
+
def foo
|
82
|
+
#{sample_code}
|
83
|
+
end
|
84
|
+
END_DEF
|
85
|
+
TC_Dump_Module.const_set("TestClass__#{node_name}", c)
|
86
|
+
|
87
|
+
o = c.new
|
88
|
+
m = o.method(:foo)
|
89
|
+
n = m.body
|
90
|
+
# puts "dumping first method"
|
91
|
+
# p sample_code
|
92
|
+
# pp o.method(:foo).body
|
93
|
+
d = Marshal.dump(n)
|
94
|
+
n2 = Marshal.load(d)
|
95
|
+
|
96
|
+
klass2 = Class.new(TestClassBase)
|
97
|
+
klass2.class_eval do
|
98
|
+
# for testing cvar
|
99
|
+
# (can't be in base class due to change in 1.9 of class var lookup)
|
100
|
+
@@a = 42
|
101
|
+
add_method(:foo, n2, Noex::PUBLIC)
|
102
|
+
end
|
103
|
+
obj1 = o
|
104
|
+
obj2 = klass2.new
|
105
|
+
|
106
|
+
orig_result = nil
|
107
|
+
orig_exc = nil
|
108
|
+
begin
|
109
|
+
orig_result = o.foo() { 17 }
|
110
|
+
rescue Exception => exc
|
111
|
+
orig_exc = exc
|
112
|
+
end
|
113
|
+
|
114
|
+
# puts "getting obj2 method"
|
115
|
+
# m = obj2.method(:foo)
|
116
|
+
# puts "getting obj2 method body"
|
117
|
+
# b = m.body
|
118
|
+
# puts "getting type"
|
119
|
+
# p b.class
|
120
|
+
# p b.members
|
121
|
+
# p b.rval
|
122
|
+
# p b.next
|
123
|
+
# p b.tbl
|
124
|
+
# puts "dumping second method"
|
125
|
+
# pp obj2.method(:foo).body
|
126
|
+
dup_result = nil
|
127
|
+
dup_exc = nil
|
128
|
+
begin
|
129
|
+
dup_result = obj2.foo() { 17 }
|
130
|
+
rescue Exception => exc
|
131
|
+
dup_exc = exc
|
132
|
+
end
|
133
|
+
|
134
|
+
assert_equal orig_exc, dup_exc
|
135
|
+
assert_equal orig_result, dup_result
|
136
|
+
}
|
137
|
+
define_method "test_dump_method_#{node_name}", p
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
if __FILE__ == $0 then
|
142
|
+
exit Test::Unit::AutoRunner.run
|
143
|
+
end
|
144
|
+
|