mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
parent
b8eeac469a
commit
93dd7d446f
7 changed files with 38 additions and 29 deletions
|
@ -6,17 +6,17 @@ module Ameba::Rules
|
|||
|
||||
describe LineLength do
|
||||
it "passes if all lines are shorter than 80 symbols" do
|
||||
source = Source.new "", "short line"
|
||||
source = Source.new "short line"
|
||||
subject.catch(source).valid?.should be_true
|
||||
end
|
||||
|
||||
it "fails if there is at least one line longer than 79 symbols" do
|
||||
source = Source.new "", long_line
|
||||
source = Source.new long_line
|
||||
subject.catch(source).valid?.should be_false
|
||||
end
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
source = Source.new "", long_line
|
||||
source = Source.new long_line
|
||||
subject.catch(source).valid?.should be_false
|
||||
|
||||
error = source.errors.first
|
||||
|
|
|
@ -5,27 +5,27 @@ module Ameba::Rules
|
|||
|
||||
describe TrailingBlankLines do
|
||||
it "passes if there is no blank lines at the end" do
|
||||
source = Source.new "", "no-blankline"
|
||||
source = Source.new "no-blankline"
|
||||
subject.catch(source).valid?.should be_true
|
||||
end
|
||||
|
||||
it "fails if there is a blank line at the end of a source" do
|
||||
source = Source.new "", "a = 1\n \n "
|
||||
source = Source.new "a = 1\n \n "
|
||||
subject.catch(source).valid?.should be_false
|
||||
end
|
||||
|
||||
it "passes if source is empty" do
|
||||
source = Source.new "", ""
|
||||
source = Source.new ""
|
||||
subject.catch(source).valid?.should be_true
|
||||
end
|
||||
|
||||
it "passes if last line is not blank" do
|
||||
source = Source.new "", "\n\n\n puts 22"
|
||||
source = Source.new "\n\n\n puts 22"
|
||||
subject.catch(source).valid?.should be_true
|
||||
end
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
source = Source.new "", "a = 1\n\n "
|
||||
source = Source.new "a = 1\n\n "
|
||||
subject.catch(source)
|
||||
|
||||
error = source.errors.first
|
||||
|
|
|
@ -5,17 +5,17 @@ module Ameba::Rules
|
|||
|
||||
describe TrailingWhitespace do
|
||||
it "passes if all lines do not have trailing whitespace" do
|
||||
source = Source.new "", "no-whispace"
|
||||
source = Source.new "no-whispace"
|
||||
subject.catch(source).valid?.should be_true
|
||||
end
|
||||
|
||||
it "fails if there is a line with trailing whitespace" do
|
||||
source = Source.new "", "whitespace at the end "
|
||||
source = Source.new "whitespace at the end "
|
||||
subject.catch(source).valid?.should be_false
|
||||
end
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
source = Source.new "", "a = 1\n b = 2 "
|
||||
source = Source.new "a = 1\n b = 2 "
|
||||
subject.catch(source).valid?.should be_false
|
||||
|
||||
error = source.errors.first
|
||||
|
|
|
@ -3,20 +3,17 @@ require "../spec_helper"
|
|||
module Ameba
|
||||
describe Source do
|
||||
describe ".new" do
|
||||
it "allows to create a source by file path" do
|
||||
Source.new(__FILE__).path.should eq __FILE__
|
||||
end
|
||||
|
||||
it "allows to create a source by content and path" do
|
||||
s = Source.new(__FILE__, "content")
|
||||
s.path.should eq __FILE__
|
||||
s.lines.should eq %w(content)
|
||||
s = Source.new("content", "path")
|
||||
s.path.should eq "path"
|
||||
s.content.should eq "content"
|
||||
s.lines.should eq ["content"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#error" do
|
||||
it "adds and error" do
|
||||
s = Source.new(__FILE__)
|
||||
s = Source.new ""
|
||||
s.error(DummyRule.new, 23, "Error!")
|
||||
s.errors.size.should eq 1
|
||||
s.errors.first.rule.should_not be_nil
|
||||
|
@ -24,5 +21,15 @@ module Ameba
|
|||
s.errors.first.message.should eq "Error!"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ast" do
|
||||
it "returns ast nodes" do
|
||||
s = Source.new %(
|
||||
class A; end
|
||||
class B; end
|
||||
)
|
||||
s.ast.to_s.should eq "class A\nend\nclass B\nend\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue