require 'spec_helper'
describe Mastalk::Document do
context 'Without mastalk syntax' do
let(:context) { "###test\nwith markdown" }
let(:expected) { "
test
\nwith markdown
\n" }
subject { Mastalk::Document.new(context) }
it 'kramdown behaviour with no tags' do
expect(Mastalk::Document.new('test').to_html).to eq("test
\n")
end
it 'converts to html' do
expect(subject.to_html).to eq(expected)
end
context 'multiline' do
let(:expected) { "TEST
\n\nwith other stuff
\n\n" }
let(:context) { "### TEST\r\n\r\nwith other stuff\r\n\r\n " }
it 'converts to html' do
expect(subject.to_html).to eq(expected)
end
end
end
subject { Mastalk::Document.new(source) }
let(:expected) { "test
\n" }
context 'custom extension' do
let(:source) { '$Etest$E' }
it 'pre-processes custom tags' do
subject.extension('$E') { |body| "#{body}
" }
expect(subject.to_html).to eq(expected)
end
context 'multi line' do
let(:source) { '$Etest$E$Shello$FIN' }
let(:expected) { "test
\nhello
\n" }
it 'processes multi line' do
subject.extension('$E') { |body| "#{body}
" }
subject.extension('$S', '$FIN') { |body| "#{body}
" }
expect(subject.to_html).to eq(expected)
end
end
end
context 'extension with start and stop' do
let(:source) { '$STARTtest$END' }
it 'pre-processes custom tags' do
subject.extension('$START', '$END') { |body| "#{body}
" }
expect(subject.to_html).to eq(expected)
end
end
context 'extension with other extensions inside' do
let(:source) { "$why\n###header\nbody\n$why" }
let(:expected) { "\n" }
it 'parses nested structures' do
expect(subject.to_html).to eq(expected)
end
end
context 'with newline as end' do
let(:source) { "$yes-no\n [y] yes \n [n] no \n $end $why\n###header\nbody\n$why" }
let(:expected) do
"\n\n"
end
it 'pre-processes custom tags' do
expect(subject.to_html).to eq(expected)
end
end
context 'two matches after each other' do
let(:source) { "$yes-no\n [y] yes \n $end $yes-no\ [n] no \n $end" }
let(:expected) do
"\n\n"
end
it 'pre-processes correctly' do
expect(subject.to_html).to eq(expected)
end
end
context 'two callouts after each other' do
let(:source) { "$~callout\n ##yes ~$ $~callout\n ##yes ~$" }
let(:expected) do
"\n
yes
\n\n\n\n
yes
\n\n\n"
end
it 'pre-processes correctly' do
expect(subject.to_html).to eq(expected)
end
end
end