# encoding=utf-8 require 'spec_helper' describe 'Polytexnic::Pipeline#to_html' do subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html } describe "comments" do let(:polytex) { "% A LaTeX comment" } it { should eq '' } context "with a section and label" do let(:polytex) do <<-'EOS' % \section{Foo} % \label{sec:foo} EOS end it { should eq '' } end context "with a manual break" do let(:polytex) { 'foo \\\\ bar' } it { should include '' } end context "with a code listing" do let(:polytex) do <<-'EOS' % \begin{codelisting} % \heading{A hello program in Ruby.} % \label{code:hello} % %= lang:ruby % \begin{code} % def hello % "hello, world!" % end % \end{code} % \end{codelisting} EOS end it { should eq '' } end context "with a code inclusion" do let(:polytex) { '% %= << spec/spec_helper.rb' } it { should eq '' } end context "with a literal percent" do let(:polytex) { '87.3\% of statistics are made up' } it { should resemble '87.3% of statistics are made up' } end context "with characters before the percent" do let(:polytex) { 'foo % bar' } it { should resemble 'foo' } end context "with two percent signs" do let(:polytex) { 'foo % bar % baz' } it { should resemble 'foo' } end context "with display math" do let(:polytex) do <<-'EOS' % \[ % \begin{bmatrix} % 1 & \cdots & 0 \\ % \vdots & \ddots & \vdots \\ % 2 & \cdots & 0 % \end{bmatrix} % \] EOS end it { should eq '' } end end describe "a complete document" do let(:polytex) do <<-'EOS' \documentclass{book} \begin{document} lorem ipsum \end{document} EOS end it { should resemble "

lorem ipsum

" } end describe "paragraphs" do let(:polytex) { 'lorem ipsum' } it { should resemble "

lorem ipsum

" } it { should_not resemble '' } end describe '\maketitle' do context "with all elements filled out explicitly" do let(:polytex) do <<-'EOS' \title{Foo \\ \emph{Bar}} \subtitle{Baz} \author{Michael Hartl} \date{January 1, 2013} \begin{document} \maketitle \end{document} EOS end it do should resemble <<-'EOS'

Foo Bar

Baz

Michael Hartl

January 1, 2013

EOS end it "should not have repeated title elements" do expect(processed_text.scan(/Michael Hartl/).length).to eq 1 end end context "with Unicode" do let(:polytex) do <<-'EOS' \title{A könyv címe} \subtitle{Alcím - itt lesz az alcím} \author{Árvíztűrő fúrógép} \date{January 1, 2013} \begin{document} \maketitle \end{document} EOS end it do should resemble <<-'EOS'

A könyv címe

Alcím - itt lesz az alcím

Árvíztűrő fúrógép

January 1, 2013

EOS end end context "when date is blank" do let(:polytex) do <<-'EOS' \title{Foo \\ \emph{Bar}} \subtitle{Baz} \author{Michael Hartl} \date{} \begin{document} \maketitle \end{document} EOS end it do should resemble <<-'EOS'

Foo Bar

Baz

Michael Hartl

EOS end end context "when date is missing" do let(:polytex) do <<-'EOS' \title{Foo \\ \emph{Bar}} \subtitle{Baz} \author{Michael Hartl} \begin{document} \maketitle \end{document} EOS end it { should resemble '

' } it "should include today's date" do expect(processed_text).to resemble Date.today.strftime("%A, %b %e") end end end describe "double backslashes" do let(:polytex) { 'foo \\\\ bar' } let(:output) { 'foo bar' } it { should resemble output } end describe "unknown command" do let(:polytex) { '\foobar' } let(:output) { '' } it { should resemble output } end describe "href" do context "standard URL" do let(:polytex) { '\href{http://example.com/}{Example Site}' } let(:output) { 'Example Site' } it { should resemble output } end context "URL containing TeX" do let(:polytex) { '\href{http://example.com/}{\emph{\TeX}}' } let(:output) { '' } it { should resemble output } end context "URL containing escaped text" do let(:polytex) { '\href{http://example.com/escaped\_text}{Example Site}' } it { should include 'Example Site' } end end describe "centering" do let(:polytex) do <<-'EOS' \begin{center} Lorem ipsum dolor sit amet \end{center} EOS end let(:output) do <<-'EOS'

Lorem ipsum

dolor sit amet

EOS end it { should resemble output } end describe "skips" do context "bigskip" do let(:polytex) { '\bigskip' } it { should resemble '