module EvalExpectationsOnAST
Public Instance Methods
check_repeat_of(target)
click to toggle source
# File lib/expectations_hook.rb, line 28 def check_repeat_of(target) use(/AST\(repeat\s*#{target}/) end
eval_in_gobstones(binding, ast)
click to toggle source
# File lib/expectations_hook.rb, line 8 def eval_in_gobstones(binding, ast) pattern_generator = expectations[type] result = pattern_generator ? !!(ast =~ pattern_generator[binding]) : true negated ? !result : result end
expectations()
click to toggle source
# File lib/expectations_hook.rb, line 32 def expectations { 'HasBinding' => lambda { |binding| subject_for(binding).ast_regexp }, 'HasForeach' => use(/AST\(foreach/), 'HasRepeat' => check_repeat_of('.+'), 'HasVariable' => use(/AST\(assignVarName/), 'HasWhile' => use(/AST\(while/), 'HasArity' => lambda { |binding| /#{subject_for(binding).ast_regexp}\s*AST\((\s*\w+){#{target}}\)/ }, 'HasRepeatOf' => check_repeat_of("AST\\(literal\\s*#{target}\\)"), 'HasUsage' => use(/AST\((proc|func)Call\s*#{target}$/) } end
subject_for(binding)
click to toggle source
# File lib/expectations_hook.rb, line 20 def subject_for(binding) if binding == 'program' StonesSpec::Subject::Program else StonesSpec::Subject.from(binding) end end
use(regexp)
click to toggle source
# File lib/expectations_hook.rb, line 16 def use(regexp) lambda { |_| regexp } end