Let ameba explain the issue at the specified location (#86)

This commit is contained in:
Vitalii Elenhaupt 2018-12-27 23:34:10 +02:00 committed by GitHub
parent 4e19571fb3
commit c91da1aa08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 359 additions and 22 deletions

View file

@ -78,11 +78,57 @@ module Ameba::Cli
c.config.should eq ""
end
describe "-e/--explain" do
it "configures file/line/column" do
c = Cli.parse_args %w(--explain src/file.cr:3:5)
c.location_to_explain.should_not be_nil
location_to_explain = c.location_to_explain.not_nil!
location_to_explain[:file].should eq "src/file.cr"
location_to_explain[:line].should eq 3
location_to_explain[:column].should eq 5
end
it "raises an error if location is not valid" do
expect_raises(Exception, "location should have PATH:line:column") do
Cli.parse_args %w(--explain src/file.cr:3)
end
end
it "raises an error if line number is not valid" do
expect_raises(Exception, "location should have PATH:line:column") do
Cli.parse_args %w(--explain src/file.cr:a:3)
end
end
it "raises an error if column number is not valid" do
expect_raises(Exception, "location should have PATH:line:column") do
Cli.parse_args %w(--explain src/file.cr:3:&)
end
end
it "raises an error if line/column are missing" do
expect_raises(Exception, "location should have PATH:line:column") do
Cli.parse_args %w(--explain src/file.cr)
end
end
end
it "accepts unknown args as files" do
c = Cli.parse_args %w(source1.cr source2.cr)
c.files.should eq %w(source1.cr source2.cr)
end
it "accepts one unknown arg as explain location if it has correct format" do
c = Cli.parse_args %w(source.cr:3:22)
c.location_to_explain.should_not be_nil
location_to_explain = c.location_to_explain.not_nil!
location_to_explain[:file].should eq "source.cr"
location_to_explain[:line].should eq 3
location_to_explain[:column].should eq 22
end
it "allows args to be blank" do
c = Cli.parse_args [] of String
c.formatter.should be_nil