| Class | BackDoorTagsTest |
| In: |
test/unit/back_door_tags_test.rb
|
| Parent: | Test::Unit::TestCase |
noTE be careful with spaces into the template strings
# File test/unit/back_door_tags_test.rb, line 119
119: def test_attribute_expansion
120: assert_render_match /.*?(#2).*?(id-4)/, %q{
121: <r:link anchor="#(1+1)" id='#"id-#{(2+2)}"' />
122: }
123: assert_render_match /\s+(\S+)\s+(\1)/, %q{
124: <r:ruby> self.to_s </r:ruby>
125: <r:ruby attr="#self.to_s">
126: tag.attr[ "attr"]
127: </r:ruby>
128: }
129: end
# File test/unit/back_door_tags_test.rb, line 26
26: def test_erb_tag
27: assert_renders "hello", %q{<r:erb><%= "hello" %></r:erb>}
28: assert_renders "0", %q{<r:erb><% n = 0 %><%= n %></r:erb>}
29: assert_renders "0123456789", %q{<r:erb>0<%= (1..8).inject( "") { |acc,n| acc + n.to_s }%>9</r:erb>}
30:
31: # this test should use a RE of /\s*2\s*3\s*4\s*5\s*1/, see the doc for the <r:erb> tag
32: assert_render_match /\s*2\s*2\s*2\s*2\s*2/, %q{
33: <r:erb>
34: <% <r:cycle values="1, 2, 3, 4, 5" reset="true"/> %>
35: <% 5.times do %>
36: <%= <r:cycle values="1, 2, 3, 4, 5"/> %>
37: <% end %>
38: </r:erb>
39: }
40:
41: assert_render_match /\s*2\s*3\s*4\s*5\s*1/, %q{
42: <r:erb>
43: <% <r:cycle values="1, 2, 3, 4, 5" reset="true"/> %>
44: <% 5.times do %>
45: <%=
46: <r:expand tag="cycle" values="1, 2, 3, 4, 5"/>
47: %>
48: <% end %>
49: </r:erb>
50: }
51: end
# File test/unit/back_door_tags_test.rb, line 53
53: def test_if_tag
54:
55: # if
56: assert_renders "true", %q{<r:if cond="true">true</r:if>}
57: assert_renders "", %q{<r:if cond="false">true</r:if>}
58: assert_raise BackDoorTags::TagError do
59: assert_renders "", %q{<r:if con="false">true</r:if>}
60: end
61:
62: # else
63: assert_renders "true", %q{<r:if cond="true">true<r:else>false</r:else></r:if>}
64: assert_renders "truetrue", %q{<r:if cond="true">true<r:else>false</r:else>true</r:if>}
65: assert_renders "false", %q{<r:if cond="false">true<r:else>false</r:else></r:if>}
66: assert_renders "false", %q{<r:if cond="false">true<r:else>false</r:else>true</r:if>}
67:
68: # side effects
69: assert_render_match /\s*1\s*/, %q{
70: <r:ruby>
71: @counter = 0
72: ""
73: </r:ruby>
74: <r:if cond="false">
75: This text is evaluated and igored, but the following "ruby" tag has a side effect that affects the "else" tag
76: <r:ruby> @counter += 1 </r:ruby>
77: <r:else> <r:ruby> @counter </r:ruby> </r:else>
78: </r:if>
79: }
80: end
# File test/unit/back_door_tags_test.rb, line 14
14: def test_ruby_tag
15: assert_renders "hello", %q{<r:ruby> "hello" </r:ruby>}
16: assert_renders "0", %q{<r:ruby> 0 </r:ruby>}
17: assert_renders "0123456789", %q{<r:ruby> (0..9).inject( "") { |acc,n| acc + n.to_s } </r:ruby>}
18:
19: # test that backdoor tags are executed in the same object context
20: assert_render_match /\s+(\S+)\s+(\1)/, %q{
21: <r:ruby> self.to_s </r:ruby>
22: <r:ruby> self.to_s </r:ruby>
23: }
24: end
# File test/unit/back_door_tags_test.rb, line 98
98: def test_tag_definition
99:
100: assert_render_match /01234567/, %q{
101: <r:tag name="test_tag">
102: raise TagError.new( "'test_tag' tag must contain a 'up_to' attribute.") unless tag.attr.has_key?( "up_to")
103: up_to = tag.attr[ "up_to"]
104: (0..up_to.to_i).inject( "") { |acc,n| acc + n.to_s }
105: </r:tag>
106: <r:test_tag up_to="7" />
107: }
108:
109: assert_render_match /(\s*Hello World!\s*){3}/, %q{
110: <r:erb_tag name="test_tag">
111: <% tag.attr[ "times"].to_i.times do %>
112: Hello <%= [ "W", "o", "r", "l", "d", "!"].join %>
113: <% end %>
114: </r:erb_tag>
115: <r:test_tag times="3" />
116: }
117: end
# File test/unit/back_door_tags_test.rb, line 82
82: def test_unless_tag
83:
84: # unless
85: assert_renders "false", %q{<r:unless cond="false">false</r:unless>}
86: assert_renders "", %q{<r:unless cond="true">true</r:unless>}
87: assert_raise BackDoorTags::TagError do
88: assert_renders "", %q{<r:unless con="true">false</r:unless>}
89: end
90:
91: # else
92: assert_renders "false", %q{<r:unless cond="true">true<r:else>false</r:else></r:unless>}
93: assert_renders "false", %q{<r:unless cond="true">true<r:else>false</r:else>true</r:unless>}
94: assert_renders "true", %q{<r:unless cond="false">true<r:else>false</r:else></r:unless>}
95: assert_renders "truetrue", %q{<r:unless cond="false">true<r:else>false</r:else>true</r:unless>}
96: end