Class: Minitest::Heat::Output::SourceCode
- Inherits:
-
Object
- Object
- Minitest::Heat::Output::SourceCode
- Defined in:
- lib/minitest/heat/output/source_code.rb
Overview
Generates the tokens representing a specific set of source code lines
Constant Summary collapse
- DEFAULT_LINE_COUNT =
3
- DEFAULT_INDENTATION_SPACES =
2
- HIGHLIGHT_KEY_LINE =
true
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#max_line_count ⇒ Object
readonly
Returns the value of attribute max_line_count.
Instance Method Summary collapse
-
#highlight_key_line? ⇒ Boolean
Whether to visually highlight the target line when displaying the source code.
-
#indentation ⇒ type
The number of spaces each line of code should be indented.
-
#initialize(filename, line_number, max_line_count: DEFAULT_LINE_COUNT) ⇒ self
constructor
Provides a collection of tokens representing the output of source code.
-
#max_line_number_digits ⇒ Integer
The number of digits for the largest line number returned.
-
#tokens ⇒ Array<Array<Token>>
The collection of style content tokens to print.
Constructor Details
#initialize(filename, line_number, max_line_count: DEFAULT_LINE_COUNT) ⇒ self
Provides a collection of tokens representing the output of source code
21 22 23 24 25 26 |
# File 'lib/minitest/heat/output/source_code.rb', line 21 def initialize(filename, line_number, max_line_count: DEFAULT_LINE_COUNT) @filename = filename @line_number = line_number.to_s @max_line_count = max_line_count @tokens = [] end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
12 13 14 |
# File 'lib/minitest/heat/output/source_code.rb', line 12 def filename @filename end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
12 13 14 |
# File 'lib/minitest/heat/output/source_code.rb', line 12 def line_number @line_number end |
#max_line_count ⇒ Object (readonly)
Returns the value of attribute max_line_count.
12 13 14 |
# File 'lib/minitest/heat/output/source_code.rb', line 12 def max_line_count @max_line_count end |
Instance Method Details
#highlight_key_line? ⇒ Boolean
Whether to visually highlight the target line when displaying the source code. Currently
defauls to true, but long-term, this is a likely candidate to be configurable. For
example, in the future, highlighting could only be used if the source includes more than
three lines. Or it could be something end users could disable in order to reduce noise.
66 67 68 |
# File 'lib/minitest/heat/output/source_code.rb', line 66 def highlight_key_line? HIGHLIGHT_KEY_LINE end |
#indentation ⇒ type
The number of spaces each line of code should be indented. Currently defaults to 2 in
order to provide visual separation between test failures, but in the future, it could
be configurable in order to save horizontal space and create more compact output. For
example, it could be smart based on line length and total available horizontal terminal
space, or there could be higher-level "display" setting that could have a `:compact`
option that would reduce the space used.
78 79 80 |
# File 'lib/minitest/heat/output/source_code.rb', line 78 def indentation DEFAULT_INDENTATION_SPACES end |
#max_line_number_digits ⇒ Integer
The number of digits for the largest line number returned. This is used for formatting and
text justification so that line numbers are right-aligned
52 53 54 55 56 57 58 |
# File 'lib/minitest/heat/output/source_code.rb', line 52 def max_line_number_digits source .line_numbers .map(&:to_s) .map(&:length) .max end |
#tokens ⇒ Array<Array<Token>>
The collection of style content tokens to print
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/minitest/heat/output/source_code.rb', line 33 def tokens source.lines.each_index do |i| current_line_number = source.line_numbers[i] current_line_of_code = source.lines[i] number_style, line_style = styles_for(current_line_of_code) @tokens << [ line_number_token(number_style, current_line_number), line_of_code_token(line_style, current_line_of_code) ] end @tokens end |