Sha256: 31bd616d521f4244dbc4d70f7b62f01ba5575090460e2eb579b4304129a982fb

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require File.expand_path('../spec_helper', __FILE__)

module Act
  describe Helper do

    before do
      @subject = Helper
    end

    #-------------------------------------------------------------------------#

    describe 'select_lines' do

      it 'returns the lines corresponding to the given range' do
        string = "1\n2\n3\n4"
        result = @subject.select_lines(string, 1, 2)
        result.should == "1\n2\n"
      end

      it 'use a one-based index' do
        string = "index\nanother"
        result = @subject.select_lines(string, 1, 1)
        result.should == "index\n"
      end

      it 'returns nil if the range is malformed' do
        string = "1\n2\n3\n4"
        result = @subject.select_lines(string, 2, 1)
        result.should.nil
      end

      it 'returns nil if the range is outside the lines of the string' do
        string = "1\n2\n3\n4"
        result = @subject.select_lines(string, 10, 11)
        result.should.nil
      end

      it 'returns the matched part if the range is partially outside the lines of the string' do
        string = "1\n2\n3\n4"
        result = @subject.select_lines(string, 3, 10)
        result.should == "3\n4"
      end

      it 'handles negative line numbers' do
        string = "1\n2\n3\n4"
        result = @subject.select_lines(string, -2, 2)
        result.should == "1\n2\n"
      end

    end

    #-------------------------------------------------------------------------#

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
act-0.0.2 spec/helper_spec.rb