Add support for showing code context lines (#181)

* Add support for showing code context lines

* Show context lines only in ExplainFormatter

* Add spec coverage for context_lines option
This commit is contained in:
Sijawusz Pur Rahnama 2021-01-12 16:20:43 +01:00 committed by GitHub
parent 9bc6c13d11
commit c4d34d74d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 13 deletions

View file

@ -22,7 +22,38 @@ module Ameba::Formatter
a = 1
)
location = Crystal::Location.new("filename", 1, 1)
subject.affected_code(source, location).should eq "> a = 1\n \e[33m^\e[0m"
subject.deansify(subject.affected_code(source, location))
.should eq "> a = 1\n ^"
end
it "returns correct line if it is found" do
source = Source.new <<-EOF
# pre:1
# pre:2
# pre:3
# pre:4
# pre:5
a = 1
# post:1
# post:2
# post:3
# post:4
# post:5
EOF
location = Crystal::Location.new("filename", 6, 1)
subject.deansify(subject.affected_code(source, location, context_lines: 3))
.should eq <<-STR
> # pre:3
> # pre:4
> # pre:5
> a = 1
^
> # post:1
> # post:2
> # post:3
STR
end
end
end