File: test_mab_indentation.rb

package info (click to toggle)
ruby-mab 0.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 272 kB
  • sloc: ruby: 740; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,023 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
require 'helper'

class TestMabIndentation < MiniTest::Unit::TestCase
  def setup
    super
    @obj = Object.new
    @obj.extend Mab::Mixin
    @obj.extend Mab::Indentation
  end

  def test_simple
    assert_equal "<p>Hello</p>", @obj.mab { tag! :p, 'Hello' }
  end

  def test_block
    assert_equal "<p>\n  Hello\n</p>", @obj.mab { tag!(:p) { text 'Hello' } }
  end

  def test_chaining
    res = <<HTML.strip
<p class="hello">
  <br>
</p>
HTML

    assert_equal res, @obj.mab {
      tag!(:p).hello do
        tag! :br
      end
    }
  end

  def test_reindent
    res = <<HTML.strip
<p>
  Hello
  World
</p>
HTML

    assert_equal res, @obj.mab {
      tag! :p do
        reindent! "Hello\nWorld"
      end
    }
  end

  def test_stringification
    res = <<HTML.strip
<h1>
  <div><span>Hello</span> | <span>Hello</span></div>
</h1>
HTML

    assert_equal res, @obj.mab {
      tag!(:h1) do
        s = tag!(:span, 'Hello')
        tag!(:div) do
          [s, s].join(' | ')
        end
      end

    }
  end
end