1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/spec/commands/amend_line_spec.rb

248 lines
5.3 KiB
Ruby
Raw Normal View History

describe "amend-line" do
before do
@t = pry_tester
end
it 'should amend the last line of input when no line number specified' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
STR
@t.process_command 'amend-line puts :blah'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :blah
STR
end
it 'should amend the specified line of input when line number given' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
STR
@t.process_command 'amend-line 1 def goodbye'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def goodbye
puts :bing
puts :bang
STR
end
it 'should amend the first line of input when 0 given as line number' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
STR
@t.process_command 'amend-line 0 def goodbye'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def goodbye
puts :bing
puts :bang
STR
end
it 'should amend a specified line when negative number given' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
STR
@t.process_command 'amend-line -1 puts :bink'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :bing
puts :bink
STR
@t.process_command 'amend-line -2 puts :bink'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :bink
puts :bink
STR
end
it 'should amend a range of lines of input when negative numbers given' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
puts :boat
STR
@t.process_command 'amend-line -3..-2 puts :bink'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :bink
puts :boat
STR
end
it 'should correctly amend the specified line with interpolated text' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
STR
# rubocop:disable Lint/InterpolationCheck
@t.process_command 'amend-line puts "#{goodbye}"'
# rubocop:enable Lint/InterpolationCheck
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-'STR')
def hello
puts :bing
puts "#{goodbye}"
STR
end
it 'should display error if nothing to amend' do
error = nil
begin
@t.process_command 'amend-line'
rescue Pry::CommandError => e
error = e
end
2015-03-10 16:49:29 -04:00
expect(error).not_to equal nil
expect(error.message).to match(/No input to amend/)
end
it 'should correctly amend the specified range of lines' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
puts :heart
STR
@t.process_command 'amend-line 2..3 puts :bong'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :bong
puts :heart
STR
end
it 'should correctly delete a specific line using the ! for content' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
puts :boast
puts :heart
STR
@t.process_command 'amend-line 3 !'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :bing
puts :boast
puts :heart
STR
end
it 'should correctly delete a range of lines using the ! for content' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
puts :boast
puts :heart
STR
@t.process_command 'amend-line 2..4 !'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :heart
STR
end
it 'should correctly delete the previous line using the ! for content' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
puts :boast
puts :heart
STR
@t.process_command 'amend-line !'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :bing
puts :bang
puts :boast
STR
end
it 'should amend the specified range of lines, with numbers < 0 in range' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
puts :boast
puts :heart
STR
@t.process_command 'amend-line 2..-2 puts :bong'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :bong
puts :heart
STR
end
it 'should correctly insert a line before a specified line using >' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
STR
@t.process_command 'amend-line 2 > puts :inserted'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :inserted
puts :bing
puts :bang
STR
end
it 'should ignore second value of range with > syntax' do
2015-01-23 04:30:41 -05:00
@t.push(*unindent(<<-STR).split("\n"))
def hello
puts :bing
puts :bang
STR
@t.process_command 'amend-line 2..21 > puts :inserted'
2015-03-10 16:49:29 -04:00
expect(@t.eval_string).to eq unindent(<<-STR)
def hello
puts :inserted
puts :bing
puts :bang
STR
end
end