2021-03-11 10:09:10 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Gitlab::MarkerRange do
|
|
|
|
subject(:marker_range) { described_class.new(first, last, mode: mode) }
|
|
|
|
|
|
|
|
let(:first) { 1 }
|
|
|
|
let(:last) { 10 }
|
|
|
|
let(:mode) { nil }
|
|
|
|
|
2021-03-22 23:09:04 -04:00
|
|
|
it { expect(marker_range.to_range).to eq(first..last) }
|
2021-03-11 10:09:10 -05:00
|
|
|
|
|
|
|
it 'behaves like a Range' do
|
|
|
|
is_expected.to be_kind_of(Range)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#mode' do
|
|
|
|
subject { marker_range.mode }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
|
|
|
|
context 'when mode is provided' do
|
|
|
|
let(:mode) { :deletion }
|
|
|
|
|
|
|
|
it { is_expected.to eq(mode) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#to_range' do
|
|
|
|
subject { marker_range.to_range }
|
|
|
|
|
|
|
|
it { is_expected.to eq(first..last) }
|
|
|
|
|
|
|
|
context 'when mode is provided' do
|
|
|
|
let(:mode) { :deletion }
|
|
|
|
|
|
|
|
it 'is omitted during transformation' do
|
|
|
|
is_expected.not_to respond_to(:mode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.from_range' do
|
|
|
|
subject { described_class.from_range(range) }
|
|
|
|
|
|
|
|
let(:range) { 1..3 }
|
|
|
|
|
|
|
|
it 'converts Range to MarkerRange object' do
|
|
|
|
is_expected.to be_a(described_class)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'keeps correct range' do
|
2021-03-22 23:09:04 -04:00
|
|
|
is_expected.to eq(described_class.new(1, 3))
|
2021-03-11 10:09:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when range excludes end' do
|
|
|
|
let(:range) { 1...3 }
|
|
|
|
|
|
|
|
it 'keeps correct range' do
|
2021-03-22 23:09:04 -04:00
|
|
|
is_expected.to eq(described_class.new(1, 3, exclude_end: true))
|
2021-03-11 10:09:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when range is already a MarkerRange' do
|
|
|
|
let(:range) { marker_range }
|
|
|
|
|
|
|
|
it { is_expected.to be(marker_range) }
|
|
|
|
end
|
|
|
|
end
|
2021-03-22 23:09:04 -04:00
|
|
|
|
|
|
|
describe '#==' do
|
|
|
|
subject { default_marker_range == another_marker_range }
|
|
|
|
|
|
|
|
let(:default_marker_range) { described_class.new(0, 1, mode: :addition) }
|
|
|
|
let(:another_marker_range) { default_marker_range }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
|
|
|
|
context 'when marker ranges have different modes' do
|
|
|
|
let(:another_marker_range) { described_class.new(0, 1, mode: :deletion) }
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when marker ranges have different ranges' do
|
|
|
|
let(:another_marker_range) { described_class.new(0, 2, mode: :addition) }
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when marker ranges is a simple range' do
|
|
|
|
let(:another_marker_range) { (0..1) }
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2021-03-11 10:09:10 -05:00
|
|
|
end
|