Class: TestBench::Output::Writer::Assertions::Line
- Inherits:
-
Object
- Object
- TestBench::Output::Writer::Assertions::Line
- Defined in:
- lib/test_bench/output/writer/assertions/line.rb
Constant Summary collapse
- IgnoreParameter =
Object.new
- Pattern =
%r{ \A (?<indentation>[[:space:]]{2})* (?<color> \e\[ (?:(?<brightness>[01])|(?<fg>3[0-7])|(?<bg>4[0-7])) (?: ;(?:(?<brightness>[01])|(?<fg>3[0-7])|(?<bg>4[0-7])) ){0,2} m )? (?<prose>[^\e\n]+) (?:\e\[0m)? \Z }x
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
Returns the value of attribute match.
Class Method Summary collapse
Instance Method Summary collapse
- #background_color?(bg) ⇒ Boolean
- #call(expected_prose, bg: IgnoreParameter, fg: IgnoreParameter, indentation: IgnoreParameter) ⇒ Object
- #foreground_color?(fg) ⇒ Boolean
- #indentation?(indentation) ⇒ Boolean
-
#initialize(match) ⇒ Line
constructor
A new instance of Line.
- #prose?(expected_prose) ⇒ Boolean
Constructor Details
#initialize(match) ⇒ Line
Returns a new instance of Line.
10 11 12 |
# File 'lib/test_bench/output/writer/assertions/line.rb', line 10 def initialize match @match = match end |
Instance Attribute Details
#match ⇒ Object (readonly)
Returns the value of attribute match.
8 9 10 |
# File 'lib/test_bench/output/writer/assertions/line.rb', line 8 def match @match end |
Class Method Details
.parse(line) ⇒ Object
14 15 16 17 |
# File 'lib/test_bench/output/writer/assertions/line.rb', line 14 def self.parse line match = Pattern.match line new match end |
Instance Method Details
#background_color?(bg) ⇒ Boolean
30 31 32 33 34 35 36 37 |
# File 'lib/test_bench/output/writer/assertions/line.rb', line 30 def background_color? bg if bg.nil? match['bg'].nil? else _, code = Palette.get bg match['bg'].to_i == code + 40 end end |
#call(expected_prose, bg: IgnoreParameter, fg: IgnoreParameter, indentation: IgnoreParameter) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/test_bench/output/writer/assertions/line.rb', line 19 def call expected_prose, bg: IgnoreParameter, fg: IgnoreParameter, indentation: IgnoreParameter return unless match return unless prose? expected_prose return unless foreground_color? fg unless fg == IgnoreParameter return unless background_color? bg unless bg == IgnoreParameter return unless indentation? indentation unless indentation == IgnoreParameter true end |
#foreground_color?(fg) ⇒ Boolean
39 40 41 42 43 44 45 46 47 |
# File 'lib/test_bench/output/writer/assertions/line.rb', line 39 def foreground_color? fg if fg.nil? match['fg'].nil? and match['brightness'].nil? else brightness, code = Palette.get fg match['fg'].to_i == code + 30 and match['brightness'].to_i == brightness end end |
#indentation?(indentation) ⇒ Boolean
49 50 51 |
# File 'lib/test_bench/output/writer/assertions/line.rb', line 49 def indentation? indentation match['indentation'].to_s == ' ' * indentation end |
#prose?(expected_prose) ⇒ Boolean
53 54 55 |
# File 'lib/test_bench/output/writer/assertions/line.rb', line 53 def prose? expected_prose match['prose'] == expected_prose end |