require 'spec_helper'
module Hemingway
describe Parser do
before do
@parser = Parser.new
end
describe "#itemize" do
it 'allows me to create an itemized list' do
html = @parser.parse("\\begin{itemize}\\item thing 1 \\item thing 2 \\end{itemize}").html
html.should == "
"
end
it 'eats up any extra newlines and such between items' do
html = @parser.parse("\\begin{itemize}\\item thing 1 \n\n\n \\item thing 2 \n \\end{itemize}").html
html.should == ""
end
it 'supports text, tags, special chars, math inline' do
html = @parser.parse("\\begin{itemize}\\item hey \\emph{$\\lambda$} \\$ buddies \\end{itemize}").html
html.should == ""
end
it 'supports items to have labels on them with various spacing' do
html = @parser.parse("\\begin{itemize}\\item[bros] over hoes \\item \n [chicks] before dicks \\end{itemize}").html
html.should == "- bros over hoes
- chicks before dicks
"
end
it 'supports text, tags, special chars, and math in labels' do
html = @parser.parse("\\begin{itemize}\\item[so many \\emph{vibes} $\\lambda$ \\$ \\$] to be had \\end{itemize}").html
html.should == "- so many vibes λ $ $ to be had
"
end
it 'supports empty labels' do
html = @parser.parse("\\begin{itemize}\\item[] do or do not \\end{itemize}").html
html.should == ""
end
it 'supports empty items with labels' do
html = @parser.parse("\\begin{itemize}\\item[Millenium \\emph{Falcon}] \\item Slave-1 \\end{itemize}").html
html.should == ""
end
it 'supports empty items without labels' do
html = @parser.parse("\\begin{itemize}\\item \\item ears off a gundart \\end{itemize}").html
html.should == ""
end
it 'should allow me to nest some lists' do
html = @parser.parse("\\begin{itemize} \\item[another list] \\begin{itemize} \\item[nesting \\emph{vibes}] over here \\end{itemize} \\item for good measure \\end{itemize}").html
html.should == "- another list
- for good measure
"
end
it 'should nest 3 layers deep just for fun' do
html = @parser.parse("\\begin{itemize} \\item \\begin{itemize} \\item \\begin{itemize} \\item hey \\end{itemize} \\end{itemize} \\end{itemize}").html
html.should == ""
end
it 'allows me to created a nested list without specfying another item' do
html = @parser.parse("\\begin{itemize} \n \\item thing 1 \n \\begin{itemize} \n \\item 2 \n \\end{itemize} \n \\end{itemize}").html
html.should == ""
end
end
describe "#enumerate" do
it 'should allow me to create an ordered list' do
html = @parser.parse("\\begin{enumerate} \\item Frodo \\item Sam \\end{enumerate}").html
html.should == ""
end
it 'should allow me to nest an unordered list in an ordered list' do
html = @parser.parse("\\begin{enumerate} \\item \\begin{itemize} \\item Frodo \\item Pippin \\end{itemize} \\item Sam \\end{enumerate}").html
html.should == ""
end
end
describe "#description" do
it 'should allow me to create a dictionary list' do
html = @parser.parse("\\begin{description} \\item Frodo \\item Sam \\end{description}").html
html.should == ""
end
it 'should wrap labels in the dictionary label tag' do
html = @parser.parse("\\begin{description} \\item [Frodo] Adventuerer \\item [Sam] Faithful Companion \\end{description}").html
html.should == "- Frodo
Adventuerer - Sam
Faithful Companion
"
end
end
end
end