File: whitespace_test.rb

package info (click to toggle)
ruby-hamlit 2.11.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,360 kB
  • sloc: ruby: 10,707; ansic: 552; sh: 23; makefile: 8
file content (115 lines) | stat: -rw-r--r-- 2,573 bytes parent folder | download | duplicates (4)
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
describe Hamlit::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 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)
        <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)
        <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)
        %div><
          = 1.times do
            %span>
              hello
      HAML
    end
  end
end