File: tag_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 (200 lines) | stat: -rw-r--r-- 3,964 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
describe Haml::Engine do
  include RenderHelper

  describe 'tag' do
    it 'renders one-line tag' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span>hello</span>
      HTML
        %span hello
      HAML
    end

    it 'accepts multi-line =' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span>o</span>
      HTML
        %span= 'hello'.gsub('hell',
          '')
      HAML
    end

    it 'renders multi-line tag' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span>
        hello
        </span>
      HTML
        %span
          hello
      HAML
    end

    it 'renders a nested tag' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span>
        <b>
        hello
        </b>
        <i>
        <small>world</small>
        </i>
        </span>
      HTML
        %span
          %b
            hello
          %i
            %small world
      HAML
    end

    it 'renders multi-line texts' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span>
        <b>
        hello
        world
        </b>
        </span>
      HTML
        %span
          %b
            hello
            world
      HAML
    end

    it 'ignores empty lines' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span>
        <b>
        hello
        </b>
        </span>
      HTML
        %span

          %b

            hello

      HAML
    end

    it 'renders classes' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span class='foo-1 bar_A'>hello</span>
      HTML
        %span.foo-1.bar_A hello
      HAML
    end

    it 'renders ids only last one' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span id='bar-'>
        hello
        </span>
      HTML
        %span#Bar_0#bar-
          hello
      HAML
    end

    it 'renders ids and classes' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span class='b d' id='c'>hello</span>
      HTML
        %span#a.b#c.d hello
      HAML
    end

    it 'renders implicit div tag starting with id' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <div class='world' id='hello'></div>
      HTML
        #hello.world
      HAML
    end

    it 'renders implicit div tag starting with class' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <div class='world' id='hello'>
        foo
        </div>
      HTML
        .world#hello
          foo
      HAML
    end

    it 'renders large-case tag' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <SPAN>
        foo
        </SPAN>
      HTML
        %SPAN
          foo
      HAML
    end

    it 'renders h1 tag' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <h1>foo</h1>
      HTML
        %h1 foo
      HAML
    end

    it 'renders tag including hyphen or underscore' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <-_>foo</-_>
      HTML
        %-_ foo
      HAML
    end

    it 'does not render silent script just after a tag' do
      assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
        <span->raise 'a'</span->
      HTML
        %span- raise 'a'
      HAML
    end

    it 'renders a text just after attributes' do
      assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
        <span a='2'>a</span>
      HTML
        %span{a: 2}a
      HAML
    end

    it 'strips a text' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span>foo</span>
      HTML
        %span    foo
      HAML
    end

    it 'ignores spaces after tag' do
      assert_render(<<-HTML.unindent, "%span  \n  a")
        <span>
        a
        </span>
      HTML
    end

    it 'parses self-closing tag' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent, format: :xhtml)
        <div />
        <div></div>
      HTML
        %div/
        %div
      HAML
    end
  end
end