-
Notifications
You must be signed in to change notification settings - Fork 53
/
test_code_blocks.rb
106 lines (83 loc) · 2.49 KB
/
test_code_blocks.rb
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
require 'helper'
class TestSkimCodeBlocks < TestSkim
def test_render_with_output_code_block
source = %q{
p
= @callback "Hello Ruby!", -> 'Hello from within a block!'
}
assert_html '<p>Hello Ruby! Hello from within a block! Hello Ruby!</p>', source
end
def test_render_with_output_code_within_block
source = %q{
p
= @callback "Hello Ruby!", => @callback "Hello from within a block!"
}
assert_html '<p>Hello Ruby! Hello from within a block! Hello Ruby!</p>', source
end
def test_render_with_output_code_within_block_2
source = %q{
p
= @callback "Hello Ruby!", => @callback "Hello from within a block!", => @callback "And another one!"
}
assert_html '<p>Hello Ruby! Hello from within a block! And another one! Hello from within a block! Hello Ruby!</p>', source
end
def test_output_block_with_arguments
source = %q{
p
= @define_macro 'person', (first_name, last_name) => "<div class=\"first_name\">#{first_name}</div><div class=\"last_name\">#{last_name}</div>"
== @call_macro 'person', 'John', 'Doe'
== @call_macro 'person', 'Max', 'Mustermann'
}
assert_html '<p><div class="first_name">John</div><div class="last_name">Doe</div><div class="first_name">Max</div><div class="last_name">Mustermann</div></p>', source
end
def test_render_with_control_code_forEach_loop
source = %q{
p
- [0..2].forEach =>
| Hey!
}
assert_html '<p>Hey!Hey!Hey!</p>', source
end
def test_render_with_control_code_for_in_loop
source = %q{
p
- for i in [0..2]
| Hey!
}
assert_html '<p>Hey!Hey!Hey!</p>', source
end
def test_render_with_control_code_for_in_loop_without_parent
source = %q{
- for i in [0..2]
p Hey!
}
assert_html '<p>Hey!</p><p>Hey!</p><p>Hey!</p>', source
end
def test_render_with_control_code_for_own_of_loop
source = %q{
p
- for own key, value of {user: 'name'}
| #{key} #{value}
}
assert_html '<p>user name</p>', source
end
def test_captured_code_block_with_conditional
source = %q{
= @callback "Hello Ruby!", -> 'Hello from within a block!' if true
}
assert_html 'Hello Ruby! Hello from within a block! Hello Ruby!', source
end
def test_attribute_merger
source = %q{
.hello class='ruby' Hello Ruby!
}
assert_html '<div class="hello ruby">Hello Ruby!</div>', source
end
def test_attribute_merger_with_not_static_class_attr
source = %q{
- class_name = 'ruby'
.hello class=class_name Hello Ruby!
}
assert_html '<div class="hello ruby">Hello Ruby!</div>', source
end
end