Sha256: 8e58d69e371a3571e34572d378bf0aae83741a2c3cc2ca7cffac617d75fe4a6c

Contents?: true

Size: 945 Bytes

Versions: 8

Compression:

Stored size: 945 Bytes

Contents

# frozen_string_literal: true

module DeepCover
  module Tools::FormatGeneratedCode
    def format_generated_code(covered_code)
      inserts = []
      generated_code = covered_code.instrument_source do |inserted, _node, expr_limit|
        inserts << [expr_limit, inserted.size]
        Term::ANSIColor.yellow(inserted)
      end

      inserts = inserts.sort_by { |exp, _| [exp.line, exp.column] }.reverse
      generated_lines = generated_code.split("\n")

      inserts.each do |exp_limit, size|
        # Line index starts at 1, so array index returns the next line
        comment_line = generated_lines[exp_limit.line]
        next unless comment_line.present?
        next unless comment_line.start_with?('#>')
        next if comment_line.start_with?('#>X')
        next unless comment_line.size >= exp_limit.column
        comment_line.insert(exp_limit.column, ' ' * size)
      end
      generated_lines.join("\n")
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
deep-cover-0.5.2 lib/deep_cover/tools/format_generated_code.rb
deep-cover-0.5.1 lib/deep_cover/tools/format_generated_code.rb
deep-cover-0.5.0 lib/deep_cover/tools/format_generated_code.rb
deep-cover-0.4.0 lib/deep_cover/tools/format_generated_code.rb
deep-cover-0.3.0 lib/deep_cover/tools/format_generated_code.rb
deep-cover-0.2.0 lib/deep_cover/tools/format_generated_code.rb
deep-cover-0.1.16 lib/deep_cover/tools/format_generated_code.rb
deep-cover-0.1.15 lib/deep_cover/tools/format_generated_code.rb