class Yadriggy::Assert::Reason
Reason
that an assertion fails.
Public Instance Methods
ast()
click to toggle source
Gets the AST of the block given to {Yadriggy::Assert::assertion}. @return [ASTnode] an abstract syntax tree.
# File lib/yadriggy/assert.rb, line 63 def ast() @ast end
results()
click to toggle source
Gets the detailed results. @return [Hash<ASTnode,Pair<String,Object>>] a map from sub-expressions
to their source and resulting vales. The sub-expressions are {ASTnode} objects.
# File lib/yadriggy/assert.rb, line 69 def results() @results end
setup(ast, results)
click to toggle source
@api private
# File lib/yadriggy/assert.rb, line 56 def setup(ast, results) @ast = ast @results = results end
show()
click to toggle source
Gets the text showing the values of the sub-expressions. @return [Array<String>] an array of lines.
# File lib/yadriggy/assert.rb, line 73 def show output = [] header = show2(@ast, '', output) output << header src, value = @results[ast] if src.nil? pp = PrettyPrinter.new(Printer.new(2)) pp.print(ast) output << pp.printer.output else output << src end output.reverse! end
show2(ast, header, output)
click to toggle source
@api private @return [String] the new header.
# File lib/yadriggy/assert.rb, line 90 def show2(ast, header, output) if ast.is_a?(Paren) show2(ast.expression, header + ' ', output) + ' ' elsif ast.is_a?(Call) && ast.block_arg.nil? && ast.block.nil? header2 = show2(ast.receiver, header, output) src2, value2 = @results[ast.receiver] src, value = @results[ast] if src.nil? src = PrettyPrinter.ast_to_s(ast) if src2.nil? "#{header}#{' ' * src.size}" else "#{header2}#{' ' * (src.size - src2.size)}" end else output << "#{header2} #{str_rep(value)}" "#{header2} |#{' ' * (src.size - src2.size - 2)}" end elsif ast.is_a?(Binary) header = show2(ast.left, header, output) src, value = @results[ast] if src.nil? header = header + ' ' else output << "#{header} #{str_rep(value)}" header = "#{header} | #{' ' * (ast.op.to_s.size - 1)}" end show2(ast.right, header, output) elsif ast.is_a?(Unary) src, value = @results[ast] if src.nil? header = header + ' ' else output << "#{header}#{str_rep(value)}" header = "#{header}|" end show2(ast.operand, header, output) else src, value = @results[ast] if src.nil? src = PrettyPrinter.ast_to_s(ast) return "#{header}#{' ' * src.size}" else output << header + str_rep(value) "#{header}|#{' ' * (src.size - 1)}" end end end
str_rep(v)
click to toggle source
@api private Obtains the text representation of the given value.
# File lib/yadriggy/assert.rb, line 141 def str_rep(v) max = 70 str = v.inspect if str.length < max str else str[0, max] + '...' end end