Commit ae5d2f5b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix Ci::Ansi2html spec

parent 0615de01
require 'spec_helper' require 'spec_helper'
describe Ci::Ansi2html do describe Ci::Ansi2html do
subject { Ci::Ansi2html }
it "prints non-ansi as-is" do it "prints non-ansi as-is" do
Ansi2html::convert("Hello").should == 'Hello' expect(subject.convert("Hello")).to eq('Hello')
end end
it "strips non-color-changing controll sequences" do it "strips non-color-changing controll sequences" do
Ansi2html::convert("Hello \e[2Kworld").should == 'Hello world' expect(subject.convert("Hello \e[2Kworld")).to eq('Hello world')
end end
it "prints simply red" do it "prints simply red" do
Ansi2html::convert("\e[31mHello\e[0m").should == '<span class="term-fg-red">Hello</span>' expect(subject.convert("\e[31mHello\e[0m")).to eq('<span class="term-fg-red">Hello</span>')
end end
it "prints simply red without trailing reset" do it "prints simply red without trailing reset" do
Ansi2html::convert("\e[31mHello").should == '<span class="term-fg-red">Hello</span>' expect(subject.convert("\e[31mHello")).to eq('<span class="term-fg-red">Hello</span>')
end end
it "prints simply yellow" do it "prints simply yellow" do
Ansi2html::convert("\e[33mHello\e[0m").should == '<span class="term-fg-yellow">Hello</span>' expect(subject.convert("\e[33mHello\e[0m")).to eq('<span class="term-fg-yellow">Hello</span>')
end end
it "prints default on blue" do it "prints default on blue" do
Ansi2html::convert("\e[39;44mHello").should == '<span class="term-bg-blue">Hello</span>' expect(subject.convert("\e[39;44mHello")).to eq('<span class="term-bg-blue">Hello</span>')
end end
it "prints red on blue" do it "prints red on blue" do
Ansi2html::convert("\e[31;44mHello").should == '<span class="term-fg-red term-bg-blue">Hello</span>' expect(subject.convert("\e[31;44mHello")).to eq('<span class="term-fg-red term-bg-blue">Hello</span>')
end end
it "resets colors after red on blue" do it "resets colors after red on blue" do
Ansi2html::convert("\e[31;44mHello\e[0m world").should == '<span class="term-fg-red term-bg-blue">Hello</span> world' expect(subject.convert("\e[31;44mHello\e[0m world")).to eq('<span class="term-fg-red term-bg-blue">Hello</span> world')
end end
it "performs color change from red/blue to yellow/blue" do it "performs color change from red/blue to yellow/blue" do
Ansi2html::convert("\e[31;44mHello \e[33mworld").should == '<span class="term-fg-red term-bg-blue">Hello </span><span class="term-fg-yellow term-bg-blue">world</span>' expect(subject.convert("\e[31;44mHello \e[33mworld")).to eq('<span class="term-fg-red term-bg-blue">Hello </span><span class="term-fg-yellow term-bg-blue">world</span>')
end end
it "performs color change from red/blue to yellow/green" do it "performs color change from red/blue to yellow/green" do
Ansi2html::convert("\e[31;44mHello \e[33;42mworld").should == '<span class="term-fg-red term-bg-blue">Hello </span><span class="term-fg-yellow term-bg-green">world</span>' expect(subject.convert("\e[31;44mHello \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>')
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
Ansi2html::convert("\e[31;44mHello\e[0m \e[33;42mworld").should == '<span class="term-fg-red term-bg-blue">Hello</span> <span class="term-fg-yellow term-bg-green">world</span>' expect(subject.convert("\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>')
end end
it "ignores unsupported codes" do it "ignores unsupported codes" do
Ansi2html::convert("\e[51mHello\e[0m").should == 'Hello' expect(subject.convert("\e[51mHello\e[0m")).to eq('Hello')
end end
it "prints light red" do it "prints light red" do
Ansi2html::convert("\e[91mHello\e[0m").should == '<span class="term-fg-l-red">Hello</span>' expect(subject.convert("\e[91mHello\e[0m")).to eq('<span class="term-fg-l-red">Hello</span>')
end end
it "prints default on light red" do it "prints default on light red" do
Ansi2html::convert("\e[101mHello\e[0m").should == '<span class="term-bg-l-red">Hello</span>' expect(subject.convert("\e[101mHello\e[0m")).to eq('<span class="term-bg-l-red">Hello</span>')
end end
it "performs color change from red/blue to default/blue" do it "performs color change from red/blue to default/blue" do
Ansi2html::convert("\e[31;44mHello \e[39mworld").should == '<span class="term-fg-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>' expect(subject.convert("\e[31;44mHello \e[39mworld")).to eq('<span class="term-fg-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>')
end end
it "performs color change from light red/blue to default/blue" do it "performs color change from light red/blue to default/blue" do
Ansi2html::convert("\e[91;44mHello \e[39mworld").should == '<span class="term-fg-l-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>' expect(subject.convert("\e[91;44mHello \e[39mworld")).to eq('<span class="term-fg-l-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>')
end end
it "prints bold text" do it "prints bold text" do
Ansi2html::convert("\e[1mHello").should == '<span class="term-bold">Hello</span>' expect(subject.convert("\e[1mHello")).to eq('<span class="term-bold">Hello</span>')
end end
it "resets bold text" do it "resets bold text" do
Ansi2html::convert("\e[1mHello\e[21m world").should == '<span class="term-bold">Hello</span> world' expect(subject.convert("\e[1mHello\e[21m world")).to eq('<span class="term-bold">Hello</span> world')
Ansi2html::convert("\e[1mHello\e[22m world").should == '<span class="term-bold">Hello</span> world' expect(subject.convert("\e[1mHello\e[22m world")).to eq('<span class="term-bold">Hello</span> world')
end end
it "prints italic text" do it "prints italic text" do
Ansi2html::convert("\e[3mHello").should == '<span class="term-italic">Hello</span>' expect(subject.convert("\e[3mHello")).to eq('<span class="term-italic">Hello</span>')
end end
it "resets italic text" do it "resets italic text" do
Ansi2html::convert("\e[3mHello\e[23m world").should == '<span class="term-italic">Hello</span> world' expect(subject.convert("\e[3mHello\e[23m world")).to eq('<span class="term-italic">Hello</span> world')
end end
it "prints underlined text" do it "prints underlined text" do
Ansi2html::convert("\e[4mHello").should == '<span class="term-underline">Hello</span>' expect(subject.convert("\e[4mHello")).to eq('<span class="term-underline">Hello</span>')
end end
it "resets underlined text" do it "resets underlined text" do
Ansi2html::convert("\e[4mHello\e[24m world").should == '<span class="term-underline">Hello</span> world' expect(subject.convert("\e[4mHello\e[24m world")).to eq('<span class="term-underline">Hello</span> world')
end end
it "prints concealed text" do it "prints concealed text" do
Ansi2html::convert("\e[8mHello").should == '<span class="term-conceal">Hello</span>' expect(subject.convert("\e[8mHello")).to eq('<span class="term-conceal">Hello</span>')
end end
it "resets concealed text" do it "resets concealed text" do
Ansi2html::convert("\e[8mHello\e[28m world").should == '<span class="term-conceal">Hello</span> world' expect(subject.convert("\e[8mHello\e[28m world")).to eq('<span class="term-conceal">Hello</span> world')
end end
it "prints crossed-out text" do it "prints crossed-out text" do
Ansi2html::convert("\e[9mHello").should == '<span class="term-cross">Hello</span>' expect(subject.convert("\e[9mHello")).to eq('<span class="term-cross">Hello</span>')
end end
it "resets crossed-out text" do it "resets crossed-out text" do
Ansi2html::convert("\e[9mHello\e[29m world").should == '<span class="term-cross">Hello</span> world' expect(subject.convert("\e[9mHello\e[29m world")).to eq('<span class="term-cross">Hello</span> world')
end end
it "can print 256 xterm fg colors" do it "can print 256 xterm fg colors" do
Ansi2html::convert("\e[38;5;16mHello").should == '<span class="xterm-fg-16">Hello</span>' expect(subject.convert("\e[38;5;16mHello")).to eq('<span class="xterm-fg-16">Hello</span>')
end end
it "can print 256 xterm fg colors on normal magenta background" do it "can print 256 xterm fg colors on normal magenta background" do
Ansi2html::convert("\e[38;5;16;45mHello").should == '<span class="xterm-fg-16 term-bg-magenta">Hello</span>' expect(subject.convert("\e[38;5;16;45mHello")).to eq('<span class="xterm-fg-16 term-bg-magenta">Hello</span>')
end end
it "can print 256 xterm bg colors" do it "can print 256 xterm bg colors" do
Ansi2html::convert("\e[48;5;240mHello").should == '<span class="xterm-bg-240">Hello</span>' expect(subject.convert("\e[48;5;240mHello")).to eq('<span class="xterm-bg-240">Hello</span>')
end end
it "can print 256 xterm bg colors on normal magenta foreground" do it "can print 256 xterm bg colors on normal magenta foreground" do
Ansi2html::convert("\e[48;5;16;35mHello").should == '<span class="term-fg-magenta xterm-bg-16">Hello</span>' expect(subject.convert("\e[48;5;16;35mHello")).to eq('<span class="term-fg-magenta xterm-bg-16">Hello</span>')
end end
it "prints bold colored text vividly" do it "prints bold colored text vividly" do
Ansi2html::convert("\e[1;31mHello\e[0m").should == '<span class="term-fg-l-red term-bold">Hello</span>' expect(subject.convert("\e[1;31mHello\e[0m")).to eq('<span class="term-fg-l-red term-bold">Hello</span>')
end end
it "prints bold light colored text correctly" do it "prints bold light colored text correctly" do
Ansi2html::convert("\e[1;91mHello\e[0m").should == '<span class="term-fg-l-red term-bold">Hello</span>' expect(subject.convert("\e[1;91mHello\e[0m")).to eq('<span class="term-fg-l-red term-bold">Hello</span>')
end 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