2014-03-14 00:31:24 -04:00
|
|
|
require_relative '../../helper'
|
2013-12-14 10:12:36 -05:00
|
|
|
|
2013-12-14 10:56:19 -05:00
|
|
|
describe Pry::Command::Cat::FileFormatter do
|
|
|
|
describe "#file_and_line" do
|
|
|
|
before do
|
|
|
|
@p = Pry.new
|
|
|
|
@opt = Slop.new
|
|
|
|
Pry::Code.stubs(:from_file)
|
2013-12-14 10:12:36 -05:00
|
|
|
end
|
|
|
|
|
2013-12-14 10:56:19 -05:00
|
|
|
after do
|
|
|
|
Pry::Code.unstub(:from_file)
|
2013-12-14 10:12:36 -05:00
|
|
|
end
|
|
|
|
|
2013-12-14 10:56:19 -05:00
|
|
|
describe "windows filesystem" do
|
|
|
|
it "should parse '/'style absolute path without line_num" do
|
|
|
|
file_with_embedded_line = "C:/Ruby193/pry_instance.rb"
|
|
|
|
ff = Pry::Command::Cat::FileFormatter.new(file_with_embedded_line, @p, @opt)
|
|
|
|
file_name, line_num = ff.file_and_line
|
|
|
|
file_name.should == "C:/Ruby193/pry_instance.rb"
|
|
|
|
line_num.should == nil
|
|
|
|
end
|
2013-12-14 10:12:36 -05:00
|
|
|
|
2013-12-14 10:56:19 -05:00
|
|
|
it "should parse '/'style absolute path with line_num" do
|
|
|
|
file_with_embedded_line = "C:/Ruby193/pry_instance.rb:2"
|
|
|
|
ff = Pry::Command::Cat::FileFormatter.new(file_with_embedded_line, @p, @opt)
|
|
|
|
file_name, line_num = ff.file_and_line
|
|
|
|
file_name.should == "C:/Ruby193/pry_instance.rb"
|
|
|
|
line_num.should == 2
|
|
|
|
end
|
2013-12-14 10:12:36 -05:00
|
|
|
|
2013-12-14 10:56:19 -05:00
|
|
|
it "should parse '\\'style absolute path without line_num" do
|
|
|
|
file_with_embedded_line = "C:\\Ruby193\\pry_instance.rb"
|
|
|
|
ff = Pry::Command::Cat::FileFormatter.new(file_with_embedded_line, @p, @opt)
|
|
|
|
file_name, line_num = ff.file_and_line
|
|
|
|
file_name.should == "C:\\Ruby193\\pry_instance.rb"
|
|
|
|
line_num.should == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should parse '\\'style absolute path with line_num" do
|
|
|
|
file_with_embedded_line = "C:\\Ruby193\\pry_instance.rb:2"
|
|
|
|
ff = Pry::Command::Cat::FileFormatter.new(file_with_embedded_line, @p, @opt)
|
|
|
|
file_name, line_num = ff.file_and_line
|
|
|
|
file_name.should == "C:\\Ruby193\\pry_instance.rb"
|
|
|
|
line_num.should == 2
|
|
|
|
end
|
2013-12-14 10:12:36 -05:00
|
|
|
end
|
|
|
|
|
2013-12-14 10:56:19 -05:00
|
|
|
describe "UNIX-like filesystem" do
|
|
|
|
it "should parse absolute path without line_num" do
|
|
|
|
file_with_embedded_line = "/Ruby193/pry_instance.rb"
|
|
|
|
ff = Pry::Command::Cat::FileFormatter.new(file_with_embedded_line, @p, @opt)
|
|
|
|
file_name, line_num = ff.file_and_line
|
|
|
|
file_name.should == "/Ruby193/pry_instance.rb"
|
|
|
|
line_num.should == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should parse absolute path with line_num" do
|
|
|
|
file_with_embedded_line = "/Ruby193/pry_instance.rb:2"
|
|
|
|
ff = Pry::Command::Cat::FileFormatter.new(file_with_embedded_line, @p, @opt)
|
|
|
|
file_name, line_num = ff.file_and_line
|
|
|
|
file_name.should == "/Ruby193/pry_instance.rb"
|
|
|
|
line_num.should == 2
|
|
|
|
end
|
2013-12-14 10:12:36 -05:00
|
|
|
end
|
|
|
|
|
2013-12-14 10:56:19 -05:00
|
|
|
it "should parse relative path without line_num" do
|
2013-12-14 10:12:36 -05:00
|
|
|
file_with_embedded_line = "pry_instance.rb"
|
|
|
|
ff = Pry::Command::Cat::FileFormatter.new(file_with_embedded_line, @p, @opt)
|
|
|
|
file_name, line_num = ff.file_and_line
|
|
|
|
file_name.should == "pry_instance.rb"
|
|
|
|
line_num.should == nil
|
|
|
|
end
|
|
|
|
|
2013-12-14 10:56:19 -05:00
|
|
|
it "should parse relative path with line_num" do
|
2013-12-14 10:12:36 -05:00
|
|
|
file_with_embedded_line = "pry_instance.rb:2"
|
|
|
|
ff = Pry::Command::Cat::FileFormatter.new(file_with_embedded_line, @p, @opt)
|
|
|
|
file_name, line_num = ff.file_and_line
|
|
|
|
file_name.should == "pry_instance.rb"
|
|
|
|
line_num.should == 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|