2019-05-03 01:33:56 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-01 01:24:01 -08:00
|
|
|
describe Pry::Helpers::DocumentationHelpers do
|
|
|
|
before do
|
|
|
|
@helper = Pry::Helpers::DocumentationHelpers
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "get_comment_content" do
|
|
|
|
it "should strip off the hash and unindent" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@helper.get_comment_content(" # hello\n # world\n")).to eq("hello\nworld\n")
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should strip out leading lines of hashes" do
|
2019-03-03 17:37:58 +02:00
|
|
|
expect(@helper.get_comment_content("###############\n#hello\n#world\n"))
|
|
|
|
.to eq("hello\nworld\n")
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should remove shebangs" do
|
2019-03-03 17:37:58 +02:00
|
|
|
expect(@helper.get_comment_content("#!/usr/bin/env ruby\n# This is a program\n"))
|
|
|
|
.to eq("This is a program\n")
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should unindent past separators" do
|
2019-03-03 17:37:58 +02:00
|
|
|
str = " # Copyright Me <me@cirw.in>\n #--\n # So there.\n"
|
|
|
|
expect(@helper.get_comment_content(str))
|
|
|
|
.to eq("Copyright Me <me@cirw.in>\n--\nSo there.\n")
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "process_rdoc" do
|
|
|
|
before do
|
2014-04-29 00:03:15 -07:00
|
|
|
Pry.config.color = true
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2014-04-29 00:03:15 -07:00
|
|
|
Pry.config.color = false
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should syntax highlight indented code" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@helper.process_rdoc(" 4 + 4\n")).not_to eq(" 4 + 4\n")
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should highlight words surrounded by +s" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@helper.process_rdoc("the +parameter+")).to match(/the \e.*parameter\e.*/)
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should syntax highlight things in backticks" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@helper.process_rdoc("for `Example`")).to match(/for `\e.*Example\e.*`/)
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should emphasise em tags" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@helper.process_rdoc("for <em>science</em>")).to eq("for \e[1mscience\e[0m")
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should emphasise italic tags" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@helper.process_rdoc("for <i>science</i>")).to eq("for \e[1mscience\e[0m")
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should syntax highlight code in <code>" do
|
2019-03-03 17:37:58 +02:00
|
|
|
expect(@helper.process_rdoc("for <code>Example</code>"))
|
|
|
|
.to match(/for \e.*Example\e.*/)
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
2015-06-24 16:36:03 +03:00
|
|
|
it "should syntax highlight code in <tt>" do
|
|
|
|
expect(@helper.process_rdoc("for <tt>Example</tt>")).to match(/for \e.*Example\e.*/)
|
|
|
|
end
|
|
|
|
|
2013-02-01 01:24:01 -08:00
|
|
|
it "should not double-highlight backticks inside indented code" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@helper.process_rdoc(" `echo 5`")).to match(/echo 5/)
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not remove ++" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@helper.process_rdoc("--\n comment in a bubble\n++")).to match(/\+\+/)
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
2021-04-11 00:54:01 +03:00
|
|
|
|
|
|
|
it "should not syntax highlight already highlighted code" do
|
|
|
|
expect(@helper.process_rdoc(" \e\[31mFOO\e\[0m")).to match(/ \e\[31mFOO\e\[0m/)
|
|
|
|
end
|
2013-02-01 01:24:01 -08:00
|
|
|
end
|
2014-03-14 05:31:24 +01:00
|
|
|
end
|