class Object
Constants
- DUMPED_OBJECT_SPACE_PROCS
- DUMP_OBJECT_SPACE_PROCS_ERRORS
Public Class Methods
echo()
click to toggle source
# File lib/sourcify/spec/no_method/unsupported_platform_spec.rb, line 6 def self.echo end
equal_to(expected)
click to toggle source
# File lib/sourcify/spec/method/to_sexp_from_def_end_block_within_irb_spec.rb, line 12 def equal_to(expected) lambda {|found| found == expected } end
irb_eval(string)
click to toggle source
# File lib/sourcify/spec/method/to_sexp_from_def_end_block_within_irb_spec.rb, line 8 def irb_eval(string) irb_exec(string)[-1] end
m2()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_w_multi_blocks_and_many_matches_spec.rb, line 18 def m2; @x1; end
m3()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_w_multi_blocks_and_many_matches_spec.rb, line 23 def m3; class << self; def m3; @x1; end; end; end
pry_eval(string)
click to toggle source
# File lib/sourcify/spec/method/to_sexp_from_def_end_block_within_pry_spec.rb, line 8 def pry_eval(string) pry_exec(string)[-1] end
to_ikra_type()
click to toggle source
# File lib/types/types/class_type.rb, line 136 def self.to_ikra_type # TODO: should this method be defined on Class? return Ikra::Types::ClassType.new(self) end
Public Instance Methods
a1()
click to toggle source
# File lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb, line 29 def a1; end
a2()
click to toggle source
# File lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb, line 29 def a2; end
aa()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_method_spec.rb, line 8 def aa; x = 1; end
bb()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_method_spec.rb, line 20 def bb; x = 2; end
blah()
click to toggle source
# File lib/sourcify/spec/proc/created_on_the_fly_proc_spec.rb, line 8 def blah; 1+2; end
capture(stdin_str = '') { || ... }
click to toggle source
# File lib/sourcify/spec/spec_helper.rb, line 87 def capture(stdin_str = '') begin require 'stringio' $o_stdin, $o_stdout, $o_stderr = $stdin, $stdout, $stderr $stdin, $stdout, $stderr = StringIO.new(stdin_str), StringIO.new, StringIO.new yield {:stdout => $stdout.string, :stderr => $stderr.string} ensure $stdin, $stdout, $stderr = $o_stdin, $o_stdout, $o_stderr end end
cc()
click to toggle source
# File lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb, line 39 def cc; end
code_to_sexp(code)
click to toggle source
# File lib/sourcify/spec/spec_helper.rb, line 47 def code_to_sexp(code) if has_parsetree? require 'parse_tree' Unifier.new.process(ParseTree.translate(code)) else require 'ruby_parser' RubyParser.new.parse(code) end end
dump_object_space_procs(debug = false)
click to toggle source
# File lib/sourcify/spec/dump_object_space_procs.rb, line 15 def dump_object_space_procs(debug = false) # Determine working dir name = [ RUBY_DESCRIPTION =~ /enterprise/i ? 'ree' : (RUBY_PLATFORM =~ /java/i ? 'jruby' : 'mri'), RUBY_VERSION, Object.const_defined?(:ParseTree) ? 'parsetree' : nil ].compact.join('~') dump_dir = File.join(File.dirname(File.expand_path(__FILE__)), '..', 'tmp', name) Dir.mkdir(dump_dir) unless File.exists?(dump_dir) puts '', '== NOTE: dump files can be found at %s' % dump_dir # Core processing ObjectSpace.each_object(Proc).to_a.select{|o| o.source_location }. group_by{|o| o.source_location[0] }.each do |ofile, objs| nfile = File.join(dump_dir, ofile.gsub('/','~')) File.open(nfile,'w') do |f| objs.sort_by{|o| o.source_location[1] }.map do |o| DUMPED_OBJECT_SPACE_PROCS[:done] += 1 begin data = { :location => o.source_location, :sexp => o.to_sexp, :source => o.to_source } f.puts(data.pretty_inspect) print '.' rescue Exception data = { :location => o.source_location, :error => $!.inspect } DUMP_OBJECT_SPACE_PROCS_ERRORS << data f.puts(data.pretty_inspect) pp(data) if debug print 'x' ensure raise STOP_DUMPING_OBJECT_SPACE_PROCS \ if DUMPED_OBJECT_SPACE_PROCS.values.uniq.size == 1 end end end end end
has_parsetree?()
click to toggle source
/////////////////////////////////////////////////////////// Spec helpers & matchers ///////////////////////////////////////////////////////////
# File lib/sourcify/spec/spec_helper.rb, line 39 def has_parsetree? Object.const_defined?(:ParseTree) end
having_raw_source(expected, opts={}, &matcher)
click to toggle source
# File lib/sourcify/spec/spec_helper.rb, line 69 def having_raw_source(expected, opts={}, &matcher) lambda do |thing| found = block_given? ? thing.to_raw_source(&matcher) : thing.to_raw_source(opts) found == expected.strip end end
having_sexp(expected, opts={}, &matcher)
click to toggle source
# File lib/sourcify/spec/spec_helper.rb, line 76 def having_sexp(expected, opts={}, &matcher) lambda do |thing| expected = eval(expected) if expected.is_a?(String) if block_given? thing.to_sexp(&matcher).inspect == expected.inspect else thing.to_sexp(opts).inspect == expected.inspect end end end
having_source(expected, opts={}, &matcher)
click to toggle source
# File lib/sourcify/spec/spec_helper.rb, line 61 def having_source(expected, opts={}, &matcher) lambda do |thing| #normalize_code(expected) # added for bug fixing normalize_code(block_given? ? thing.to_source(&matcher) : thing.to_source(opts)) \ == normalize_code(expected) end end
ikra_type()
click to toggle source
Returns the [Ikra::Types::RubyType] for this object. Instance of the same Ruby class can principally have different Ikra
types. Thus, this method is defined as an instance method.
# File lib/types/types/class_type.rb, line 143 def ikra_type if self.is_a?(Module) return self.singleton_class.to_ikra_type else # TODO: Double check if we always want to have the singleton class? return self.class.to_ikra_type end end
irb_exec(stdin_str)
click to toggle source
# File lib/sourcify/spec/spec_helper.rb, line 99 def irb_exec(stdin_str) # See http://tyenglog.heroku.com/2010/9/how-to-test-irb-specific-support & # http://tyenglog.heroku.com/2010/9/how-to-test-irb-specific-support-2- sourcify_rb = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'sourcify.rb') irb_feedback = /^ ?=> / irb_opts = '--simple-prompt' values = %x(echo "#{stdin_str}" | irb #{irb_opts} -r #{sourcify_rb}).split("\n"). grep(irb_feedback).map{|s| eval(s.sub(irb_feedback,'').strip) } # IRB behaves slightly differently in 1.9.2 for appending newline (values[-1].nil? && RUBY_VERSION =~ /1.9.(2|3)/) ? values[0 .. -2] : values end
m()
click to toggle source
# File lib/sourcify/spec/method/to_raw_source_w_specified_strip_enclosure_spec.rb, line 11 def m # i should stay !! end
m1()
click to toggle source
# File lib/sourcify/spec/method/encoding_from_def_end_block_spec.rb, line 7 def m1; "こんにちは"; end
m10()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb, line 108 def m10 x = :case end
m11()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb, line 119 def m11 x = :do end
m12()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb, line 130 def m12 x = :end end
m13()
click to toggle source
# File lib/sourcify/spec/method/to_source_magic_file_var_spec.rb, line 128 def m13; `echo #{__FILE__}`; end
m14()
click to toggle source
# File lib/sourcify/spec/method/to_source_magic_file_var_spec.rb, line 135 def m14; %W(#{__FILE__}); end
m15()
click to toggle source
# File lib/sourcify/spec/method/to_source_magic_file_var_spec.rb, line 142 def m15; '#{__FILE__}'; end
m16()
click to toggle source
# File lib/sourcify/spec/method/to_source_magic_file_var_spec.rb, line 149 def m16; %q(#{__FILE__}); end
m17()
click to toggle source
# File lib/sourcify/spec/method/to_source_magic_file_var_spec.rb, line 156 def m17; %w(#{__FILE__}); end
m18()
click to toggle source
# File lib/sourcify/spec/method/to_source_magic_file_var_spec.rb, line 163 def m18; "\#{__FILE__}"; end
m19()
click to toggle source
# File lib/sourcify/spec/method/to_source_magic_file_var_spec.rb, line 170 def m19; "__FILE__"; end
m2()
click to toggle source
NOTE: This specifically addresses github.com/ngty/sourcify/issues/15
# File lib/sourcify/spec/method/encoding_from_def_end_block_spec.rb, line 15 def m2; /\p{Lu}/ ; end
m3()
click to toggle source
# File lib/sourcify/spec/method/encoding_from_def_end_block_spec.rb, line 22 def m3 <<-EOL こんにちは EOL end
m4()
click to toggle source
# File lib/sourcify/spec/method/others_from_def_end_block_spec.rb, line 31 def m4; x; end
m5()
click to toggle source
# File lib/sourcify/spec/method/to_sexp_from_def_end_block_w_variables_spec.rb, line 39 def m5; $x; end
m6()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_for_spec.rb, line 77 def m6 for x1 in [2,3] for x2 in [2,3] x2 end end end
m7()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_for_spec.rb, line 96 def m7 for x1 in [3,4] for x2 in [3,4] do x2 end end end
m8()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_for_spec.rb, line 111 def m8 for x1 in [4,5] \ do for x2 in [4,5] do x2 end end end
m9()
click to toggle source
# File lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb, line 97 def m9 x = :begin end
normalize_code(code)
click to toggle source
# File lib/sourcify/spec/spec_helper.rb, line 57 def normalize_code(code) Ruby2Ruby.new.process(code_to_sexp(code)) end
pry_exec(stdin_str)
click to toggle source
# File lib/sourcify/spec/spec_helper.rb, line 112 def pry_exec(stdin_str) sourcify_rb = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'sourcify.rb') pry_opts = '--simple-prompt --no-color' results = [] %x(echo "#{stdin_str}" | pry #{pry_opts} -r #{sourcify_rb}). split("\n").each do |line| case line when /^((?:>> |)=> )/ results << [line.sub($1,'')] when /^( )/ results[-1] << line end end results = results.map{|lines| eval(lines.join) } results[-1].nil? ? results[0..-2] : results end
test(&block)
click to toggle source
# File lib/sourcify/spec/proc/created_on_the_fly_proc_spec.rb, line 7 def test(&block); block ; end
watever(*args, &block)
click to toggle source
# File lib/sourcify/spec/spec_helper.rb, line 43 def watever(*args, &block) Proc.new(&block) end