mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Docs & tests
This commit is contained in:
parent
5e10113055
commit
9bba850a9b
12 changed files with 142 additions and 24 deletions
24
spec/ameba/rule_spec.cr
Normal file
24
spec/ameba/rule_spec.cr
Normal file
|
@ -0,0 +1,24 @@
|
|||
require "../../spec/spec_helper"
|
||||
|
||||
module Ameba
|
||||
describe RULES do
|
||||
it "contains available rules" do
|
||||
Ameba::RULES.empty?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe Rule do
|
||||
describe "#catch" do
|
||||
it "accepts and returns source" do
|
||||
s = Source.new "", ""
|
||||
DummyRule.new.catch(s).should eq s
|
||||
end
|
||||
end
|
||||
|
||||
describe "#name" do
|
||||
it "returns name of the rule" do
|
||||
DummyRule.new.name.should eq "DummyRule"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
spec/ameba/rules/line_length_spec.cr
Normal file
28
spec/ameba/rules/line_length_spec.cr
Normal file
|
@ -0,0 +1,28 @@
|
|||
require "../../spec_helper"
|
||||
|
||||
module Ameba::Rules
|
||||
subject = LineLength.new
|
||||
long_line = "*" * 80
|
||||
|
||||
describe LineLength do
|
||||
it "passes if all lines are shorter than 80 symbols" do
|
||||
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
|
||||
subject.catch(source).valid?.should be_false
|
||||
end
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
source = Source.new "", long_line
|
||||
subject.catch(source).valid?.should be_false
|
||||
|
||||
error = source.errors.first
|
||||
error.rule.should eq subject
|
||||
error.pos.should eq 1
|
||||
error.message.should eq "Line too long (80 symbols)"
|
||||
end
|
||||
end
|
||||
end
|
28
spec/ameba/source_spec.cr
Normal file
28
spec/ameba/source_spec.cr
Normal file
|
@ -0,0 +1,28 @@
|
|||
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)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#error" do
|
||||
it "adds and error" do
|
||||
s = Source.new(__FILE__)
|
||||
s.error(DummyRule.new, 23, "Error!")
|
||||
s.errors.size.should eq 1
|
||||
s.errors.first.rule.should_not be_nil
|
||||
s.errors.first.pos.should eq 23
|
||||
s.errors.first.message.should eq "Error!"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +1,4 @@
|
|||
require "./spec_helper"
|
||||
|
||||
describe Ameba do
|
||||
# TODO: Write tests
|
||||
|
||||
it "works" do
|
||||
false.should eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
require "spec"
|
||||
require "../src/ameba"
|
||||
|
||||
struct DummyRule < Ameba::Rule
|
||||
def test(source)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue