Class: Test::Unit::Assertions::RubyReflector
- Inherits:
-
Object
- Object
- Test::Unit::Assertions::RubyReflector
show all
- Includes:
- Coulor
- Defined in:
- lib/assert2/ripper_reflector.rb,
lib/assert2.rb,
lib/assert2/rubynode_reflector.rb
Overview
this class turns hamburger back into live cattle
Defined Under Namespace
Classes: CallMethod, Nada, ScopeMethod
Constant Summary
collapse
- HAS_RUBYNODE =
false
- HAS_RIPPER =
false
Constants included
from Coulor
Coulor::BOLD, Coulor::CLEAR
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#__build_message(reflection) ⇒ Object
CONSIDER pass the same args as blocks take?.
-
#__evaluate_diagnostics ⇒ Object
-
#__reflect_assertion(called, options, block, got) ⇒ Object
-
#_alias(node) ⇒ Object
-
#_and(node, und = 'and') ⇒ Object
-
#_aref(*args) ⇒ Object
-
#_aref_field(*args) ⇒ Object
-
#_arg_paren(*args) ⇒ Object
-
#_args(node) ⇒ Object
_call and _fcall insert the real args.
-
#_args_add_block(*args) ⇒ Object
-
#_args_add_star(*args) ⇒ Object
-
#_argscat(node) ⇒ Object
-
#_array(node) ⇒ Object
-
#_assign(*args) ⇒ Object
-
#_assoc_new(*args) ⇒ Object
-
#_assoclist_from_args(*args) ⇒ Object
-
#_attrasgn(node) ⇒ Object
-
#_back_ref(node) ⇒ Object
-
#_bare_assoc_hash(*args) ⇒ Object
-
#_begin(node) ⇒ Object
-
#_binary(from, op, to) ⇒ Object
-
#_block(node) ⇒ Object
-
#_block_arg(node) ⇒ Object
-
#_block_pass(node) ⇒ Object
-
#_block_var(*args) ⇒ Object
-
#_blockarg(*args) ⇒ Object
-
#_body_stmt(*args) ⇒ Object
-
#_brace_block(*args) ⇒ Object
-
#_break(node) ⇒ Object
-
#_call(node) ⇒ Object
-
#_case(node) ⇒ Object
-
#_cdecl(node) ⇒ Object
-
#_class(node) ⇒ Object
-
#_class_name_error(args) ⇒ Object
-
#_colon2(node) ⇒ Object
-
#_colon3(node) ⇒ Object
-
#_command(*args) ⇒ Object
-
#_command_call(*args) ⇒ Object
-
#_const(node) ⇒ Object
ERGO raise if any other key!.
-
#_const_path_ref(*args) ⇒ Object
-
#_const_ref(*args) ⇒ Object
-
#_cvar(node) ⇒ Object
-
#_cvasgn(node) ⇒ Object
-
#_cvdecl(node) ⇒ Object
-
#_dasgn(node) ⇒ Object
-
#_dasgn_curr(node) ⇒ Object
-
#_def(*args) ⇒ Object
-
#_defined(node) ⇒ Object
-
#_defn(node) ⇒ Object
-
#_defs(node) ⇒ Object
-
#_do_block(*args) ⇒ Object
-
#_dot2(node) ⇒ Object
-
#_dot3(node) ⇒ Object
-
#_dregx(node) ⇒ Object
-
#_dregx_once(node) ⇒ Object
-
#_dstr(node, delim = '"') ⇒ Object
-
#_dsym(node) ⇒ Object
-
#_dvar(node) ⇒ Object
-
#_dxstr(node) ⇒ Object
-
#_dyna_symbol(*args) ⇒ Object
-
#_else(*args) ⇒ Object
-
#_elsif(*args) ⇒ Object
-
#_ensure(node) ⇒ Object
-
#_evstr(node) ⇒ Object
-
#_false(nada) ⇒ Object
-
#_fcall(node) ⇒ Object
-
#_field(*args) ⇒ Object
-
#_flip2(node) ⇒ Object
ERGO what the heck is this??.
-
#_for(node) ⇒ Object
-
#_gasgn(node) ⇒ Object
-
#_gvar(node) ⇒ Object
-
#_hash(node) ⇒ Object
-
#_iasgn(node) ⇒ Object
-
#_if(node) ⇒ Object
-
#_if_mod(*args) ⇒ Object
-
#_ifop(*args) ⇒ Object
-
#_iter(node) ⇒ Object
-
#_ivar(node) ⇒ Object
-
#_lasgn(node) ⇒ Object
-
#_lit(node) ⇒ Object
-
#_lvar(node) ⇒ Object
-
#_masgn(node) ⇒ Object
-
#_massign(*args) ⇒ Object
-
#_match(node) ⇒ Object
-
#_match2(node) ⇒ Object
-
#_match3(node) ⇒ Object
-
#_method(node) ⇒ Object
-
#_method_add_arg(*args) ⇒ Object
-
#_method_add_block(*args) ⇒ Object
-
#_method_missing(*args) ⇒ Object
-
#_mlhs_paren(*args) ⇒ Object
-
#_module(node, what = 'module') ⇒ Object
-
#_mrhs_add_star(*args) ⇒ Object
-
#_mrhs_new_from_args(*args) ⇒ Object
-
#_next(node) ⇒ Object
-
#_nil(nada) ⇒ Object
-
#_not(node) ⇒ Object
-
#_nth_ref(node) ⇒ Object
-
#_op_asgn1(node) ⇒ Object
ERGO just look up the list of these?.
-
#_op_asgn2(node) ⇒ Object
-
#_op_asgn_and(node) ⇒ Object
-
#_op_asgn_or(node, op = ' ||= ') ⇒ Object
-
#_opassign(*args) ⇒ Object
-
#_or(node) ⇒ Object
-
#_params(*args) ⇒ Object
CONSIDER just call cycle already!.
-
#_paren(*args) ⇒ Object
-
#_postexe(node) ⇒ Object
-
#_redo(node) ⇒ Object
-
#_regexp_literal(*args) ⇒ Object
-
#_resbody(node) ⇒ Object
-
#_rescue(node) ⇒ Object
-
#_rest_param(*args) ⇒ Object
-
#_retry(node) ⇒ Object
-
#_return(node) ⇒ Object
-
#_return0(*args) ⇒ Object
-
#_sclass(node) ⇒ Object
-
#_scope(node) ⇒ Object
-
#_self(node) ⇒ Object
-
#_send(node, thence = '') ⇒ Object
-
#_splat(node) ⇒ Object
-
#_str(node) ⇒ Object
-
#_string_concat(*args) ⇒ Object
-
#_string_content(*args) ⇒ Object
-
#_string_embexpr(*args) ⇒ Object
-
#_string_literal(*args) ⇒ Object
-
#_super(node) ⇒ Object
-
#_svalue(node) ⇒ Object
-
#_symbol(*args) ⇒ Object
-
#_symbol_literal(*args) ⇒ Object
-
#_to_ary(node) ⇒ Object
-
#_true(nada) ⇒ Object
-
#_unary(*args) ⇒ Object
-
#_undef(node) ⇒ Object
-
#_unless(*args) ⇒ Object
-
#_unless_mod(*args) ⇒ Object
-
#_until(node) ⇒ Object
-
#_valias(node) ⇒ Object
-
#_var_field(*args) ⇒ Object
-
#_var_ref(args) ⇒ Object
-
#_vcall(node) ⇒ Object
-
#_void_stmt(*args) ⇒ Object
-
#_when(node) ⇒ Object
-
#_while(node, concept = 'while') ⇒ Object
-
#_xstr(node) ⇒ Object
-
#_yield(node) ⇒ Object
-
#_yield0 ⇒ Object
-
#_zarray(node) ⇒ Object
-
#_zsuper(node) ⇒ Object
-
#absorb_block_args(code_fragments) ⇒ Object
CONSIDER a suckier way of detecting.
-
#arrow_result(result) ⇒ Object
-
#capture(&block) ⇒ Object
-
#capture_snip(snip, value) ⇒ Object
-
#capture_source ⇒ Object
-
#cycle(args, tween = nil) ⇒ Object
-
#delimit(what = ', ') ⇒ Object
-
#detect(expression) ⇒ Object
-
#diagnose(diagnostic, result, called, options, block, additional_diagnostics) ⇒ Object
-
#eval_intermediate(expression) ⇒ Object
-
#eval_parenz ⇒ Object
-
#extract_block(rippage = @ripped) ⇒ Object
-
#fcall_args(node = nil, methodic = false) ⇒ Object
-
#format_assertion_result(assertion_source, inspection) ⇒ Object
-
#format_capture(width, snip, value) ⇒ Object
-
#format_captures ⇒ Object
-
#format_evaluations ⇒ Object
ERGO spew the backrefs (?) any regular expression matchers may emit! ERGO don’t eval the caller of a block without its block!.
-
#format_inspection(inspection, spaces) ⇒ Object
TODO move this fluff to the ruby_reflector!.
-
#format_snip(width, snip) ⇒ Object
CONSIDER extract_block must not skip block-vars - intercept them here not down there.
-
#format_value(width, value) ⇒ Object
TODO width is a de-facto instance variable.
-
#head_body(node) ⇒ Object
-
#initialize(called = nil, yo_block = nil, reflect_values = true) ⇒ RubyReflector
constructor
note that a block, from your context, is not optional.
-
#measure_capture(kap) ⇒ Object
-
#neg_one(node) ⇒ Object
-
#nest_if(condition, before, after, &block) ⇒ Object
-
#recv_zero_self(node, plus = '') ⇒ Object
-
#reflect_assertion(block, got) ⇒ Object
-
#reflect_nodes(body_node) ⇒ Object
-
#reset(called) ⇒ Object
-
#rip(lines) ⇒ Object
-
#scrape_literal(node, regex = false) ⇒ Object
-
#sender(args) ⇒ Object
-
#sink(text) ⇒ Object
-
#split_and_read(called) ⇒ Object
-
#we_b(node) ⇒ Object
-
#we_b_op(node) ⇒ Object
-
#wrap(ldelim, rdelim = ldelim) ⇒ Object
TODO google for or claim ‘motion potion’.
Methods included from Coulor
#blue, #bold, #colorize, #colorize?, #colour, #green, #magenta, #orange, #red
Constructor Details
#initialize(called = nil, yo_block = nil, reflect_values = true) ⇒ RubyReflector
note that a block, from your context, is not optional
84
85
86
87
88
89
|
# File 'lib/assert2/rubynode_reflector.rb', line 84
def initialize(called = '')
reset(called)
@reflect = ''
@captures = []
@line_number = nil
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
113
114
115
|
# File 'lib/assert2.rb', line 113
def args
@args
end
|
#assertion_source ⇒ Object
Returns the value of attribute assertion_source.
10
11
12
|
# File 'lib/assert2/ripper_reflector.rb', line 10
def assertion_source
@assertion_source
end
|
#block=(yo_block) ⇒ Object
14
15
16
|
# File 'lib/assert2/ripper_reflector.rb', line 14
def block=(value)
@block = value
end
|
#captured_block_vars ⇒ Object
Returns the value of attribute captured_block_vars.
113
114
115
|
# File 'lib/assert2.rb', line 113
def captured_block_vars
@captured_block_vars
end
|
#captures ⇒ Object
Returns the value of attribute captures.
10
11
12
|
# File 'lib/assert2/ripper_reflector.rb', line 10
def captures
@captures
end
|
#evaluations ⇒ Object
Returns the value of attribute evaluations.
78
79
80
|
# File 'lib/assert2/rubynode_reflector.rb', line 78
def evaluations
@evaluations
end
|
#reflect ⇒ Object
Returns the value of attribute reflect.
10
11
12
|
# File 'lib/assert2/ripper_reflector.rb', line 10
def reflect
@reflect
end
|
#reflect_values=(value) ⇒ Object
Sets the attribute reflect_values
81
82
83
|
# File 'lib/assert2/rubynode_reflector.rb', line 81
def reflect_values=(value)
@reflect_values = value
end
|
#result ⇒ Object
Returns the value of attribute result.
78
79
80
|
# File 'lib/assert2/rubynode_reflector.rb', line 78
def result
@result
end
|
#ripped ⇒ Object
Returns the value of attribute ripped.
13
14
15
|
# File 'lib/assert2/ripper_reflector.rb', line 13
def ripped
@ripped
end
|
Returns the value of attribute transformation.
78
79
80
|
# File 'lib/assert2/rubynode_reflector.rb', line 78
def transformation
@transformation
end
|
Instance Method Details
#__build_message(reflection) ⇒ Object
CONSIDER pass the same args as blocks take?
133
134
135
136
|
# File 'lib/assert2.rb', line 133
def __build_message(reflection)
__evaluate_diagnostics
return (@__additional_diagnostics.uniq + [reflection]).compact.join("\n")
end
|
#__evaluate_diagnostics ⇒ Object
127
128
129
130
131
|
# File 'lib/assert2.rb', line 127
def __evaluate_diagnostics
@__additional_diagnostics.each_with_index do |d, x|
@__additional_diagnostics[x] = d.call if d.respond_to? :call
end
end
|
#__reflect_assertion(called, options, block, got) ⇒ Object
705
706
707
708
709
710
711
|
# File 'lib/assert2/ripper_reflector.rb', line 705
def __reflect_assertion(called, options, block, got)
effect = self
effect.args = *options[:args]
effect.block = block
reset(called)
return effect.reflect_assertion(block, got) end
|
#_alias(node) ⇒ Object
684
685
686
|
# File 'lib/assert2/ripper_reflector.rb', line 684
def _alias(*args)
cycle args, ' '
end
|
#_and(node, und = 'and') ⇒ Object
452
453
454
455
456
|
# File 'lib/assert2/rubynode_reflector.rb', line 452
def _and(node, und = 'and')
return eval_intermediate( '( ' +
eval_parenz{ first_(node)} + ' ' + und + ' ' +
eval_parenz{second_(node)} + ' )' )
end
|
#_aref(*args) ⇒ Object
446
447
448
449
450
451
|
# File 'lib/assert2/ripper_reflector.rb', line 446
def _aref(*args)
capture do
sender args.shift
wrap('[', ']'){ sender args.shift }
end
end
|
#_aref_field(*args) ⇒ Object
336
337
338
339
|
# File 'lib/assert2/ripper_reflector.rb', line 336
def _aref_field(*args)
sender args.shift
wrap('[', ']'){ sender args.shift }
end
|
#_arg_paren(*args) ⇒ Object
527
528
529
530
531
|
# File 'lib/assert2/ripper_reflector.rb', line 527
def _arg_paren(*args);
sink '('
cycle args, ', '
sink ')'
end
|
#_args(node) ⇒ Object
_call and _fcall insert the real args
380
|
# File 'lib/assert2/rubynode_reflector.rb', line 380
def _args(node); return ''; end
|
#_args_add_block(*args) ⇒ Object
625
626
627
628
629
630
631
632
633
634
635
636
637
638
|
# File 'lib/assert2/ripper_reflector.rb', line 625
def _args_add_block(*args)
baseline = @reflect.length
if args.first.first.class == Array
cycle args.shift, ', '
else
thing = args.shift
sender thing if thing.any?
end
if args.first
sink ', ' if @reflect.length > baseline
sink '&'
sender args.first
end
end
|
#_args_add_star(*args) ⇒ Object
309
310
311
312
313
314
315
316
|
# File 'lib/assert2/ripper_reflector.rb', line 309
def _args_add_star(*args)
delimit do
cycle args.shift, ', '
end
sink '*'
sender args.shift
end
|
#_argscat(node) ⇒ Object
813
814
815
816
|
# File 'lib/assert2/rubynode_reflector.rb', line 813
def _argscat(node)
return head_(node) + ', *' +
nest_if(node[:body].first == :array, '[', ']'){ body_(node) }
end
|
#_array(node) ⇒ Object
288
289
290
|
# File 'lib/assert2/ripper_reflector.rb', line 288
def _array(*args)
wrap('[', ']'){ cycle args, ', ' }
end
|
#_assign(*args) ⇒ Object
516
517
518
519
520
521
522
523
524
525
|
# File 'lib/assert2/ripper_reflector.rb', line 516
def _assign(*args)
sender args.shift
sink ' = '
if args.first.first.class == Array
wrap('[ ', ' ]'){ cycle args, ', ' }
else
cycle args, ', '
end
end
|
#_assoc_new(*args) ⇒ Object
610
611
612
|
# File 'lib/assert2/ripper_reflector.rb', line 610
def _assoc_new(*args)
cycle args, ' => '
end
|
#_assoclist_from_args(*args) ⇒ Object
469
470
471
|
# File 'lib/assert2/ripper_reflector.rb', line 469
def _assoclist_from_args(*args)
cycle args, ', '
end
|
#_attrasgn(node) ⇒ Object
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
# File 'lib/assert2/rubynode_reflector.rb', line 606
def _attrasgn(node)
recv, args = node.values_at(:recv, :args)
if args
if args.first == :array
if node[:mid].class == Symbol
if node[:mid] == :'[]='
return recv_zero_self(node) + '[' +
_send(args.last.first) + '] = ' +
_send(args.last.last)
end
return recv_zero_self(node, '.') + mid_(node) + '(' + _send(args.last.last) + ')'
end
end
return recv_zero_self(node) +
'[' + head_(args.last) + '] = ' +
body_(args.last)
end
return recv_zero_self(node, '.') + node[:mid].to_s.gsub(/=$/, '')
end
|
#_back_ref(node) ⇒ Object
458
|
# File 'lib/assert2/rubynode_reflector.rb', line 458
def _back_ref(node); '$' + node[:nth].chr; end
|
#_bare_assoc_hash(*args) ⇒ Object
250
|
# File 'lib/assert2/ripper_reflector.rb', line 250
def _bare_assoc_hash(*args); cycle args, ', '; end
|
#_begin(node) ⇒ Object
594
595
596
597
598
|
# File 'lib/assert2/ripper_reflector.rb', line 594
def _begin(*args)
sink "begin"
sender args.shift
sink "\nend"
end
|
#_binary(from, op, to) ⇒ Object
494
495
496
497
498
499
500
|
# File 'lib/assert2/ripper_reflector.rb', line 494
def _binary(from, op, to)
capture do
sender from
sink " #{op} "
sender to
end
end
|
#_block(node) ⇒ Object
199
200
201
|
# File 'lib/assert2/rubynode_reflector.rb', line 199
def _block(node)
return node.map{|n| _send(n, "\n") }.join
end
|
#_block_arg(node) ⇒ Object
704
705
706
|
# File 'lib/assert2/rubynode_reflector.rb', line 704
def _block_arg(node) return '' end
|
#_block_pass(node) ⇒ Object
650
651
652
653
654
655
|
# File 'lib/assert2/rubynode_reflector.rb', line 650
def _block_pass(node)
fcall = node[:iter].last
return eval_intermediate(recv_(fcall, '.') +
mid_(fcall) + '(' + args_(fcall, ', ') +
'&' + body_(node) + ')' )
end
|
#_block_var(*args) ⇒ Object
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
|
# File 'lib/assert2/ripper_reflector.rb', line 550
def _block_var(*args)
params = args.first[1]
rest_param = args.first[3]
blockarg = args.first[5]
sink '|'
cycle params, ', ' if params
if rest_param
sink ', ' if params
sender rest_param
end
if blockarg
sink ', ' if params or rest_param
sender blockarg
end
sink '| '
end
|
#_blockarg(*args) ⇒ Object
589
590
591
592
|
# File 'lib/assert2/ripper_reflector.rb', line 589
def _blockarg(*args)
sink '&'
sender args.first
end
|
#_body_stmt(*args) ⇒ Object
389
390
391
392
393
394
395
|
# File 'lib/assert2/ripper_reflector.rb', line 389
def _body_stmt(*args)
wrap "\n" do
cycle args.shift, "\n"
end
cycle args, "\n"
end
|
#_brace_block(*args) ⇒ Object
502
503
504
505
506
507
|
# File 'lib/assert2/ripper_reflector.rb', line 502
def _brace_block(*args)
sink '{ '
sender args.shift
cycle args.first, "\n"
sink ' }'
end
|
#_break(node) ⇒ Object
397
398
399
|
# File 'lib/assert2/ripper_reflector.rb', line 397
def _break(*args)
sink "break\n"
end
|
#_call(node) ⇒ Object
421
422
423
424
425
426
427
428
429
430
431
432
|
# File 'lib/assert2/ripper_reflector.rb', line 421
def _call(*args)
capture do
if args.first.first.class == Array
wrap('[ ', ' ]'){ cycle args.shift, ', ' }
else
sender args.shift
end
sink args.shift.to_s
sender args.shift
end
end
|
#_case(node) ⇒ Object
384
|
# File 'lib/assert2/rubynode_reflector.rb', line 384
def _case(node); '( case ' + head_body(node) + "\nend )"; end
|
#_cdecl(node) ⇒ Object
425
426
427
|
# File 'lib/assert2/rubynode_reflector.rb', line 425
def _cdecl(node)
return _send(node[ node[:vid] == 0 ? :else : :vid ]) + ' = ' + value_(node)
end
|
#_class(node) ⇒ Object
318
319
320
321
322
323
324
325
326
327
|
# File 'lib/assert2/ripper_reflector.rb', line 318
def _class(*args)
sink 'class '
args.compact.each do |arg|
sink ' < ' if arg == args[1]
sender arg
end
sink "\nend"
end
|
#_class_name_error(args) ⇒ Object
623
|
# File 'lib/assert2/ripper_reflector.rb', line 623
def _class_name_error(args); capture{ sender args }; end
|
#_colon2(node) ⇒ Object
459
|
# File 'lib/assert2/rubynode_reflector.rb', line 459
def _colon2(node); head_(node, '::') + mid_(node); end
|
#_colon3(node) ⇒ Object
460
|
# File 'lib/assert2/rubynode_reflector.rb', line 460
def _colon3(node); '::' + mid_(node); end
|
#_command(*args) ⇒ Object
237
238
239
240
241
242
243
244
245
246
247
248
|
# File 'lib/assert2/ripper_reflector.rb', line 237
def _command(*args)
capture do
args.each do |item|
if item.first.class == Symbol
sender item
sink ' ' if item == args.first
else
cycle item
end
end
end
end
|
#_command_call(*args) ⇒ Object
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/assert2/ripper_reflector.rb', line 200
def _command_call(*args)
sender args.shift
sink args.shift.to_s
sender args.shift
if args.first.compact != [:params]
sink ' '
end
cycle args
end
|
#_const(node) ⇒ Object
ERGO raise if any other key!
563
564
565
566
567
568
569
570
|
# File 'lib/assert2/rubynode_reflector.rb', line 563
def _const(node)
expression = vid_(node)
q = eval(expression, @block.binding)
eval_intermediate(expression) unless q.kind_of?(Module)
return expression
rescue return expression
end
|
#_const_path_ref(*args) ⇒ Object
434
435
436
437
438
439
440
441
|
# File 'lib/assert2/ripper_reflector.rb', line 434
def _const_path_ref(*args)
capture do
args.each do |arg|
sink '::' unless arg == args.first
sender arg
end
end
end
|
#_const_ref(*args) ⇒ Object
332
333
334
|
# File 'lib/assert2/ripper_reflector.rb', line 332
def _const_ref(*args)
capture{ sender args.last }
end
|
#_cvar(node) ⇒ Object
461
|
# File 'lib/assert2/rubynode_reflector.rb', line 461
def _cvar(node); _lvar(node); end
|
#_cvasgn(node) ⇒ Object
433
|
# File 'lib/assert2/rubynode_reflector.rb', line 433
def _cvasgn(node); _dasgn_curr(node); end
|
#_cvdecl(node) ⇒ Object
462
|
# File 'lib/assert2/rubynode_reflector.rb', line 462
def _cvdecl(node); vid_(node) + ' = ' + value_(node); end
|
#_dasgn(node) ⇒ Object
429
|
# File 'lib/assert2/rubynode_reflector.rb', line 429
def _dasgn(node); _dasgn_curr(node); end
|
#_dasgn_curr(node) ⇒ Object
416
417
418
419
420
421
422
423
|
# File 'lib/assert2/rubynode_reflector.rb', line 416
def _dasgn_curr(node)
expression = vid_(node)
return expression unless value = node[:value]
expression << ' = '
we_b_array = value.first == :array
expression << nest_if(we_b_array, '[', ']'){ value_(node) }
return expression
end
|
#_def(*args) ⇒ Object
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
# File 'lib/assert2/ripper_reflector.rb', line 341
def _def(*args) sink 'def '
sender args.shift
if args.first.first == :paren
wrap '(', ')' do
sender args.shift.last
end
elsif args.first.compact != [:params]
sink ' '
end
cycle args
sink "end"
end
|
#_defined(node) ⇒ Object
463
|
# File 'lib/assert2/rubynode_reflector.rb', line 463
def _defined(node); 'defined? ' + head_(node); end
|
#_defn(node) ⇒ Object
216
|
# File 'lib/assert2/rubynode_reflector.rb', line 216
def _defn(node); _defs(node); end
|
#_defs(node) ⇒ Object
357
358
359
360
361
|
# File 'lib/assert2/ripper_reflector.rb', line 357
def _defs(*args)
sink 'def '
cycle args
sink "end\n"
end
|
#_do_block(*args) ⇒ Object
509
510
511
512
513
514
|
# File 'lib/assert2/ripper_reflector.rb', line 509
def _do_block(*args)
sink " do\n"
sender args.shift
cycle args.first, "\n"
sink "\nend"
end
|
#_dot2(node) ⇒ Object
443
|
# File 'lib/assert2/ripper_reflector.rb', line 443
def _dot2(*args); cycle args, '..'; end
|
#_dot3(node) ⇒ Object
444
|
# File 'lib/assert2/ripper_reflector.rb', line 444
def _dot3(*args); cycle args, '...'; end
|
#_dregx(node) ⇒ Object
466
|
# File 'lib/assert2/rubynode_reflector.rb', line 466
def _dregx(node); _dstr(node, '/'); end
|
#_dregx_once(node) ⇒ Object
467
|
# File 'lib/assert2/rubynode_reflector.rb', line 467
def _dregx_once(node); _dstr(node, '/'); end
|
#_dstr(node, delim = '"') ⇒ Object
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
# File 'lib/assert2/rubynode_reflector.rb', line 578
def _dstr(node, delim = '"')
regex = delim == '/'
expression = delim + scrape_literal(node, regex)
if node[:next] and node[:next].first == :array
(node[:next].last || []).each do |n|
expression << if n.first == :str
scrape_literal(n.last, regex)
else
'#{ ' + _send(n) + ' }'
end
end
end
return eval_intermediate(expression + delim)
end
|
#_dsym(node) ⇒ Object
468
|
# File 'lib/assert2/rubynode_reflector.rb', line 468
def _dsym(node); ':' + _lit(node[:lit]) + ' ' + rest_(node); end
|
#_dvar(node) ⇒ Object
469
|
# File 'lib/assert2/rubynode_reflector.rb', line 469
def _dvar(node); eval_intermediate(vid_(node)); end
|
#_dxstr(node) ⇒ Object
470
|
# File 'lib/assert2/rubynode_reflector.rb', line 470
def _dxstr(node); _dstr(node, '`'); end
|
#_dyna_symbol(*args) ⇒ Object
269
270
271
272
273
|
# File 'lib/assert2/ripper_reflector.rb', line 269
def _dyna_symbol(*args)
@strung = true
wrap ':"', '"' do cycle args end
@strung = false
end
|
#_else(*args) ⇒ Object
477
478
479
480
|
# File 'lib/assert2/ripper_reflector.rb', line 477
def _else(*args)
sink "\nelse\n"
cycle args
end
|
#_elsif(*args) ⇒ Object
482
483
484
485
486
487
|
# File 'lib/assert2/ripper_reflector.rb', line 482
def _elsif(*args)
sink "\nelsif "
sender args.shift
sink "\n"
cycle args
end
|
#_ensure(node) ⇒ Object
416
417
418
419
|
# File 'lib/assert2/ripper_reflector.rb', line 416
def _ensure(*args)
sink "ensure\n"
cycle args, "\n"
end
|
#_evstr(node) ⇒ Object
472
|
# File 'lib/assert2/rubynode_reflector.rb', line 472
def _evstr(node); body_(node); end
|
#_false(nada) ⇒ Object
473
|
# File 'lib/assert2/rubynode_reflector.rb', line 473
def _false(nada); 'false'; end
|
#_fcall(node) ⇒ Object
489
|
# File 'lib/assert2/ripper_reflector.rb', line 489
def _fcall(*args); sender *args; end
|
#_field(*args) ⇒ Object
282
283
284
285
286
|
# File 'lib/assert2/ripper_reflector.rb', line 282
def _field(*args)
sender args.shift
sink args.shift.to_s
sender args.shift
end
|
#_flip2(node) ⇒ Object
ERGO what the heck is this??
495
496
497
498
499
|
# File 'lib/assert2/rubynode_reflector.rb', line 495
def _flip2(node) p node
p node.keys
return ''
end
|
#_for(node) ⇒ Object
363
364
365
366
367
368
369
370
371
|
# File 'lib/assert2/ripper_reflector.rb', line 363
def _for(*args)
sink 'for '
sender args.shift
sink ' in '
sender args.shift
sink "\n"
cycle args
sink "\nend"
end
|
#_gasgn(node) ⇒ Object
431
|
# File 'lib/assert2/rubynode_reflector.rb', line 431
def _gasgn(node); _dasgn_curr(node); end
|
#_gvar(node) ⇒ Object
474
|
# File 'lib/assert2/rubynode_reflector.rb', line 474
def _gvar(node); vid_(node); end
|
#_hash(node) ⇒ Object
473
474
475
|
# File 'lib/assert2/ripper_reflector.rb', line 473
def _hash(*args)
wrap('{ ', ' }'){ cycle args, ', ' }
end
|
#_iasgn(node) ⇒ Object
430
|
# File 'lib/assert2/rubynode_reflector.rb', line 430
def _iasgn(node); _dasgn_curr(node); end
|
#_if(node) ⇒ Object
359
360
361
362
363
364
365
|
# File 'lib/assert2/rubynode_reflector.rb', line 359
def _if(*args)
sink "if "
sender args.shift
sink "\n"
cycle args
sink "\nend"
end
|
#_if_mod(*args) ⇒ Object
655
656
657
658
659
|
# File 'lib/assert2/ripper_reflector.rb', line 655
def _if_mod(*args)
sender args.last
sink ' if '
sender args.first
end
|
#_ifop(*args) ⇒ Object
667
668
669
670
671
672
673
|
# File 'lib/assert2/ripper_reflector.rb', line 667
def _ifop(*args)
sender args.shift
sink ' ? '
sender args.shift
sink ' : '
sender args.shift
end
|
#_iter(node) ⇒ Object
657
658
659
660
661
662
663
664
665
666
|
# File 'lib/assert2/rubynode_reflector.rb', line 657
def _iter(node)
var = node[:var]
return eval_intermediate(
iter_(node) +
'{' +
nest_if(var != false, '|', '|'){ var_(node) unless var == 0 } +
nest_if(node[:body] , ' ', ' '){ body_(node) } +
'}')
end
|
#_ivar(node) ⇒ Object
475
|
# File 'lib/assert2/rubynode_reflector.rb', line 475
def _ivar(node); _dvar(node); end
|
#_lasgn(node) ⇒ Object
432
|
# File 'lib/assert2/rubynode_reflector.rb', line 432
def _lasgn(node); _dasgn_curr(node); end
|
#_lit(node) ⇒ Object
476
|
# File 'lib/assert2/rubynode_reflector.rb', line 476
def _lit(node); node[:lit].inspect; end
|
#_lvar(node) ⇒ Object
477
|
# File 'lib/assert2/rubynode_reflector.rb', line 477
def _lvar(node); eval_intermediate(vid_(node)); end
|
#_masgn(node) ⇒ Object
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
# File 'lib/assert2/rubynode_reflector.rb', line 501
def _masgn(node)
value, head, args = node.values_at(:value, :head, :args)
if value
return '( ' + head_(node) + ' = *' + head_(value.last) + ' )' if value.first == :splat
if head and args
exp = head_(node)
return exp + ', * = ' + value_(node) if args == -1
return exp + ', *' + args_(node) + ' = ' + value_(node)
end
return '( ' + head_(node) + ' = ' + value_(node) + ' )' if args == false
end
if value == false and head == false and args
return '*' + neg_one(args)
end
if head.kind_of?(Array) and head.first == :array
return head.last.map{|n|
nest_if(n.first == :masgn, '(', ')'){ _send(n) }
}.join(', ')
end
if head == false and args and value
return '*' + args_(node) + ' = ' + value_(node)
end
return head_(node)
end
|
#_massign(*args) ⇒ Object
640
641
642
643
644
|
# File 'lib/assert2/ripper_reflector.rb', line 640
def _massign(*args)
cycle args.shift, ', '
sink ' = '
cycle args
end
|
#_match(node) ⇒ Object
478
|
# File 'lib/assert2/rubynode_reflector.rb', line 478
def _match(node); node[:lit].inspect; end
|
#_match2(node) ⇒ Object
690
691
692
693
|
# File 'lib/assert2/rubynode_reflector.rb', line 690
def _match2(node)
return recv_(node) + ' =~ ' + value_(node)
end
|
#_match3(node) ⇒ Object
699
700
701
702
|
# File 'lib/assert2/rubynode_reflector.rb', line 699
def _match3(node)
return recv_(node) + ' =~ ' + _send(node[:lit] || node[:value])
end
|
#_method(node) ⇒ Object
209
210
211
212
|
# File 'lib/assert2/rubynode_reflector.rb', line 209
def _method(node)
p node
return ''
end
|
#_method_add_arg(*args) ⇒ Object
490
|
# File 'lib/assert2/ripper_reflector.rb', line 490
def _method_add_arg(*args); capture{ cycle args }; end
|
#_method_add_block(*args) ⇒ Object
491
|
# File 'lib/assert2/ripper_reflector.rb', line 491
def _method_add_block(*args); capture{ cycle args }; end
|
#_method_missing(*args) ⇒ Object
688
689
690
|
# File 'lib/assert2/ripper_reflector.rb', line 688
def _method_missing(*args)
puts " rippage = #{ args.pretty_inspect } "
end
|
#_mlhs_paren(*args) ⇒ Object
600
601
602
603
604
605
606
607
608
|
# File 'lib/assert2/ripper_reflector.rb', line 600
def _mlhs_paren(*args)
if args.first.first.class == Array
sink '('
cycle args.first, ', '
sink ')'
else
sender args.first
end
end
|
#_module(node, what = 'module') ⇒ Object
646
647
648
649
650
651
|
# File 'lib/assert2/ripper_reflector.rb', line 646
def _module(*args)
sink 'module '
sender args.shift
sender args.shift
sink 'end'
end
|
#_mrhs_add_star(*args) ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/assert2/ripper_reflector.rb', line 220
def _mrhs_add_star(*args)
sink '*'
sender args.last[1]
wrap '[', ']' do
cycle args.last[2..-1]
end
end
|
#_mrhs_new_from_args(*args) ⇒ Object
653
|
# File 'lib/assert2/ripper_reflector.rb', line 653
def _mrhs_new_from_args(*args) cycle args, ', ' end
|
#_next(node) ⇒ Object
383
|
# File 'lib/assert2/rubynode_reflector.rb', line 383
def _next(node); 'next' ; end
|
#_nil(nada) ⇒ Object
480
|
# File 'lib/assert2/rubynode_reflector.rb', line 480
def _nil(nada); 'nil' ; end
|
#_not(node) ⇒ Object
481
|
# File 'lib/assert2/rubynode_reflector.rb', line 481
def _not(node); '(not(' + body_(node) + '))'; end
|
#_nth_ref(node) ⇒ Object
482
|
# File 'lib/assert2/rubynode_reflector.rb', line 482
def _nth_ref(node); "$#{ node[:nth] }"; end
|
#_op_asgn1(node) ⇒ Object
ERGO just look up the list of these?
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
|
# File 'lib/assert2/rubynode_reflector.rb', line 788
def _op_asgn1(node) return '' unless args = node[:args]
exp = recv_(node)
if [:'-', :'+', :'*', :'**', :'/', :^, :|, :&,
:'<<', :'>>',
].include?(node[:mid]) and
node[:recv] and args.first == :argscat
return exp +
"[#{ body_(args.last) }] #{ node[:mid] }= " + head_(args.last)
end
raise "unexpected mid value #{ node[:mid].inspect } in opcode for X= " unless node[:mid] == 0
if args.first == :argscat and args.last[:body]
exp << '[' + body_(args.last) + ']'
exp << ' ||= ' + head_(args.last)
else
raise "unexpected arguments in opcode for ||= "
end
return exp
end
|
#_op_asgn2(node) ⇒ Object
435
436
437
438
439
440
441
442
443
444
445
446
447
|
# File 'lib/assert2/rubynode_reflector.rb', line 435
def _op_asgn2(node)
expression = ''
if node[:recv].first == :self
expression << 'self'
else
expression << recv_(node)
end
expression << '.'
expression << vid_(node[:next].last) + ' ||= ' + value_(node)
return expression
end
|
#_op_asgn_and(node) ⇒ Object
483
|
# File 'lib/assert2/rubynode_reflector.rb', line 483
def _op_asgn_and(node); _op_asgn_or(node, ' &&= '); end
|
#_op_asgn_or(node, op = ' ||= ') ⇒ Object
629
630
631
632
633
634
635
|
# File 'lib/assert2/rubynode_reflector.rb', line 629
def _op_asgn_or(node, op = ' ||= ')
return head_(node) + op + value_(node[:value].last)
end
|
#_opassign(*args) ⇒ Object
543
|
# File 'lib/assert2/ripper_reflector.rb', line 543
def _opassign(*args); cycle args, ' '; end
|
#_or(node) ⇒ Object
484
|
# File 'lib/assert2/rubynode_reflector.rb', line 484
def _or(node); _and(node, 'or'); end
|
#_params(*args) ⇒ Object
CONSIDER just call cycle already!
571
572
573
|
# File 'lib/assert2/ripper_reflector.rb', line 571
def _params(*args)
cycle args, ', '
end
|
#_paren(*args) ⇒ Object
583
584
585
586
587
|
# File 'lib/assert2/ripper_reflector.rb', line 583
def _paren(*args)
sink '('
cycle args.last, "\n"
sink ')'
end
|
#_postexe(node) ⇒ Object
406
407
408
409
|
# File 'lib/assert2/rubynode_reflector.rb', line 406
def _postexe(node)
raise '_postexe called with unexpected arguments' unless node == {} or node.keys == [:node]
return 'END'
end
|
#_redo(node) ⇒ Object
387
|
# File 'lib/assert2/rubynode_reflector.rb', line 387
def _redo(node); 'redo'; end
|
#_regexp_literal(*args) ⇒ Object
292
293
294
295
296
297
298
299
300
301
|
# File 'lib/assert2/ripper_reflector.rb', line 292
def _regexp_literal(*args)
capture do
regexp_end = args.pop
sender regexp_end
@strung = true
cycle args
@strung = false
sender regexp_end
end
end
|
#_resbody(node) ⇒ Object
337
338
339
340
|
# File 'lib/assert2/rubynode_reflector.rb', line 337
def _resbody(node)
return body_(node)
end
|
#_rescue(node) ⇒ Object
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
# File 'lib/assert2/ripper_reflector.rb', line 401
def _rescue(*args)
sink "rescue"
sink ' ' if args[0]
if args[0] and args[0].first.class == Array
cycle args[0]
else
sender args[0]
end
sink ' => ' if args[1]
sender args[1] if args[1]
cycle args[2], "\n"
end
|
#_rest_param(*args) ⇒ Object
545
546
547
548
|
# File 'lib/assert2/ripper_reflector.rb', line 545
def _rest_param(*args)
sink '*'
cycle args
end
|
#_retry(node) ⇒ Object
386
|
# File 'lib/assert2/rubynode_reflector.rb', line 386
def _retry(node); 'retry'; end
|
#_return(node) ⇒ Object
679
680
681
682
|
# File 'lib/assert2/ripper_reflector.rb', line 679
def _return(*args)
sink 'return '
cycle args, ', '
end
|
#_return0(*args) ⇒ Object
675
676
677
|
# File 'lib/assert2/ripper_reflector.rb', line 675
def _return0(*args)
sink 'return'
end
|
#_sclass(node) ⇒ Object
222
223
224
225
226
|
# File 'lib/assert2/rubynode_reflector.rb', line 222
def _sclass(node)
return 'class << ' + recv_(node) +
head_body(node) +
"end\n"
end
|
#_scope(node) ⇒ Object
311
312
313
|
# File 'lib/assert2/rubynode_reflector.rb', line 311
def _scope(node)
return ScopeMethod.new._scopic(self, node)
end
|
#_self(node) ⇒ Object
215
|
# File 'lib/assert2/rubynode_reflector.rb', line 215
def _self(node); 'self'; end
|
#_send(node, thence = '') ⇒ Object
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/assert2/rubynode_reflector.rb', line 177
def _send(node, thence = '')
return '' unless node
return node.to_s + thence if node.class == Symbol
target = :"_#{ node.first }"
last = node.last
(@line = last[:node].line) rescue nil
exp = send(target, last)
exp << thence if exp.length > 0
return exp
end
|
#_splat(node) ⇒ Object
554
555
556
557
558
559
560
561
|
# File 'lib/assert2/rubynode_reflector.rb', line 554
def _splat(node)
if (head = node[:head]) and
((we_b_array = head.first == :array) or head.first == :lvar)
return '*' + nest_if(we_b_array, '[', ']'){ head_(node) }
end
return '*' + head_(node)
end
|
#_str(node) ⇒ Object
485
|
# File 'lib/assert2/rubynode_reflector.rb', line 485
def _str(node); _lit(node); end
|
#_string_concat(*args) ⇒ Object
265
266
267
|
# File 'lib/assert2/ripper_reflector.rb', line 265
def _string_concat(*args)
cycle args, ' '
end
|
#_string_content(*args) ⇒ Object
261
262
263
|
# File 'lib/assert2/ripper_reflector.rb', line 261
def _string_content(*args)
cycle args end
|
#_string_embexpr(*args) ⇒ Object
275
276
277
278
279
280
|
# File 'lib/assert2/ripper_reflector.rb', line 275
def _string_embexpr(*args)
waz_strung = @strung
@strung = false
wrap '#{ ', ' }' do cycle args end
@strung = waz_strung
end
|
#_string_literal(*args) ⇒ Object
252
253
254
255
256
257
258
259
|
# File 'lib/assert2/ripper_reflector.rb', line 252
def _string_literal(*args)
capture do
waz_strung = @strung
@strung = true
wrap('"'){ cycle args }
@strung = waz_strung
end
end
|
#_super(node) ⇒ Object
211
212
213
214
|
# File 'lib/assert2/ripper_reflector.rb', line 211
def _super(*args)
sink 'super'
cycle args
end
|
#_svalue(node) ⇒ Object
486
|
# File 'lib/assert2/rubynode_reflector.rb', line 486
def _svalue(node); head_(node); end
|
#_symbol(*args) ⇒ Object
537
538
539
540
|
# File 'lib/assert2/ripper_reflector.rb', line 537
def _symbol(*args);
sink ':'
cycle args, ', '
end
|
#_symbol_literal(*args) ⇒ Object
533
534
535
|
# File 'lib/assert2/ripper_reflector.rb', line 533
def _symbol_literal(*args)
cycle args, ', '
end
|
#_to_ary(node) ⇒ Object
487
|
# File 'lib/assert2/rubynode_reflector.rb', line 487
def _to_ary(node); head_(node); end
|
#_true(nada) ⇒ Object
488
|
# File 'lib/assert2/rubynode_reflector.rb', line 488
def _true(nada); 'true' ; end
|
#_unary(*args) ⇒ Object
614
615
616
617
618
619
620
|
# File 'lib/assert2/ripper_reflector.rb', line 614
def _unary(*args)
capture do
sink arg = args.shift.to_s
sink ' ' if arg == 'not'
cycle args
end
end
|
#_undef(node) ⇒ Object
489
|
# File 'lib/assert2/rubynode_reflector.rb', line 489
def _undef(node); 'undef ' + mid_(node); end
|
#_unless(*args) ⇒ Object
461
462
463
464
465
466
467
|
# File 'lib/assert2/ripper_reflector.rb', line 461
def _unless(*args)
sink "unless "
sender args.shift
sink "\n"
cycle args
sink "\nend"
end
|
#_unless_mod(*args) ⇒ Object
661
662
663
664
665
|
# File 'lib/assert2/ripper_reflector.rb', line 661
def _unless_mod(*args)
sender args.last
sink ' unless '
sender args.first
end
|
#_until(node) ⇒ Object
373
374
375
376
377
378
379
|
# File 'lib/assert2/ripper_reflector.rb', line 373
def _until(*args)
sink 'until '
sender args.shift
sink "\n"
cycle args
sink "\nend"
end
|
#_valias(node) ⇒ Object
352
353
354
|
# File 'lib/assert2/rubynode_reflector.rb', line 352
def _valias(node)
return "alias #{ node[:new] } #{ node[:old] }"
end
|
#_var_field(*args) ⇒ Object
492
|
# File 'lib/assert2/ripper_reflector.rb', line 492
def _var_field(*args); cycle args, ', '; end
|
#_var_ref(args) ⇒ Object
622
|
# File 'lib/assert2/ripper_reflector.rb', line 622
def _var_ref(args); capture{ sender args }; end
|
#_vcall(node) ⇒ Object
490
|
# File 'lib/assert2/rubynode_reflector.rb', line 490
def _vcall(node); mid_(node); end
|
#_void_stmt(*args) ⇒ Object
329
330
|
# File 'lib/assert2/ripper_reflector.rb', line 329
def _void_stmt(*args)
end
|
#_when(node) ⇒ Object
385
|
# File 'lib/assert2/rubynode_reflector.rb', line 385
def _when(node); 'when ' + head_body(node) + "\n" + next_(node); end
|
#_while(node, concept = 'while') ⇒ Object
381
382
383
384
385
386
387
|
# File 'lib/assert2/ripper_reflector.rb', line 381
def _while(*args)
sink 'while '
sender args.shift
sink "\n"
cycle args
sink "\nend"
end
|
#_xstr(node) ⇒ Object
492
|
# File 'lib/assert2/rubynode_reflector.rb', line 492
def _xstr(node); '`' + scrape_literal(node) + '`'; end
|
#_yield(node) ⇒ Object
575
576
577
578
579
580
581
|
# File 'lib/assert2/ripper_reflector.rb', line 575
def _yield(*args)
if args.first.first == :paren
sink 'yield('
sender args.first.last
sink ')'
end
end
|
#_yield0 ⇒ Object
542
|
# File 'lib/assert2/ripper_reflector.rb', line 542
def _yield0; sink 'yield'; end
|
#_zarray(node) ⇒ Object
493
|
# File 'lib/assert2/rubynode_reflector.rb', line 493
def _zarray(node); return '[]'; end
|
#_zsuper(node) ⇒ Object
216
217
218
|
# File 'lib/assert2/ripper_reflector.rb', line 216
def _zsuper(*args)
sink 'super'
end
|
#absorb_block_args(code_fragments) ⇒ Object
CONSIDER a suckier way of detecting
108
109
110
111
112
113
|
# File 'lib/assert2/rubynode_reflector.rb', line 108
def absorb_block_args(code_fragments) @captured_block_vars = nil if code_fragments.first =~ /\|(.*)\|/ or code_fragments[1].to_s =~ /\|(.*)\|/
@captured_block_vars = $1
end
end
|
#arrow_result(result) ⇒ Object
841
842
843
|
# File 'lib/assert2/rubynode_reflector.rb', line 841
def arrow_result(result) return "\t--> #{ result.inspect }"
end
|
#capture(&block) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/assert2/ripper_reflector.rb', line 65
def capture(&block)
snip = capture_source(&block)
return if @captures.select{|k,v| k == snip }.length > 0
if @block
value = detect(snip)
capture_snip(snip, value) unless (value == Nada rescue false)
end
end
|
#capture_snip(snip, value) ⇒ Object
75
76
77
78
79
|
# File 'lib/assert2/ripper_reflector.rb', line 75
def capture_snip(snip, value)
return if snip =~ /^"(.*)"$/ and $1 == value
return if snip =~ /^\/(.*)\/$/ and $1.match(value) @captures << [snip, value]
end
|
#capture_source ⇒ Object
59
60
61
62
63
|
# File 'lib/assert2/ripper_reflector.rb', line 59
def capture_source
longness = @reflect.length
yield
return @reflect[longness..-1].strip
end
|
#cycle(args, tween = nil) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/assert2/ripper_reflector.rb', line 131
def cycle(args, tween = nil)
waz = false
args.each do |arg|
if arg and arg != []
sink tween if tween and waz
if arg.class == Array and arg.first.class == Array
cycle arg, tween
else
sender arg
end
waz = true
end
end
end
|
#delimit(what = ', ') ⇒ Object
303
304
305
306
307
|
# File 'lib/assert2/ripper_reflector.rb', line 303
def delimit(what = ', ')
longness = @reflect.length
yield
sink what if longness < @reflect.length
end
|
#detect(expression) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/assert2/ripper_reflector.rb', line 45
def detect(ident)
if @args and @captured_block_vars
ident = "#{@captured_block_vars} = $__args.kind_of?(Array) && $__args.length == 1 ? $__args.first : $__args\n" +
ident
$__args = @args
end
return eval(ident, @block.binding)
rescue ArgumentError => e
return Nada if e.message =~ /wrong number of arguments \(0 for /
return e.inspect
rescue Exception => e
return e.inspect
end
|
#diagnose(diagnostic, result, called, options, block, additional_diagnostics) ⇒ Object
713
714
715
716
717
718
719
720
721
|
# File 'lib/assert2/ripper_reflector.rb', line 713
def diagnose(diagnostic = nil, got = nil, called = caller[0],
options = {}, block = nil, additional_diagnostics)
@__additional_diagnostics = additional_diagnostics
options = { :args => [] }.merge(options)
@__additional_diagnostics.unshift diagnostic
return __build_message(__reflect_assertion(called, options, block, got))
end
|
138
139
140
141
|
# File 'lib/assert2/rubynode_reflector.rb', line 138
def eval_intermediate(expression)
detect(expression) if @reflect_values
return expression
end
|
#eval_parenz ⇒ Object
471
|
# File 'lib/assert2/rubynode_reflector.rb', line 471
def eval_parenz; eval_intermediate('( ' + yield + ' )'); end
|
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/assert2/ripper_reflector.rb', line 81
def (rippage = @ripped)
brace_block = rippage.first
brace_block = brace_block.last
if block_var = brace_block[1]
ripper = RubyReflector.new
ripper.sender block_var
@captured_block_vars = ripper.reflect.sub(/^\|/, '').sub(/\| $/, '')
end
return brace_block[2]
end
|
#fcall_args(node = nil, methodic = false) ⇒ Object
637
638
639
640
641
642
|
# File 'lib/assert2/rubynode_reflector.rb', line 637
def fcall_args(node = nil, methodic = false)
expression = ''
return expression unless node
expression << ' ' unless methodic
return expression + nest_if(methodic, '(', ')'){ _send(node) }
end
|
145
146
147
148
149
|
# File 'lib/assert2.rb', line 145
def format_assertion_result(assertion_source, inspection)
spaces = " --> ".length
inspection = format_inspection(inspection, spaces)
return assertion_source.rstrip + "\n --> #{inspection.lstrip}\n"
end
|
151
152
153
|
# File 'lib/assert2.rb', line 151
def format_capture(width, snip, value)
return "#{ format_snip(width, snip) } --> #{ format_value(width, value) }"
end
|
121
122
123
124
125
126
127
128
129
|
# File 'lib/assert2/ripper_reflector.rb', line 121
def format_captures
width = @captures.inject(0){|x, (k, v)|
e = measure_capture(k)
x < e ? e : x
}
return @captures.map{|snip, capture|
format_capture width, snip, capture
}.join("\n")
end
|
ERGO spew the backrefs (?) any regular expression matchers may emit!
ERGO don't eval the caller of a block without its block!
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/assert2/rubynode_reflector.rb', line 156
def format_evaluations
max_line = @evaluations.map{|exp, val, prob| exp.length}.sort.last
already = {}
lines = []
@evaluations.each do |exp, val, prob|
line = " #{ exp.center(max_line) } "
line << if prob then
orange('--? ' + prob)
else
green('--> ') + bold(short_inspect(val))
end
lines << line unless already[line] == true
already[line] = true
end
return lines.compact.join("\n")
end
|
TODO move this fluff to the ruby_reflector!
138
139
140
141
142
143
|
# File 'lib/assert2.rb', line 138
def format_inspection(inspection, spaces)
spaces = ' ' * spaces
inspection = inspection.gsub('\n'){ "\\n\" +\n \"" } if inspection =~ /^".*"$/
inspection = inspection.gsub("\n"){ "\n" + spaces }
return inspection.lstrip
end
|
CONSIDER extract_block must not skip block-vars - intercept
them here not down there
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/assert2/ripper_reflector.rb', line 98
def format_snip(width, snip)
snips = snip.split("\n")
if snips.length > 1 and
snips.inject(0){|x, v| v.strip.length > x ? v.strip.length : x } <= width snips.last.replace("%*s" % [width, snips.last.strip])
return snips.join("\n")
end
return "%*s" % [width, snip] if snip.length <= width
chop = snip.scan(/(\w+[[:punct:]]?)/).flatten
snip = ''
length = 0
chop.each do |snippet|
(snip << "\n"; length = 0) if length + snippet.length > width
snip << snippet
length += snippet.length
end
return snip.split("\n").map{|snippet| format_snip(width, snippet) }.join("\n")
end
|
TODO width is a de-facto instance variable
155
156
157
158
159
|
# File 'lib/assert2.rb', line 155
def format_value(width, value) width += 4
source = value.pretty_inspect.rstrip
return format_inspection(source, width)
end
|
#head_body(node) ⇒ Object
388
|
# File 'lib/assert2/rubynode_reflector.rb', line 388
def head_body(node); head_(node) + "\n" + body_(node); end
|
#measure_capture(kap) ⇒ Object
161
162
163
164
165
|
# File 'lib/assert2.rb', line 161
def measure_capture(kap)
return kap.split("\n").inject(0){|x, v| v.strip.length > x ? v.strip.length : x } if kap.match("\n")
kap.length
end
|
#neg_one(node) ⇒ Object
479
|
# File 'lib/assert2/rubynode_reflector.rb', line 479
def neg_one(node); node == -1 ? '' : _send(node); end
|
#nest_if(condition, before, after, &block) ⇒ Object
780
781
782
783
784
785
786
|
# File 'lib/assert2/rubynode_reflector.rb', line 780
def nest_if(condition, before, after, &block)
exp = ''
exp << before if condition
exp << (block.call || '')
exp << after if condition
return exp
end
|
#recv_zero_self(node, plus = '') ⇒ Object
600
601
602
603
604
|
# File 'lib/assert2/rubynode_reflector.rb', line 600
def recv_zero_self(node, plus = '')
recv = node[:recv]
return 'self' + plus if recv == 0
return recv_(node, plus)
end
|
#reflect_assertion(block, got) ⇒ Object
692
693
694
695
696
697
698
699
700
701
702
703
|
# File 'lib/assert2/ripper_reflector.rb', line 692
def reflect_assertion(block, got)
self.block = block
.each do |statement|
sender statement
end
inspection = got.pretty_inspect
return format_assertion_result(assertion_source, inspection) +
format_captures
end
|
#reflect_nodes(body_node) ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/assert2/rubynode_reflector.rb', line 98
def reflect_nodes(body_node)
if body_node
@transformation = body_node.transform(:include_node => true)
return @result = _send(@transformation)
end
rescue
puts "\nOffending line: #{ @line }"
raise
end
|
#reset(called) ⇒ Object
23
24
25
26
|
# File 'lib/assert2/ripper_reflector.rb', line 23
def reset(called)
source = split_and_read(called)
@ripped = rip(source) if source
end
|
#rip(lines) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/assert2/ripper_reflector.rb', line 28
def rip(lines)
lines = [lines].flatten
x = 0
until exp = Ripper.sexp(@assertion_source = lines[0..x].join)
(x += 1) >= lines.length and
raise 'your assertion failed, but your source is ' +
'incorrectly formatted and resists reflection!' +
"\nSee: http://assert2.rubyforge.org/assert21.html#Warning_Put_Assertions_on_Separate_Lines\n"
lines.inspect
end
return exp.last
end
|
#scrape_literal(node, regex = false) ⇒ Object
572
573
574
575
576
|
# File 'lib/assert2/rubynode_reflector.rb', line 572
def scrape_literal(node, regex = false)
lit = node[:lit].inspect.gsub(/^"/, '').gsub(/"$/, '')
lit.gsub!('\\\\', '\\') if regex
return lit
end
|
#sender(args) ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/assert2/ripper_reflector.rb', line 150
def sender(args)
if args.inspect =~ /, \[(\d+), \d+\]\]$/
lineno = $1.to_i
@line_number ||= lineno
if @line_number < lineno
@reflect << "\n "
@line_number = lineno
end
end
send :"_#{args[0]}", *args[1..-1] if args
end
|
#sink(text) ⇒ Object
146
147
148
|
# File 'lib/assert2/ripper_reflector.rb', line 146
def sink(text)
@reflect << text
end
|
#split_and_read(called) ⇒ Object
118
119
120
121
122
123
124
125
|
# File 'lib/assert2.rb', line 118
def split_and_read(called)
if called + ':' =~ /([^:]+):(\d+):/
file, line = $1, $2.to_i
return File.readlines(file)[line - 1 .. -1]
end
return nil
end
|
#we_b(node) ⇒ Object
491
|
# File 'lib/assert2/rubynode_reflector.rb', line 491
def we_b(node); node.first.first; end
|
#we_b_op(node) ⇒ Object
695
696
697
|
# File 'lib/assert2/rubynode_reflector.rb', line 695
def we_b_op(node)
return node[:mid] && node[:mid].to_s !~ /^[a-z]/i
end
|
#wrap(ldelim, rdelim = ldelim) ⇒ Object
TODO google for or claim ‘motion potion’
166
167
168
169
170
|
# File 'lib/assert2/ripper_reflector.rb', line 166
def wrap(ldelim, rdelim = ldelim)
sink ldelim
yield
sink rdelim
end
|