Class: VhdlDoctest::ResultFormatter
- Inherits:
-
Object
- Object
- VhdlDoctest::ResultFormatter
- Defined in:
- lib/vhdl_doctest/result_formatter.rb
Instance Method Summary collapse
- #compile_error? ⇒ Boolean
- #count_failure ⇒ Object
- #failed? ⇒ Boolean
-
#format ⇒ Object
pretty print error message.
-
#initialize(output) ⇒ ResultFormatter
constructor
A new instance of ResultFormatter.
-
#replace_binary(str) ⇒ Object
convert binary expression in a string to decimal.
- #succeeded? ⇒ Boolean
Constructor Details
#initialize(output) ⇒ ResultFormatter
Returns a new instance of ResultFormatter.
3 4 5 |
# File 'lib/vhdl_doctest/result_formatter.rb', line 3 def initialize(output) @output = output end |
Instance Method Details
#compile_error? ⇒ Boolean
23 24 25 |
# File 'lib/vhdl_doctest/result_formatter.rb', line 23 def compile_error? @output.include?("ghdl: compilation error") end |
#count_failure ⇒ Object
35 36 37 |
# File 'lib/vhdl_doctest/result_formatter.rb', line 35 def count_failure lines.select{ |l| l.match(/FAILED/) }.count end |
#failed? ⇒ Boolean
31 32 33 |
# File 'lib/vhdl_doctest/result_formatter.rb', line 31 def failed? @output.include?("FAILED") end |
#format ⇒ Object
pretty print error message
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vhdl_doctest/result_formatter.rb', line 8 def format if compile_error? "FAILED: Test did not run because of compilation error" else lines.reduce([]) do |formatted, l| if l.match(/(FAILED: .*) expected to (.*), but (.*)/) formatted << $1 formatted << " expected: " + $2 formatted << " actual: " + replace_binary($3) end formatted end.join("\n") end end |
#replace_binary(str) ⇒ Object
convert binary expression in a string to decimal
40 41 42 |
# File 'lib/vhdl_doctest/result_formatter.rb', line 40 def replace_binary(str) str.gsub(/[01]+/) { |bin| bin.to_i(2).to_s(10) } end |
#succeeded? ⇒ Boolean
27 28 29 |
# File 'lib/vhdl_doctest/result_formatter.rb', line 27 def succeeded? ! compile_error? && ! failed? end |