File: site.rb

package info (click to toggle)
ruby-parslet 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,260 kB
  • sloc: ruby: 6,157; sh: 8; javascript: 3; makefile: 3
file content (56 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class Site
  attr_reader :original_line
  
  def initialize(original_line, code, expectation)
    @original_line = original_line
    @code = code
    @expectation = expectation
    @values = []
  end
  def id
    object_id
  end
  
  def to_instrumented_line
    "begin "+
      "(#@code).tap { |o| $instrumentation.put [#{id}, [:ok, o]] }; "+
    "rescue Exception => exception; "+
      "$instrumentation.put [#{id}, [:raised, exception]];"+
      "raise;"+
    "end"
  end
  
  def format_documentation_line
    value_str = format_values
    "#@code# => #{value_str}"
  end
  def format_values
    return 'NOT REACHED!' if @values.empty?
    
    v = @values.size == 1 ? @values.first : @values
    s = v.inspect
    
    max_len = 60 - 3
    s.size > max_len ? s[0,max_len] + '...' : s
  end
  def check
    return true if !@expectation || @expectation.match(/^\s*$/)

    str = format_values
    if str != @expectation
      puts "      #{@code.strip} # => #{str.red}"
      puts "      #{' '*@code.strip.size} # expected: #@expectation"
    else
      puts "      #{@code.strip} # => #{str.green}"
    end
  end
  def store(msg)
    store_if(:ok, msg)
  end
  
private
  def store_if(cond, msg)
    code, value = msg 
    @values << value if code == cond
  end
end