2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2018-01-25 08:38:12 +00:00
|
|
|
|
2018-06-16 11:50:59 +00:00
|
|
|
module Ameba::Rule::Lint
|
2018-01-25 08:38:12 +00:00
|
|
|
describe Syntax do
|
|
|
|
subject = Syntax.new
|
|
|
|
|
|
|
|
it "passes if there is no invalid syntax" do
|
2022-04-04 19:10:27 +00:00
|
|
|
expect_no_issues subject, <<-CRYSTAL
|
2018-01-25 08:38:12 +00:00
|
|
|
def hello
|
|
|
|
puts "totally valid"
|
|
|
|
rescue e: Exception
|
|
|
|
end
|
2022-04-04 19:10:27 +00:00
|
|
|
CRYSTAL
|
2018-01-25 08:38:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is an invalid syntax" do
|
2022-04-04 19:10:27 +00:00
|
|
|
expect_issue subject, <<-CRYSTAL
|
2018-01-25 08:38:12 +00:00
|
|
|
def hello
|
|
|
|
puts "invalid"
|
|
|
|
rescue Exception => e
|
2022-04-04 19:10:27 +00:00
|
|
|
# ^ error: expecting any of these tokens: ;, NEWLINE (not '=>')
|
2018-01-25 08:38:12 +00:00
|
|
|
end
|
2022-04-04 19:10:27 +00:00
|
|
|
CRYSTAL
|
2018-01-25 08:38:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, location and message" do
|
|
|
|
s = Source.new "def hello end", "source.cr"
|
|
|
|
subject.catch(s).should_not be_valid
|
2018-06-10 21:15:12 +00:00
|
|
|
issue = s.issues.first
|
2018-01-25 08:38:12 +00:00
|
|
|
|
2018-06-10 21:15:12 +00:00
|
|
|
issue.rule.should_not be_nil
|
|
|
|
issue.location.to_s.should eq "source.cr:1:11"
|
2021-11-29 21:04:59 +00:00
|
|
|
issue.message.should match /unexpected token: "?end"? \(expected ["'];["'] or newline\)/
|
2018-01-25 08:38:12 +00:00
|
|
|
end
|
2019-04-13 19:38:37 +00:00
|
|
|
|
|
|
|
it "has highest severity" do
|
|
|
|
subject.severity.should eq Severity::Error
|
|
|
|
end
|
2018-01-25 08:38:12 +00:00
|
|
|
end
|
|
|
|
end
|