summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-14 21:27:52 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-14 21:27:52 +0200
commit3c16243fc8dbddcacf6da58866efea3aa46cfcde (patch)
treeed9dccae58c3e808113da95caea986f5fe3cc9e6
parenta62a304249f7fcd7fca0123986d170cac8fd75db (diff)
downloadgitlab-ci-3c16243fc8dbddcacf6da58866efea3aa46cfcde.tar.gz
Improve parser. tests added
-rw-r--r--lib/ansi2html.rb8
-rw-r--r--spec/lib/ansi2html_spec.rb12
-rw-r--r--spec/models/build_spec.rb2
3 files changed, 17 insertions, 5 deletions
diff --git a/lib/ansi2html.rb b/lib/ansi2html.rb
index 9375075..59491f1 100644
--- a/lib/ansi2html.rb
+++ b/lib/ansi2html.rb
@@ -1,7 +1,6 @@
# ANSI color library
module Ansi2html
COLOR = {
- '1' => 'bold',
'30' => 'black',
'31' => 'red',
'32' => 'green',
@@ -18,12 +17,14 @@ module Ansi2html
tag_open = false
s = StringScanner.new(ansi.gsub("<", "&lt;"))
while(!s.eos?)
- if s.scan(/\e\[(3[0-7]|90|1)m/) || s.scan(/\[1;(3[0-7])m/)
+ if s.scan(/\e\[(3[0-7]|90)m/) || s.scan(/\e\[1;(3[0-7])m/)
if tag_open
out << %{</span>}
end
out << %{<span class="#{COLOR[s[1]]}">}
tag_open = true
+ elsif s.scan(/\e\[1m/)
+ # Just ignore bold style
else
if s.scan(/\e\[0m/)
if tag_open
@@ -35,6 +36,9 @@ module Ansi2html
end
end
end
+ if tag_open
+ out << %{</span>}
+ end
out
end
end
diff --git a/spec/lib/ansi2html_spec.rb b/spec/lib/ansi2html_spec.rb
index 73700c1..dbbd1e9 100644
--- a/spec/lib/ansi2html_spec.rb
+++ b/spec/lib/ansi2html_spec.rb
@@ -21,7 +21,15 @@ describe Ansi2html do
Ansi2html::convert("\e[90mHello\e[0m").should == '<span class="grey">Hello</span>'
end
- it "white bold boys have more fun" do
- Ansi2html::convert("\e[37m\e[1mHello\e[0m\e[0m").should == '<span class="white"><span class="bold">Hello</span></span>'
+ it "ignore nested bold" do
+ Ansi2html::convert("\e[37m\e[1mHello\e[0m\e[0m").should == '<span class="white">Hello</span>'
+ end
+
+ it "should print cucumber style" do
+ Ansi2html::convert("\e[1;32mScenario:\e[0m").should == '<span class="green">Scenario:</span>'
+ end
+
+ it 'should always close tags' do
+ Ansi2html::convert("\e[1;32mScenario: User sign up").should == '<span class="green">Scenario: User sign up</span>'
end
end
diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb
index 6054b99..63ee34f 100644
--- a/spec/models/build_spec.rb
+++ b/spec/models/build_spec.rb
@@ -14,7 +14,7 @@ describe Build do
it { should respond_to :pending? }
it { should respond_to :git_author_name }
it { should respond_to :short_sha }
- it { should respond_to :ansi_color_codes }
+ it { should respond_to :trace_html }
end