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

  describe 'whitespace removal' do
    it 'removes outer whitespace by >' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span>a</span><span>b</span>
        <span>c</span><span>
        d
        </span><span>
        e
        </span>
        <span>f</span>
      HTML
        %span> a
        %span b
        %span c
        %span>
          d
        %span
          e
        %span f
      HAML
    end

    it 'removes top-level outer whitespaces with >' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        a<br>b
      HTML
        - if true
          a
        %br>
        b
      HAML
    end

    it 'removes top-level outer whitespaces with >' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        a<br>c
      HTML
        - if true
          a
        - else
          b
        %br>
        c
      HAML
    end

    it 'removes outer whitespace by > from inside of block' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <span>a</span><span>
        b
        </span><span>
        c
        </span>
      HTML
        %span a
        - if true
          %span>
            b
        %span
          c
      HAML
    end

    it 'removes whitespaces inside block script' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent, disable_capture: true)
        <span>foofoo2<span>bar</span></span>
      HTML
        %span<
          = 2.times do
            = 'foo'
          %span> bar
      HAML
    end

    it 'removes whitespace inside script inside silent script' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <div class='bar'>foofoofoo</div>
      HTML
        .bar<
          - 3.times do
            = 'foo'
      HAML
    end

    it 'removes whitespace inside script recursively' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent, disable_capture: true)
        <div class='foo'>bar1bar1bar1bar12</div>
      HTML
        .foo<
          - 1.times do
            = 2.times do
              - 2.times do
                = 1.times do
                  = 'bar'
      HAML
    end

    it 'does not remove whitespace after string interpolation' do
      assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
        <div>helloworld</div>
      HTML
        %div<
          #{'hello'}
          world
      HAML
    end

    it 'removes whitespace inside script inside silent script' do
      assert_render(<<-HTML.unindent, <<-HAML.unindent)
        <div class='bar'>12</div>
      HTML
        .bar<
          - 1.times do
            = '1'
            = '2'
      HAML
    end

    it 'does not nuke internal recursively' do
      assert_render(%Q|<div><span>\nhello\n</span></div>|, <<-HAML.unindent)
        %div><
          %span>
            hello
      HAML
    end

    it 'does not nuke inside script' do
      assert_render(%Q|<div><span>\nhello\n</span>1</div>|, <<-HAML.unindent, disable_capture: true)
        %div><
          = 1.times do
            %span>
              hello
      HAML
    end
  end
end