Sha256: 06fcbaa9d45dad6d48605244f14edc1183074a8aabeeffa12c7cd7eee90327d0

Contents?: true

Size: 943 Bytes

Versions: 10

Compression:

Stored size: 943 Bytes

Contents

require 'spec_helper'
require 'pry'

describe Snuffle::LineOfCode do

  class SourceFileMock
    include Ephemeral::Base
    collects :lines_of_code, class_name: "Snuffle::LineOfCode"
    attr_accessor :locs
  end

  let(:source_file) { SourceFileMock.new }

  let(:loc_1) { Snuffle::LineOfCode.new(range: (0..24) ) }
  let(:loc_2) { Snuffle::LineOfCode.new(range: (25..34)) }
  let(:loc_3) { Snuffle::LineOfCode.new(range: (35..44)) }

  before do
    source_file.lines_of_code << loc_1
    source_file.lines_of_code << loc_2
    source_file.lines_of_code << loc_3
  end

  describe ".find" do

    it "locates a range within a line" do
      locs = Snuffle::LineOfCode.containing(source_file.lines_of_code, 26, 34)
      expect(locs).to eq([loc_2])
    end

    it "locates a range spanning lines" do
      locs = Snuffle::LineOfCode.containing(source_file.lines_of_code, 26, 42)
      expect(locs).to eq([loc_2, loc_3])
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
snuffle-0.14.2 spec/snuffle/line_of_code_spec.rb
snuffle-0.14.1 spec/snuffle/line_of_code_spec.rb
snuffle-0.14.0 spec/snuffle/line_of_code_spec.rb
snuffle-0.13.0 spec/snuffle/line_of_code_spec.rb
snuffle-0.12.2 spec/snuffle/line_of_code_spec.rb
snuffle-0.12.1 spec/snuffle/line_of_code_spec.rb
snuffle-0.12.0 spec/snuffle/line_of_code_spec.rb
snuffle-0.11.1 spec/snuffle/line_of_code_spec.rb
snuffle-0.10.1 spec/snuffle/line_of_code_spec.rb
snuffle-0.9.1 spec/snuffle/line_of_code_spec.rb