Sha256: 9541f70c74ae3e17eea08720c02a99cf38edf34770cf0a35113a3aaba3004529

Contents?: true

Size: 787 Bytes

Versions: 2

Compression:

Stored size: 787 Bytes

Contents

module SimpleCov
  # Classifies whether lines are relevant for code coverage analysis.
  # Comments & whitespace lines, and :nocov: token blocks, are considered not relevant.

  class LinesClassifier
    RELEVANT = 0
    NOT_RELEVANT = nil

    WHITESPACE_LINE = /^\s*$/
    COMMENT_LINE = /^\s*#/
    WHITESPACE_OR_COMMENT_LINE = Regexp.union(WHITESPACE_LINE, COMMENT_LINE)

    def self.no_cov_line
      /^(\s*)#(\s*)(\:#{SimpleCov.nocov_token}\:)/
    end

    def classify(lines)
      skipping = false

      lines.map do |line|
        if line =~ self.class.no_cov_line
          skipping = !skipping
          NOT_RELEVANT
        elsif skipping || line =~ WHITESPACE_OR_COMMENT_LINE
          NOT_RELEVANT
        else
          RELEVANT
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simplecov-0.15.1 lib/simplecov/lines_classifier.rb
simplecov-0.15.0 lib/simplecov/lines_classifier.rb