2014-12-31 15:59:32 -05:00
|
|
|
require 'spec_helper'
|
2011-11-29 22:52:30 -05:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
RSpec.describe 'AwesomePrint/Nokogiri' do
|
|
|
|
it 'should colorize tags' do
|
2014-12-31 15:59:32 -05:00
|
|
|
xml = Nokogiri::XML('<html><body><h1></h1></body></html>')
|
2016-11-08 21:39:25 -05:00
|
|
|
expect(xml.ai).to eq <<-EOS
|
2011-11-29 22:52:30 -05:00
|
|
|
<?xml version=\"1.0\"?>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mhtml\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mbody\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mh1\e[0m/>\e[1;32m
|
|
|
|
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36m/html\e[0m>
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
end
|
2011-11-29 22:52:30 -05:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'should colorize contents' do
|
2014-12-31 15:59:32 -05:00
|
|
|
xml = Nokogiri::XML('<html><body><h1>Hello</h1></body></html>')
|
2016-11-08 21:39:25 -05:00
|
|
|
expect(xml.ai).to eq <<-EOS
|
2011-11-29 22:52:30 -05:00
|
|
|
<?xml version=\"1.0\"?>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mhtml\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mbody\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mh1\e[0m>\e[1;32mHello\e[0m<\e[1;36m/h1\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36m/html\e[0m>
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
end
|
2011-11-29 22:52:30 -05:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'should colorize class and id' do
|
2014-12-31 15:59:32 -05:00
|
|
|
xml = Nokogiri::XML('<html><body><h1><span id="hello" class="world"></span></h1></body></html>')
|
2016-11-08 21:39:25 -05:00
|
|
|
expect(xml.ai).to eq <<-EOS
|
2011-11-29 22:52:30 -05:00
|
|
|
<?xml version=\"1.0\"?>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mhtml\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mbody\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mh1\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36mspan\e[0m \e[1;33mid=\"hello\"\e[0m \e[1;33mclass=\"world\"\e[0m/>\e[1;32m
|
|
|
|
\e[0m<\e[1;36m/h1\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
|
|
|
\e[0m<\e[1;36m/html\e[0m>
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
2011-11-29 22:52:30 -05:00
|
|
|
end
|
2015-02-12 16:24:47 -05:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'handle empty NodeSet' do
|
2015-02-12 16:24:47 -05:00
|
|
|
xml = Nokogiri::XML::NodeSet.new(Nokogiri::XML(''))
|
|
|
|
expect(xml.ai).to eq('[]')
|
|
|
|
end
|
2011-11-29 22:52:30 -05:00
|
|
|
end
|