summaryrefslogtreecommitdiff
path: root/spec/inline_quoted_spec.rb
blob: a292bc5b8b12a6d9287ebccd1bc78a6092cacad0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# frozen_string_literal: true

require_relative 'spec_helper'

describe 'Asciidoctor::Epub3::Converter - Inline Quoted' do
  subject { Asciidoctor::Epub3::Converter.new('epub3').convert_inline_quoted node }

  let(:parent) { instance_double('parent').as_null_object }
  let(:node) { Asciidoctor::Inline.new parent, :bar, 'text', type: type }

  it 'resolves inline quotes' do
    book, = to_epub fixture_file('inline-quote/book.adoc')
    chapter = book.item_by_href 'chapter.xhtml'
    expect(chapter).not_to be_nil
    expect(chapter.content).to include '<p><span class="inline-quote">Knowledge kills action; action requires the veils of illusion.</span></p>'
    expect(chapter.content).to include '<p><strong>enclosed in asterisk characters</strong></p>'
    expect(chapter.content).to include '<p>enclosed in plus characters</p>'
    expect(chapter.content).to include "<p>`single grave accent to the left and a single acute accent to the right'</p>"
    expect(chapter.content).to include "<p>``two grave accents to the left and two acute accents to the right''</p>"
    expect(chapter.content).to include '<p><mark>hashes around text</mark></p>'
  end

  context 'double' do
    let(:type) { :double }

    it 'wraps with double quotes' do
      expect(subject).to eq(%(“text”))
    end
  end

  context 'single' do
    let(:type) { :single }

    it 'wraps with single quotes' do
      expect(subject).to eq(%(‘text’))
    end
  end

  context 'strong' do
    let(:type) { :strong }

    it 'renders as strong element' do
      expect(subject).to eq('<strong>text</strong>')
    end
  end

  context 'monospaced' do
    let(:type) { :monospaced }

    it 'renders as code element' do
      expect(subject).to eq('<code class="literal">text</code>')
    end
  end

  context 'latexmath' do
    let(:type) { :latexmath }

    it 'renders as code element' do
      expect(subject).to eq('<code class="literal">text</code>')
    end
  end

  context 'with role' do
    let :node do
      Asciidoctor::Inline.new parent, :bar, 'text', type: type, attributes: { 'role' => 'foo' }
    end

    context 'emphasis' do
      let(:type) { :emphasis }

      it 'puts role as class' do
        expect(subject).to eq('<em class="foo">text</em>')
      end
    end

    context 'double' do
      let(:type) { :double }

      it 'wraps with span element and puts role as class' do
        expect(subject).to eq('<span class="foo">“text”</span>')
      end
    end

    context 'custom type' do
      let(:type) { :custom_type }

      it 'wraps with span element and puts role as class' do
        expect(subject).to eq('<span class="foo">text</span>')
      end
    end
  end

  context 'with id' do
    let(:node) { Asciidoctor::Inline.new parent, :bar, 'text', type: type, id: 'ID' }

    context 'emphasis' do
      let(:type) { :emphasis }

      it 'puts role as class' do
        expect(subject).to eq('<em id="ID">text</em>')
      end
    end

    context 'double' do
      let(:type) { :double }

      it 'wraps with span element and puts role as class' do
        expect(subject).to eq('<span id="ID">“text”</span>')
      end
    end

    context 'custom type' do
      let(:type) { :custom_type }

      it 'wraps with span element and puts role as class' do
        expect(subject).to eq('<span id="ID">text</span>')
      end
    end
  end

  context 'with id and role' do
    let :node do
      Asciidoctor::Inline.new parent, :bar, 'text', type: type, id: 'ID', attributes: { 'role' => 'foo' }
    end

    context 'emphasis' do
      let(:type) { :emphasis }

      it 'puts role as class' do
        expect(subject).to eq('<em id="ID" class="foo">text</em>')
      end
    end

    context 'double' do
      let(:type) { :double }

      it 'wraps with span element and puts role as class' do
        expect(subject).to eq('<span id="ID" class="foo">“text”</span>')
      end
    end

    context 'custom type' do
      let(:type) { :custom_type }

      it 'wraps with span element and puts role as class' do
        expect(subject).to eq('<span id="ID" class="foo">text</span>')
      end
    end
  end
end