require 'spec_helper'
module RevealCK
module Markdown
describe PreProcessor do
describe 'handling ```notes' do
let :notes_input do
<<-EOS.strip_heredoc
```notes
This is a note
```
EOS
end
let :note_input do
<<-EOS.strip_heredoc
```note
This is a note
```
EOS
end
let :transformed_notes do
<<-EOS.strip_heredoc
DIVIDER
NOTES_OPEN
This is a note
NOTES_CLOSE
DIVIDER
EOS
end
it 'transforms ```notes into NOTES_OPEN
' do
output = PreProcessor.new(notes_input).process
expect(output).to include 'NOTES_OPEN
'
end
it 'transforms ```note into NOTES_OPEN
' do
output = PreProcessor.new(note_input).process
expect(output).to include 'NOTES_OPEN
'
end
it 'transforms the trailing ``` into NOTES_CLOSE
' do
output = PreProcessor.new(note_input).process
expect(output).to include 'NOTES_CLOSE
'
end
it 'transforms both open and close and adds some newlines' do
output = PreProcessor.new(notes_input).process
expect(output).to eq transformed_notes
end
end
it 'protects _s within emoji by turning them into a temporary token' do
input = ':money_with_wings:'
output = PreProcessor.new(input).process
expect(output).to include ':moneyEUwithEUwings:'
input = ':blue_heart:'
output = PreProcessor.new(input).process
expect(output).to include ':blueEUheart:'
input = ':non-potable_water:'
output = PreProcessor.new(input).process
expect(output).to include ':non-potableEUwater:'
end
let :standard_result do
<<-EOS.strip_heredoc
DIVIDER
First
DIVIDER
EOS
end
context 'without vertical slides' do
it 'wraps a document with DIVIDER
s' do
input = 'First'
output = PreProcessor.new(input).process
expect(output).to eq standard_result
end
it 'is consistent when starting+ending separators are used' do
input = <<-EOS.strip_heredoc
---
First
---
EOS
output = PreProcessor.new(input).process
expect(output).to eq standard_result
end
it 'is consistent when only starting separators are used' do
input = <<-EOS.strip_heredoc
---
First
EOS
output = PreProcessor.new(input).process
expect(output).to eq standard_result
end
it 'is consistent when only ending separators are used' do
input = <<-EOS.strip_heredoc
First
---
EOS
output = PreProcessor.new(input).process
expect(output).to eq standard_result
end
let :three_slides_input do
<<-EOS.strip_heredoc
First
---
Second
---
Third
EOS
end
let :three_slides_output do
<<-EOS.strip_heredoc
DIVIDER
First
DIVIDER
Second
DIVIDER
Third
DIVIDER
EOS
end
it 'can handle three slides' do
input = three_slides_input
output = PreProcessor.new(input).process
expect(output).to eq three_slides_output
end
end
context 'with vertical slides' do
let :single_vertical_output do
<<-EOS.strip_heredoc
VERTICAL_START
First
DIVIDER
Second
DIVIDER
Third
VERTICAL_END
EOS
end
context 'single vertical slide' do
it 'handles situation with no "closing" vertical' do
unbalanced_vertical_markdown = <<-EOS.strip_heredoc
***
First
---
Second
---
Third
EOS
output = PreProcessor.new(unbalanced_vertical_markdown).process
expect(output).to eq single_vertical_output
end
it 'handles situation with a "closing" vertical' do
balanced_vertical_markdown = <<-EOS.strip_heredoc
***
First
---
Second
---
Third
***
EOS
output = PreProcessor.new(balanced_vertical_markdown).process
expect(output).to eq single_vertical_output
end
end
context 'horizontal and vertical combinations' do
it 'handles vertical slides surrounded by horizontals' do
vertical_surrounded_by_horizontal = <<-EOS.strip_heredoc
First
***
Vertical 1
---
Vertical 2
---
Vertical 3
***
Last
EOS
output = PreProcessor.new(vertical_surrounded_by_horizontal).process
expect(output).to eq <<-EOS.strip_heredoc
DIVIDER
First
VERTICAL_START
Vertical 1
DIVIDER
Vertical 2
DIVIDER
Vertical 3
VERTICAL_END
Last
DIVIDER
EOS
end
it 'handles back-to-back vertical slides surrounded by horizontals' do
vertical_surrounded_by_horizontal = <<-EOS.strip_heredoc
First
***
Vertical A1
---
Vertical A2
---
Vertical A3
***
***
Vertical B1
---
Vertical B2
---
Vertical B3
***
Last
EOS
output = PreProcessor.new(vertical_surrounded_by_horizontal).process
expect(output).to eq <<-EOS.strip_heredoc
DIVIDER
First
VERTICAL_START
Vertical A1
DIVIDER
Vertical A2
DIVIDER
Vertical A3
VERTICAL_END
VERTICAL_START
Vertical B1
DIVIDER
Vertical B2
DIVIDER
Vertical B3
VERTICAL_END
Last
DIVIDER
EOS
end
it 'handles multiple vertical slides surrounded by horizontals' do
vertical_surrounded_by_horizontal = <<-EOS.strip_heredoc
First
***
Vertical A1
---
Vertical A2
---
Vertical A3
***
Middle
***
Vertical B1
---
Vertical B2
---
Vertical B3
***
Last
EOS
output = PreProcessor.new(vertical_surrounded_by_horizontal).process
expect(output).to eq <<-EOS.strip_heredoc
DIVIDER
First
VERTICAL_START
Vertical A1
DIVIDER
Vertical A2
DIVIDER
Vertical A3
VERTICAL_END
Middle
VERTICAL_START
Vertical B1
DIVIDER
Vertical B2
DIVIDER
Vertical B3
VERTICAL_END
Last
DIVIDER
EOS
end
end
end
end
end
end