| | 297 | |
| | 298 | def test_cannot_define_macro_to_override_reserved_statements(self): |
| | 299 | for reserved in ('if', 'else', 'elseif', 'set', 'macro', 'foreach', 'parse', 'include', 'stop', 'end'): |
| | 300 | template = airspeed.Template('#macro ( %s $value) $value #end' % reserved) |
| | 301 | self.assertRaises(airspeed.TemplateSyntaxError, template.merge, {}) |
| | 302 | |
| | 303 | def test_cannot_call_undefined_macro(self): |
| | 304 | template = airspeed.Template('#undefined()') |
| | 305 | self.assertRaises(Exception, template.merge, {}) |
| | 306 | |
| | 307 | def test_define_and_use_macro_with_no_parameters(self): |
| | 308 | template = airspeed.Template('#macro ( hello)hi#end#hello ()#hello()') |
| | 309 | self.assertEquals('hihi', template.merge({'text': 'hello'})) |
| | 310 | |
| | 311 | def test_define_and_use_macro_with_one_parameter(self): |
| | 312 | template = airspeed.Template('#macro ( bold $value)<strong>$value</strong>#end#bold ($text)') |
| | 313 | self.assertEquals('<strong>hello</strong>', template.merge({'text': 'hello'})) |
| | 314 | |
| | 315 | def test_use_of_macro_name_is_case_insensitive(self): |
| | 316 | template = airspeed.Template('#macro ( bold $value)<strong>$value</strong>#end#BoLd ($text)') |
| | 317 | self.assertEquals('<strong>hello</strong>', template.merge({'text': 'hello'})) |
| | 318 | |
| | 319 | def test_define_and_use_macro_with_two_parameter(self): |
| | 320 | template = airspeed.Template('#macro (addition $value1 $value2 )$value1+$value2#end#addition (1 2)') |
| | 321 | self.assertEquals('1+2', template.merge({})) |
| | 322 | template = airspeed.Template('#macro (addition $value1 $value2 )$value1+$value2#end#addition( $one $two )') |
| | 323 | self.assertEquals('ONE+TWO', template.merge({'one': 'ONE', 'two': 'TWO'})) |
| | 324 | |
| | 325 | def test_cannot_redefine_macro(self): |
| | 326 | template = airspeed.Template('#macro ( hello)hi#end#macro(hello)again#end') |
| | 327 | self.assertRaises(Exception, template.merge, {}) ## Should this be TemplateSyntaxError? |
| | 328 | |