Commit ad96cc0e authored by Fabio Pitino's avatar Fabio Pitino

Fixing specs

parent cb0616fe
...@@ -187,6 +187,10 @@ module Gitlab ...@@ -187,6 +187,10 @@ module Gitlab
) )
end end
def section_to_class_name(section)
section.to_s.downcase.gsub(/[^a-z0-9]/, '-')
end
def handle_new_line def handle_new_line
css_classes = [] css_classes = []
...@@ -208,8 +212,7 @@ module Gitlab ...@@ -208,8 +212,7 @@ module Gitlab
section = scanner[3] section = scanner[3]
line = scanner.matched[0...-5] # strips \r\033[0K line = scanner.matched[0...-5] # strips \r\033[0K
# generate section class normalized_section = section_to_class_name(section)
normalized_section = section.to_s.downcase.gsub(/[^a-z0-9]/, '-')
if action == "start" if action == "start"
handle_section_start(normalized_section, timestamp, line) handle_section_start(normalized_section, timestamp, line)
......
...@@ -4,11 +4,11 @@ describe Gitlab::Ci::Ansi2html do ...@@ -4,11 +4,11 @@ describe Gitlab::Ci::Ansi2html do
subject { described_class } subject { described_class }
it "prints non-ansi as-is" do it "prints non-ansi as-is" do
expect(convert_html("Hello")).to eq('Hello') expect(convert_html("Hello")).to eq('<span class="">Hello</span>')
end end
it "strips non-color-changing control sequences" do it "strips non-color-changing control sequences" do
expect(convert_html("Hello \e[2Kworld")).to eq('Hello world') expect(convert_html("Hello \e[2Kworld")).to eq('<span class="">Hello world</span>')
end end
it "prints simply red" do it "prints simply red" do
...@@ -32,7 +32,7 @@ describe Gitlab::Ci::Ansi2html do ...@@ -32,7 +32,7 @@ describe Gitlab::Ci::Ansi2html do
end end
it "resets colors after red on blue" do it "resets colors after red on blue" do
expect(convert_html("\e[31;44mHello\e[0m world")).to eq('<span class="term-fg-red term-bg-blue">Hello</span> world') expect(convert_html("\e[31;44mHello\e[0m world")).to eq('<span class="term-fg-red term-bg-blue">Hello</span><span class=""> world</span>')
end end
it "performs color change from red/blue to yellow/blue" do it "performs color change from red/blue to yellow/blue" do
...@@ -44,11 +44,11 @@ describe Gitlab::Ci::Ansi2html do ...@@ -44,11 +44,11 @@ describe Gitlab::Ci::Ansi2html do
end end
it "performs color change from red/blue to reset to yellow/green" do it "performs color change from red/blue to reset to yellow/green" do
expect(convert_html("\e[31;44mHello\e[0m \e[33;42mworld")).to eq('<span class="term-fg-red term-bg-blue">Hello</span> <span class="term-fg-yellow term-bg-green">world</span>') expect(convert_html("\e[31;44mHello\e[0m \e[33;42mworld")).to eq('<span class="term-fg-red term-bg-blue">Hello</span><span class=""> </span><span class="term-fg-yellow term-bg-green">world</span>')
end end
it "ignores unsupported codes" do it "ignores unsupported codes" do
expect(convert_html("\e[51mHello\e[0m")).to eq('Hello') expect(convert_html("\e[51mHello\e[0m")).to eq('<span class="">Hello</span>')
end end
it "prints light red" do it "prints light red" do
...@@ -72,8 +72,8 @@ describe Gitlab::Ci::Ansi2html do ...@@ -72,8 +72,8 @@ describe Gitlab::Ci::Ansi2html do
end end
it "resets bold text" do it "resets bold text" do
expect(convert_html("\e[1mHello\e[21m world")).to eq('<span class="term-bold">Hello</span> world') expect(convert_html("\e[1mHello\e[21m world")).to eq('<span class="term-bold">Hello</span><span class=""> world</span>')
expect(convert_html("\e[1mHello\e[22m world")).to eq('<span class="term-bold">Hello</span> world') expect(convert_html("\e[1mHello\e[22m world")).to eq('<span class="term-bold">Hello</span><span class=""> world</span>')
end end
it "prints italic text" do it "prints italic text" do
...@@ -81,7 +81,7 @@ describe Gitlab::Ci::Ansi2html do ...@@ -81,7 +81,7 @@ describe Gitlab::Ci::Ansi2html do
end end
it "resets italic text" do it "resets italic text" do
expect(convert_html("\e[3mHello\e[23m world")).to eq('<span class="term-italic">Hello</span> world') expect(convert_html("\e[3mHello\e[23m world")).to eq('<span class="term-italic">Hello</span><span class=""> world</span>')
end end
it "prints underlined text" do it "prints underlined text" do
...@@ -89,7 +89,7 @@ describe Gitlab::Ci::Ansi2html do ...@@ -89,7 +89,7 @@ describe Gitlab::Ci::Ansi2html do
end end
it "resets underlined text" do it "resets underlined text" do
expect(convert_html("\e[4mHello\e[24m world")).to eq('<span class="term-underline">Hello</span> world') expect(convert_html("\e[4mHello\e[24m world")).to eq('<span class="term-underline">Hello</span><span class=""> world</span>')
end end
it "prints concealed text" do it "prints concealed text" do
...@@ -97,7 +97,7 @@ describe Gitlab::Ci::Ansi2html do ...@@ -97,7 +97,7 @@ describe Gitlab::Ci::Ansi2html do
end end
it "resets concealed text" do it "resets concealed text" do
expect(convert_html("\e[8mHello\e[28m world")).to eq('<span class="term-conceal">Hello</span> world') expect(convert_html("\e[8mHello\e[28m world")).to eq('<span class="term-conceal">Hello</span><span class=""> world</span>')
end end
it "prints crossed-out text" do it "prints crossed-out text" do
...@@ -105,7 +105,7 @@ describe Gitlab::Ci::Ansi2html do ...@@ -105,7 +105,7 @@ describe Gitlab::Ci::Ansi2html do
end end
it "resets crossed-out text" do it "resets crossed-out text" do
expect(convert_html("\e[9mHello\e[29m world")).to eq('<span class="term-cross">Hello</span> world') expect(convert_html("\e[9mHello\e[29m world")).to eq('<span class="term-cross">Hello</span><span class=""> world</span>')
end end
it "can print 256 xterm fg colors" do it "can print 256 xterm fg colors" do
...@@ -137,15 +137,15 @@ describe Gitlab::Ci::Ansi2html do ...@@ -137,15 +137,15 @@ describe Gitlab::Ci::Ansi2html do
end end
it "prints &lt;" do it "prints &lt;" do
expect(convert_html("<")).to eq('&lt;') expect(convert_html("<")).to eq('<span class="">&lt;</span>')
end end
it "replaces newlines with line break tags" do it "replaces newlines with line break tags" do
expect(convert_html("\n")).to eq('<br>') expect(convert_html("\n")).to eq('<span class=""><br/><span class=""></span></span>')
end end
it "groups carriage returns with newlines" do it "groups carriage returns with newlines" do
expect(convert_html("\r\n")).to eq('<br>') expect(convert_html("\r\n")).to eq('<span class=""><br/><span class=""></span></span>')
end end
describe "incremental update" do describe "incremental update" do
...@@ -166,14 +166,14 @@ describe Gitlab::Ci::Ansi2html do ...@@ -166,14 +166,14 @@ describe Gitlab::Ci::Ansi2html do
let(:pre_text) { "\e[1mHello" } let(:pre_text) { "\e[1mHello" }
let(:pre_html) { "<span class=\"term-bold\">Hello</span>" } let(:pre_html) { "<span class=\"term-bold\">Hello</span>" }
let(:text) { "\e[1mWorld" } let(:text) { "\e[1mWorld" }
let(:html) { "<span class=\"term-bold\"></span><span class=\"term-bold\">World</span>" } let(:html) { "<span class=\"term-bold\">World</span>" }
it_behaves_like 'stateable converter' it_behaves_like 'stateable converter'
end end
context "with split sequence" do context "with split sequence" do
let(:pre_text) { "\e[1m" } let(:pre_text) { "\e[1m" }
let(:pre_html) { "<span class=\"term-bold\"></span>" } let(:pre_html) { "" }
let(:text) { "Hello" } let(:text) { "Hello" }
let(:html) { "<span class=\"term-bold\">Hello</span>" } let(:html) { "<span class=\"term-bold\">Hello</span>" }
...@@ -182,7 +182,7 @@ describe Gitlab::Ci::Ansi2html do ...@@ -182,7 +182,7 @@ describe Gitlab::Ci::Ansi2html do
context "with partial sequence" do context "with partial sequence" do
let(:pre_text) { "Hello\e" } let(:pre_text) { "Hello\e" }
let(:pre_html) { "Hello" } let(:pre_html) { "<span class=\"\">Hello</span>" }
let(:text) { "[1m World" } let(:text) { "[1m World" }
let(:html) { "<span class=\"term-bold\"> World</span>" } let(:html) { "<span class=\"term-bold\"> World</span>" }
...@@ -191,9 +191,9 @@ describe Gitlab::Ci::Ansi2html do ...@@ -191,9 +191,9 @@ describe Gitlab::Ci::Ansi2html do
context 'with new line' do context 'with new line' do
let(:pre_text) { "Hello\r" } let(:pre_text) { "Hello\r" }
let(:pre_html) { "Hello\r" } let(:pre_html) { "<span class=\"\">Hello\r</span>" }
let(:text) { "\nWorld" } let(:text) { "\nWorld" }
let(:html) { "<br>World" } let(:html) { "<span class=\"\"><br/><span class=\"\">World</span></span>" }
it_behaves_like 'stateable converter' it_behaves_like 'stateable converter'
end end
...@@ -207,20 +207,20 @@ describe Gitlab::Ci::Ansi2html do ...@@ -207,20 +207,20 @@ describe Gitlab::Ci::Ansi2html do
let(:section_start) { "section_start:#{section_start_time.to_i}:#{section_name}\r\033[0K"} let(:section_start) { "section_start:#{section_start_time.to_i}:#{section_name}\r\033[0K"}
let(:section_end) { "section_end:#{section_end_time.to_i}:#{section_name}\r\033[0K"} let(:section_end) { "section_end:#{section_end_time.to_i}:#{section_name}\r\033[0K"}
let(:section_start_html) do let(:section_start_html) do
'<div class="hidden" data-action="start"'\ '<div class="js-section-start fa fa-caret-down append-right-8 cursor-pointer"' \
" data-timestamp=\"#{section_start_time.to_i}\" data-section=\"#{section_name}\">"\ " data-timestamp=\"#{section_start_time.to_i}\" data-section=\"#{class_name(section_name)}\"" \
"#{section_start[0...-5]}</div>" ' role="button"></div>'
end end
let(:section_end_html) do let(:section_end_html) do
'<div class="hidden" data-action="end"'\ "<div class=\"section-end\" data-section=\"#{class_name(section_name)}\"></div>"
" data-timestamp=\"#{section_end_time.to_i}\" data-section=\"#{section_name}\">"\
"#{section_end[0...-5]}</div>"
end end
shared_examples 'forbidden char in section_name' do shared_examples 'forbidden char in section_name' do
it 'ignores sections' do it 'ignores sections' do
text = "#{section_start}Some text#{section_end}" text = "#{section_start}Some text#{section_end}"
html = text.gsub("\033[0K", '').gsub('<', '&lt;') class_name_start = section_start.gsub("\033[0K", '').gsub('<', '&lt;')
class_name_end = section_end.gsub("\033[0K", '').gsub('<', '&lt;')
html = %{<span class="">#{class_name_start}Some text#{class_name_end}</span>}
expect(convert_html(text)).to eq(html) expect(convert_html(text)).to eq(html)
end end
...@@ -231,7 +231,11 @@ describe Gitlab::Ci::Ansi2html do ...@@ -231,7 +231,11 @@ describe Gitlab::Ci::Ansi2html do
it 'prints light red' do it 'prints light red' do
text = "#{section_start}\e[91mHello\e[0m\n#{section_end}" text = "#{section_start}\e[91mHello\e[0m\n#{section_end}"
html = %{#{section_start_html}<span class="term-fg-l-red">Hello</span><br>#{section_end_html}} header = %{<span class="term-fg-l-red section js-section-header js-s_#{class_name(section_name)}">Hello</span>}
line_break = %{<span class="section js-section-header js-s_#{class_name(section_name)}"><br/></span>}
line = %{<span class="section s_#{class_name(section_name)} line"></span>}
empty_line = %{<span class="section js-s_#{class_name(section_name)}"></span>}
html = "#{section_start_html}#{header}#{line_break}#{line}#{empty_line}#{section_end_html}"
expect(convert_html(text)).to eq(html) expect(convert_html(text)).to eq(html)
end end
...@@ -294,4 +298,8 @@ describe Gitlab::Ci::Ansi2html do ...@@ -294,4 +298,8 @@ describe Gitlab::Ci::Ansi2html do
stream = StringIO.new(data) stream = StringIO.new(data)
subject.convert(stream).html subject.convert(stream).html
end end
def class_name(section)
subject::Converter.new.section_to_class_name(section)
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment