mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 10:55:30 -04:00
Add tests for the Rename module
This commit is contained in:
parent
a5e97af3a3
commit
986939ecb6
70
spec/rename_spec.cr
Normal file
70
spec/rename_spec.cr
Normal file
@ -0,0 +1,70 @@
|
||||
require "./spec_helper"
|
||||
require "../src/rename"
|
||||
|
||||
include Rename
|
||||
|
||||
describe Rule do
|
||||
it "raises on nested brackets" do
|
||||
expect_raises Exception do
|
||||
Rule.new "[[]]"
|
||||
end
|
||||
expect_raises Exception do
|
||||
Rule.new "{{}}"
|
||||
end
|
||||
end
|
||||
|
||||
it "raises on unclosed brackets" do
|
||||
expect_raises Exception do
|
||||
Rule.new "["
|
||||
end
|
||||
expect_raises Exception do
|
||||
Rule.new "{"
|
||||
end
|
||||
expect_raises Exception do
|
||||
Rule.new "[{]}"
|
||||
end
|
||||
end
|
||||
|
||||
it "raises when closing unopened brackets" do
|
||||
expect_raises Exception do
|
||||
Rule.new "]"
|
||||
end
|
||||
expect_raises Exception do
|
||||
Rule.new "[}"
|
||||
end
|
||||
end
|
||||
|
||||
it "handles `|` in patterns" do
|
||||
rule = Rule.new "{a|b|c}"
|
||||
rule.render({"b" => "b"}).should eq "b"
|
||||
rule.render({"a" => "a", "b" => "b"}).should eq "a"
|
||||
end
|
||||
|
||||
it "allows `|` outside of patterns" do
|
||||
rule = Rule.new "hello|world"
|
||||
rule.render({} of String => String).should eq "hello|world"
|
||||
end
|
||||
|
||||
it "raises on escaped characters" do
|
||||
expect_raises Exception do
|
||||
Rule.new "hello/world"
|
||||
end
|
||||
end
|
||||
|
||||
it "handles spaces in patterns" do
|
||||
rule = Rule.new "{ a }"
|
||||
rule.render({"a" => "a"}).should eq "a"
|
||||
end
|
||||
|
||||
it "strips leading and tailing spaces" do
|
||||
rule = Rule.new " hello "
|
||||
rule.render({"a" => "a"}).should eq "hello"
|
||||
end
|
||||
|
||||
it "renders a few examples correctly" do
|
||||
rule = Rule.new "[Ch. {chapter }] {title | id} testing"
|
||||
rule.render({"id" => "ID"}).should eq "ID testing"
|
||||
rule.render({"chapter" => "CH", "id" => "ID"}).should eq "Ch. CH ID testing"
|
||||
rule.render({} of String => String).should eq "testing"
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user