shard-ameba/spec/ameba/source_spec.cr

75 lines
1.9 KiB
Crystal
Raw Normal View History

2017-10-30 20:00:01 +00:00
require "../spec_helper"
module Ameba
describe Source do
describe ".new" do
it "allows to create a source by code and path" do
2022-12-22 18:18:27 +00:00
source = Source.new "code", "path"
source.path.should eq "path"
source.code.should eq "code"
source.lines.should eq ["code"]
2017-10-30 20:00:01 +00:00
end
end
2017-12-18 11:06:19 +00:00
describe "#fullpath" do
it "returns a relative path of the source" do
2022-12-22 18:18:27 +00:00
source = Source.new "", "./source_spec.cr"
source.fullpath.should contain "source_spec.cr"
2017-12-18 11:06:19 +00:00
end
it "returns fullpath if path is blank" do
2022-12-22 18:18:27 +00:00
source = Source.new "", ""
source.fullpath.should_not be_nil
2017-12-18 11:06:19 +00:00
end
end
2018-05-29 10:19:00 +00:00
2021-02-03 15:14:03 +00:00
describe "#spec?" do
it "returns true if the source is a spec file" do
2022-12-22 18:18:27 +00:00
source = Source.new "", "./source_spec.cr"
source.spec?.should be_true
2021-02-03 15:14:03 +00:00
end
it "returns false if the source is not a spec file" do
2022-12-22 18:18:27 +00:00
source = Source.new "", "./source.cr"
source.spec?.should be_false
2021-02-03 15:14:03 +00:00
end
end
2018-05-29 10:19:00 +00:00
describe "#matches_path?" do
it "returns true if source's path is matched" do
2022-12-22 18:18:27 +00:00
source = Source.new "", "source.cr"
source.matches_path?("source.cr").should be_true
2018-05-29 10:19:00 +00:00
end
it "returns false if source's path is not matched" do
2022-12-22 18:18:27 +00:00
source = Source.new "", "source.cr"
source.matches_path?("new_source.cr").should be_false
2018-05-29 10:19:00 +00:00
end
end
2022-12-19 14:27:20 +00:00
describe "#pos" do
it "works" do
2022-12-22 18:18:27 +00:00
source = Source.new <<-CRYSTAL
2022-12-19 14:27:20 +00:00
foo
bar
fizz
buzz
2022-12-22 18:18:27 +00:00
CRYSTAL
location = Crystal::Location.new("", 2, 1)
end_location = Crystal::Location.new("", 3, 4)
range = Range.new(
source.pos(location),
source.pos(end_location, end: true),
exclusive: true
)
source.code[range].should eq <<-CRYSTAL
2022-12-19 14:27:20 +00:00
bar
fizz
2022-12-22 18:18:27 +00:00
CRYSTAL
2022-12-19 14:27:20 +00:00
end
end
2017-10-30 20:00:01 +00:00
end
end