File: text_test.rb

package info (click to toggle)
ruby-haml 6.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,004 kB
  • sloc: ruby: 9,908; sh: 23; makefile: 11
file content (212 lines) | stat: -rw-r--r-- 5,358 bytes parent folder | download | duplicates (2)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
describe Haml::Engine do
  include RenderHelper

  describe 'text' do
    it 'renders string interpolation' do
      skip 'escape is not working well in truffleruby' if RUBY_ENGINE == 'truffleruby'
      assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
        a3aa" [&quot;1&quot;, 2] b " !
        a{:a=&gt;3}
        <ht2ml>
      HTML
        #{ "a#{3}a" }a" #{["1", 2]} b " !
        a#{{ a: 3 }}
        <ht#{2}ml>
      HAML
    end

    it 'escapes all operators by backslash' do
      assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
        a
        = 'a'
        -
      HTML
        = 'a'
        -
        \= 'a'
        \-
      HAML
    end

    it 'renders == operator' do
      skip 'escape is not working well in truffleruby' if RUBY_ENGINE == 'truffleruby'
      assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
        =
        =
        <a>
        &lt;a&gt;
      HTML
        ===
        == =
        == <a>
        == #{'<a>'}
      HAML
    end

    it 'renders !== operator' do
      skip 'escape is not working well in truffleruby' if RUBY_ENGINE == 'truffleruby'
      assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
        &lt;a&gt;
        <a>
        =
        =
      HTML
        == #{'<a>'}
        !== #{'<a>'}
        !===
        !== =
      HAML
    end

    it 'leaves empty spaces after backslash' do
      assert_render("       a\n", '\       a')
    end

    it 'renders spaced - properly' do
      assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
        <div>
        foo
        <div class='test'>- bar</div>
        <div class='test'>- baz</div>
        </div>
      HTML
        %div
          foo
          .test - bar
          .test - baz
      HAML
    end

    describe 'inline operator' do
      it 'renders ! operator' do
        assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
          <span><nyaa></span>
          <span><nyaa></span>
          <nyaa>
        HTML
          %span!#{'<nyaa>'}
          %span! #{'<nyaa>'}
          ! #{'<nyaa>'}
        HAML
      end

      it 'renders & operator' do
        skip 'escape is not working well in truffleruby' if RUBY_ENGINE == 'truffleruby'
        assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
          <span>&lt;nyaa&gt;</span>
          <span>&lt;nyaa&gt;</span>
          &lt;nyaa&gt;
        HTML
          %span& #{'<nyaa>'}
          %span&#{'<nyaa>'}
          & #{'<nyaa>'}
        HAML
      end

      it 'renders !, & operator right before a non-space character' do
        assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
          &nbsp;
          &nbsp;
          !hello
          !hello
        HTML
          &nbsp;
          \&nbsp;
          !hello
          \!hello
        HAML
      end

      it 'renders &, ! operator inside a tag' do
        assert_render(<<-HTML.unindent, <<-HAML.unindent)
          <span>&nbsp;</span>
          <span>nbsp;</span>
          <span>nbsp;</span>
          <span>!hello</span>
          <span>hello</span>
          <span>hello</span>
        HTML
          %span &nbsp;
          %span&nbsp;
          %span& nbsp;
          %span !hello
          %span!hello
          %span! hello
        HAML
      end

      it 'does not accept backslash operator' do
        assert_render(<<-'HTML'.unindent, <<-'HAML'.unindent)
          <span>\    foo</span>
        HTML
          %span\    foo
        HAML
      end

      it 'renders != operator' do
        assert_render(<<-HTML.unindent, <<-HAML.unindent)
          <span><nyaa></span>
        HTML
          %span!= '<nyaa>'
        HAML
      end

      it 'renders !== operator' do
        assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
          <span><nyaa></span>
          <span><nyaa></span>
          <nyaa>
          <nyaa>
        HTML
          %span!==#{'<nyaa>'}
          %span!== #{'<nyaa>'}
          !==#{'<nyaa>'}
          !== #{'<nyaa>'}
        HAML
      end

      it 'renders &= operator' do
        assert_render(<<-HTML.unindent, <<-HAML.unindent)
          <span>&lt;nyaa&gt;</span>
        HTML
          %span&= '<nyaa>'
        HAML
      end

      it 'renders &== operator' do
        skip 'escape is not working well in truffleruby' if RUBY_ENGINE == 'truffleruby'
        assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
          =
          =
          &lt;p&gt;
        HTML
          &===
          &== =
          &== #{'<p>'}
        HAML
      end

      it 'renders ~ operator' do
        assert_render(<<-HTML.unindent, <<-HAML.unindent, escape_html: false)
          <span>1</span>
        HTML
          %span~ 1
        HAML
      end
    end

    describe 'string interpolation' do
      it { assert_render("\n", '#{}') }
      it { assert_render("1\n", '1#{}') }
      it { assert_render("12\n", '1#{2}') }
      it { assert_render("}1\n", '}#{1}') }
      it { assert_render("12\n", '#{1}2') }
      it { assert_render("12345\n", '1#{ "2#{3}4" }5') }
      it { assert_render("123456789\n", '#{1}2#{3}4#{5}6#{7}8#{9}') }
      it { assert_render(%Q{'"!@$%^&*|=1112\n}, %q{'"!@$%^&*|=#{1}1#{1}2}) }
      it { assert_render("あ1\n", 'あ#{1}') }
      it { assert_render("あいう\n", 'あ#{"い"}う') }
      it { assert_render("a&lt;b&gt;c\n", 'a#{"<b>"}c') } if RUBY_ENGINE != 'truffleruby' # escape is not working in truffleruby
    end
  end
end