spec/kramdown/converter/man_spec.rb in kramdown-man-0.1.4 vs spec/kramdown/converter/man_spec.rb in kramdown-man-0.1.5
- old
+ new
@@ -23,11 +23,11 @@
subject.convert(root).should == [
described_class::HEADER,
".TH Header",
".LP",
".PP",
- "Hello world."
+ 'Hello world\.'
].join("\n")
end
end
describe "#convert_root" do
@@ -44,11 +44,11 @@
it "should convert every element" do
subject.convert_root(root).should == [
".TH Header",
".LP",
".PP",
- "Hello world."
+ 'Hello world\.'
].join("\n")
end
end
describe "#convert_element" do
@@ -98,104 +98,104 @@
describe "#convert_typographic_sym" do
context "ndash" do
let(:doc) { Kramdown::Document.new("-- foo") }
let(:sym) { doc.root.children[0].children[0] }
- it "should convert ndash symbols back into '--'" do
- subject.convert_typographic_sym(sym).should == '--'
+ it "should convert ndash symbols back into '\-\-'" do
+ subject.convert_typographic_sym(sym).should == "\\-\\-"
end
end
context "mdash" do
let(:doc) { Kramdown::Document.new("--- foo") }
let(:sym) { doc.root.children[0].children[0] }
- it "should convert mdash symbols into '—'" do
- subject.convert_typographic_sym(sym).should == '—'
+ it "should convert mdash symbols into '\[em]'" do
+ subject.convert_typographic_sym(sym).should == '\[em]'
end
end
context "hellip" do
let(:doc) { Kramdown::Document.new("... foo") }
let(:sym) { doc.root.children[0].children[0] }
- it "should convert mdash symbols into '…'" do
- subject.convert_typographic_sym(sym).should == '…'
+ it "should convert mdash symbols into '...'" do
+ subject.convert_typographic_sym(sym).should == '...'
end
end
context "laquo" do
let(:doc) { Kramdown::Document.new("<< foo") }
let(:sym) { doc.root.children[0].children[0] }
- it "should convert mdash symbols into '«'" do
- subject.convert_typographic_sym(sym).should == '«'
+ it "should convert mdash symbols into '\[Fo]'" do
+ subject.convert_typographic_sym(sym).should == '\[Fo]'
end
end
context "raquo" do
let(:doc) { Kramdown::Document.new("foo >> bar") }
let(:sym) { doc.root.children[0].children[1] }
- it "should convert mdash symbols into '»'" do
- subject.convert_typographic_sym(sym).should == '»'
+ it "should convert mdash symbols into '\[Fc]'" do
+ subject.convert_typographic_sym(sym).should == '\[Fc]'
end
end
context "laquo_space" do
let(:doc) { Kramdown::Document.new(" << foo") }
let(:sym) { doc.root.children[0].children[0] }
- it "should convert mdash symbols into '«'" do
- subject.convert_typographic_sym(sym).should == '«'
+ it "should convert mdash symbols into '\[Fo]'" do
+ subject.convert_typographic_sym(sym).should == '\[Fo]'
end
end
context "raquo_space" do
let(:doc) { Kramdown::Document.new("foo >> bar") }
let(:sym) { doc.root.children[0].children[1] }
- it "should convert mdash symbols into '»'" do
- subject.convert_typographic_sym(sym).should == '»'
+ it "should convert mdash symbols into '\[Fc]'" do
+ subject.convert_typographic_sym(sym).should == '\[Fc]'
end
end
end
describe "#convert_smart_quote" do
context "lsquo" do
let(:doc) { Kramdown::Document.new("'hello world'") }
let(:quote) { doc.root.children[0].children.first }
- it "should convert lsquo quotes into '‘'" do
- subject.convert_smart_quote(quote).should == '‘'
+ it "should convert lsquo quotes into '\[oq]'" do
+ subject.convert_smart_quote(quote).should == '\[oq]'
end
end
context "rsquo" do
let(:doc) { Kramdown::Document.new("'hello world'") }
let(:quote) { doc.root.children[0].children.last }
- it "should convert rsquo quotes into '’'" do
- subject.convert_smart_quote(quote).should == '’'
+ it "should convert rsquo quotes into '\[cq]'" do
+ subject.convert_smart_quote(quote).should == '\[cq]'
end
end
context "ldquo" do
let(:doc) { Kramdown::Document.new('"hello world"') }
let(:quote) { doc.root.children[0].children.first }
- it "should convert lsquo quotes into '“'" do
- subject.convert_smart_quote(quote).should == '“'
+ it "should convert lsquo quotes into '\[lq]'" do
+ subject.convert_smart_quote(quote).should == '\[lq]'
end
end
context "rdquo" do
let(:doc) { Kramdown::Document.new('"hello world"') }
let(:quote) { doc.root.children[0].children.last }
- it "should convert lsquo quotes into '”'" do
- subject.convert_smart_quote(quote).should == '”'
+ it "should convert lsquo quotes into '\[rq]'" do
+ subject.convert_smart_quote(quote).should == '\[rq]'
end
end
end
describe "#convert_header" do
@@ -320,12 +320,10 @@
let(:text1) { 'hello' }
let(:text2) { 'world' }
let(:doc) { Kramdown::Document.new("1. #{text1}\n\n #{text2}") }
it "should convert the other p elements to '.IP \\\\n\\n...'" do
- p li
-
subject.convert_ol_li(li).should == [
".IP \\n+[step0]",
text1,
".IP \\n",
text2
@@ -344,26 +342,28 @@
subject.convert_abbreviation(abbreviation).should == acronym
end
end
describe "#convert_blockquote" do
- let(:text) { "Some quote." }
- let(:doc) { Kramdown::Document.new("> #{text}") }
- let(:blockquote) { doc.root.children[0] }
+ let(:text) { "Some quote." }
+ let(:escaped_text) { 'Some quote\.' }
+ let(:doc) { Kramdown::Document.new("> #{text}") }
+ let(:blockquote) { doc.root.children[0] }
it "should convert blockquote elements into '.PP\\n.RS\\ntext...\\n.RE'" do
- subject.convert_blockquote(blockquote).should == ".PP\n.RS\n#{text}\n.RE"
+ subject.convert_blockquote(blockquote).should == ".PP\n.RS\n#{escaped_text}\n.RE"
end
end
describe "#convert_codeblock" do
- let(:code) { "puts 'hello world'" }
- let(:doc) { Kramdown::Document.new(" #{code}\n") }
- let(:codeblock) { doc.root.children[0] }
+ let(:code) { "puts 'hello world'" }
+ let(:escaped_code) { 'puts \(aqhello world\(aq' }
+ let(:doc) { Kramdown::Document.new(" #{code}\n") }
+ let(:codeblock) { doc.root.children[0] }
it "should convert codeblock elements into '.nf\\ntext...\\n.fi'" do
- subject.convert_codeblock(codeblock).should == ".nf\n#{code}\n.fi"
+ subject.convert_codeblock(codeblock).should == ".nf\n#{escaped_code}\n.fi"
end
end
describe "#convert_comment" do
let(:text) { "Copyright (c) 2013" }
@@ -374,89 +374,97 @@
subject.convert_comment(comment).should == ".\\\" #{text}"
end
end
describe "#convert_p" do
- let(:text) { "Hello world." }
- let(:doc) { Kramdown::Document.new(text) }
- let(:p) { doc.root.children[0] }
+ let(:text) { "Hello world." }
+ let(:escaped_text) { 'Hello world\.' }
+ let(:doc) { Kramdown::Document.new(text) }
+ let(:p) { doc.root.children[0] }
it "should convert p elements into '.PP\\ntext'" do
- subject.convert_p(p).should == ".PP\n#{text}"
+ subject.convert_p(p).should == ".PP\n#{escaped_text}"
end
context "when the paragraph starts with a codespan element" do
let(:option) { '--foo' }
let(:text) { 'Foo bar baz' }
let(:doc) { Kramdown::Document.new("`#{option}`\n\t#{text}") }
- it "should convert p elements into '.TP\\n\\fB\\fC--option\\fR\\ntext...'" do
- subject.convert_p(p).should == ".TP\n\\fB\\fC#{option}\\fR\n#{text}"
+ it "should convert p elements into '.TP\\n\\fB--option\\fR\\ntext...'" do
+ subject.convert_p(p).should == ".TP\n\\fB#{option}\\fR\n#{text}"
end
context "when there is only one codespan element" do
let(:code) { 'code' }
let(:doc) { Kramdown::Document.new("`#{code}`") }
- it "should convert p elements into '.PP\\n\\fB\\fC...\\fR'" do
- subject.convert_p(p).should == ".PP\n\\fB\\fC#{code}\\fR"
+ it "should convert p elements into '.PP\\n\\fB...\\fR'" do
+ subject.convert_p(p).should == ".PP\n\\fB#{code}\\fR"
end
end
context "when there are more than one codespan element" do
let(:flag) { '-f' }
let(:option) { '--foo' }
let(:text) { 'Foo bar baz' }
let(:doc) { Kramdown::Document.new("`#{flag}`, `#{option}`\n\t#{text}") }
- it "should convert p elements into '.TP\\n\\fB\\fC-o\\fR, \\fB\\fC--option\\fR\\ntext...'" do
- subject.convert_p(p).should == ".TP\n\\fB\\fC#{flag}\\fR, \\fB\\fC#{option}\\fR\n#{text}"
+ it "should convert p elements into '.TP\\n\\fB-o\\fR, \\fB--option\\fR\\ntext...'" do
+ subject.convert_p(p).should == ".TP\n\\fB#{flag}\\fR, \\fB#{option}\\fR\n#{text}"
end
context "when there is no newline" do
let(:doc) { Kramdown::Document.new("`#{flag}` `#{option}`") }
it "should convert the p element into a '.HP\\n...'" do
- subject.convert_p(p).should == ".HP\n\\fB\\fC#{flag}\\fR \\fB\\fC#{option}\\fR"
+ subject.convert_p(p).should == ".HP\n\\fB#{flag}\\fR \\fB#{option}\\fR"
end
end
end
end
context "when the paragraph starts with a em element" do
- let(:option) { '--foo' }
- let(:text) { 'Foo bar baz' }
- let(:doc) { Kramdown::Document.new("*#{option}*\n\t#{text}") }
+ let(:option) { '--foo' }
+ let(:escaped_option) { "\\-\\-foo" }
+ let(:text) { 'Foo bar baz' }
- it "should convert p elements into '.TP\\n\\fB\\fC--option\\fR\\ntext...'" do
- subject.convert_p(p).should == ".TP\n\\fI#{option}\\fP\n#{text}"
+ let(:doc) do
+ Kramdown::Document.new("*#{option}*\n\t#{text}")
end
+ it "should convert p elements into '.TP\\n\\fI--option\\fP\\ntext...'" do
+ subject.convert_p(p).should == ".TP\n\\fI#{escaped_option}\\fP\n#{text}"
+ end
+
context "when there is only one em element" do
let(:text) { 'foo' }
let(:doc) { Kramdown::Document.new("*#{text}*") }
- it "should convert p elements into '.PP\\n\\fB\\fC...\\fR'" do
+ it "should convert p elements into '.PP\\n\\fI...\\fP'" do
subject.convert_p(p).should == ".PP\n\\fI#{text}\\fP"
end
end
context "when there are more than one em element" do
- let(:flag) { '-f' }
- let(:option) { '--foo' }
- let(:text) { 'Foo bar baz' }
- let(:doc) { Kramdown::Document.new("*#{flag}*, *#{option}*\n\t#{text}") }
+ let(:flag) { '-f' }
+ let(:escaped_flag) { "\\-f" }
+ let(:text) { 'Foo bar baz' }
- it "should convert p elements into '.TP\\n\\fI-o\\fP, \\fI--option\\fP\\ntext...'" do
- subject.convert_p(p).should == ".TP\n\\fI\\#{flag}\\fP, \\fI#{option}\\fP\n#{text}"
+ let(:doc) do
+ Kramdown::Document.new("*#{flag}*, *#{option}*\n\t#{text}")
end
+ it "should convert p elements into '.TP\\n\\fI-o\\fP, \\fI\\-\\-option\\fP\\ntext...'" do
+ subject.convert_p(p).should == ".TP\n\\fI#{escaped_flag}\\fP, \\fI#{escaped_option}\\fP\n#{text}"
+ end
+
context "when there is no newline" do
let(:doc) { Kramdown::Document.new("*#{flag}* *#{option}*") }
it "should convert the p element into a '.HP\\n...'" do
- subject.convert_p(p).should == ".HP\n\\fI\\#{flag}\\fP \\fI#{option}\\fP"
+ subject.convert_p(p).should == ".HP\n\\fI#{escaped_flag}\\fP \\fI#{escaped_option}\\fP"
end
end
end
end
end
@@ -484,40 +492,41 @@
describe "#convert_codespan" do
let(:code) { "puts 'hello world'" }
let(:doc) { Kramdown::Document.new("`#{code}`") }
let(:codespan) { doc.root.children[0].children[0] }
- it "should convert codespan elements into '\\fB\\fCcode\\fR'" do
- subject.convert_codespan(codespan).should == "\\fB\\fC#{code}\\fR"
+ it "should convert codespan elements into '\\fBcode\\fR'" do
+ subject.convert_codespan(codespan).should == "\\fB#{code}\\fR"
end
end
describe "#convert_a" do
- let(:text) { 'example' }
- let(:href) { 'http://example.com/' }
- let(:doc) { Kramdown::Document.new("[#{text}](#{href})") }
- let(:link) { doc.root.children[0].children[0] }
+ let(:text) { 'example' }
+ let(:href) { 'http://example.com/' }
+ let(:escaped_href) { 'http:\[sl]\[sl]example\.com\[sl]' }
+ let(:doc) { Kramdown::Document.new("[#{text}](#{href})") }
+ let(:link) { doc.root.children[0].children[0] }
it "should convert a link elements into 'text\\n.UR href\\n.UE'" do
- subject.convert_a(link).should == "#{text}\n.UR #{href}\n.UE"
+ subject.convert_a(link).should == "#{text}\n.UR #{escaped_href}\n.UE"
end
context "when the href begins with mailto:" do
- let(:text) { 'Bob' }
- let(:email) { 'bob@example.com' }
- let(:doc) { Kramdown::Document.new("[#{text}](mailto:#{email})") }
+ let(:text) { 'Bob' }
+ let(:email) { 'bob@example.com' }
+ let(:escaped_email) { 'bob\[at]example\.com' }
+ let(:doc) { Kramdown::Document.new("[#{text}](mailto:#{email})") }
it "should convert the link elements into '.MT email\\n.ME'" do
- subject.convert_a(link).should == "#{text}\n.MT #{email}\n.ME"
+ subject.convert_a(link).should == "#{text}\n.MT #{escaped_email}\n.ME"
end
context "when link is <email>" do
- let(:email) { 'bob@example.com' }
- let(:doc) { Kramdown::Document.new("<#{email}>") }
+ let(:doc) { Kramdown::Document.new("<#{email}>") }
it "should convert the link elements into '.MT email\\n.ME'" do
- subject.convert_a(link).should == "\n.MT #{email}\n.ME"
+ subject.convert_a(link).should == "\n.MT #{escaped_email}\n.ME"
end
end
end
context "when the href begins with man:" do
@@ -538,14 +547,14 @@
end
end
end
describe "#escape" do
- it "should escape '\\' as '\\\\'" do
- subject.escape("hello\\ world").should == "hello\\\\ world"
- end
+ let(:text) { "hello\nworld" }
- it "should escape '-' as '\\-'" do
- subject.escape("foo-bar").should == "foo\\-bar"
+ described_class::GLYPHS.each do |char,glyph|
+ it "should convert #{char.dump} into #{glyph.dump}" do
+ subject.escape("#{text} #{char}").should == "#{text} #{glyph}"
+ end
end
end
end