Sha256: 37ff88b54d57a397905994fe2e3d877baf32e042ae89d63148299d6b7088c806

Contents?: true

Size: 1.96 KB

Versions: 23

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

module SimpleCov
  class SourceFile
    #
    # Representing single branch that has been detected in coverage report.
    # Give us support methods that handle needed calculations.
    class Branch
      attr_reader :start_line, :end_line, :coverage, :type

      # rubocop:disable Metrics/ParameterLists
      def initialize(start_line:, end_line:, coverage:, inline:, type:)
        @start_line = start_line
        @end_line   = end_line
        @coverage   = coverage
        @inline     = inline
        @type       = type
        @skipped    = false
      end
      # rubocop:enable Metrics/ParameterLists

      def inline?
        @inline
      end

      #
      # Return true if there is relevant count defined > 0
      #
      # @return [Boolean]
      #
      def covered?
        !skipped? && coverage.positive?
      end

      #
      # Check if branche missed or not
      #
      # @return [Boolean]
      #
      def missed?
        !skipped? && coverage.zero?
      end

      # The line on which we want to report the coverage
      #
      # Usually we choose the line above the start of the branch (so that it shows up
      # at if/else) because that
      # * highlights the condition
      # * makes it distinguishable if the first line of the branch is an inline branch
      #   (see the nested_branches fixture)
      #
      def report_line
        if inline?
          start_line
        else
          start_line - 1
        end
      end

      # Flags the branch as skipped
      def skipped!
        @skipped = true
      end

      # Returns true if the branch was marked skipped by virtue of nocov comments.
      def skipped?
        @skipped
      end

      def overlaps_with?(line_range)
        start_line <= line_range.end && end_line >= line_range.begin
      end

      #
      # Return array with coverage count and badge
      #
      # @return [Array]
      #
      def report
        [type, coverage]
      end
    end
  end
end

Version data entries

23 entries across 22 versions & 8 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/simplecov-0.22.0/lib/simplecov/source_file/branch.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/simplecov-0.22.0/lib/simplecov/source_file/branch.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/simplecov-0.22.0/lib/simplecov/source_file/branch.rb
strongmind-simplecov-0.23.0 lib/simplecov/source_file/branch.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/simplecov-0.22.0/lib/simplecov/source_file/branch.rb
simplecov-0.22.0 lib/simplecov/source_file/branch.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/simplecov-0.21.2/lib/simplecov/source_file/branch.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/simplecov-0.21.2/lib/simplecov/source_file/branch.rb
simplecov-0.21.2 lib/simplecov/source_file/branch.rb
simplecov-0.21.1 lib/simplecov/source_file/branch.rb
simplecov-0.21.0 lib/simplecov/source_file/branch.rb
simplecov-0.20.0 lib/simplecov/source_file/branch.rb
simplecov-0.19.1 lib/simplecov/source_file/branch.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/simplecov-0.19.0/lib/simplecov/source_file/branch.rb
simplecov-0.19.0 lib/simplecov/source_file/branch.rb
simplecov-0.18.5 lib/simplecov/source_file/branch.rb
simplecov-0.18.4 lib/simplecov/source_file/branch.rb
simplecov-0.18.3 lib/simplecov/source_file/branch.rb
simplecov-0.18.2 lib/simplecov/source_file/branch.rb
simplecov-0.18.1 lib/simplecov/source_file/branch.rb