
import unittest

from contemplation import Template, Context

class RenderTests(unittest.TestCase):

    TEST_CASES = (
        # Raw text
        ('Hello!', {}, 'Hello!'),
        # Basic variable
        ('{{ i }}', {'i': 'Hello!'}, 'Hello!'),
        ('Hello, {{ foo }}!', {'foo': 'World'}, 'Hello, World!'),
        ('{{ a }} -- {{ b }}', {'a': 1, 'b': 'b'}, '1 -- b'),
        # Variable lookups
        ('{{ foo.bar }}', {'foo': {'bar': 'baz'}}, 'baz'),
        ('{{ foo.1 }}', {'foo': ['a', 'b']}, 'b'),
        ('{{ foo.title }}', {'foo': 'something'}, 'Something'),
        # XXX multi-level lookups
        # Comments
        ('abc{# comment #}def', {}, 'abcdef'),
        # Invalid syntax
        ('{% foo }}', {}, '{% foo }}'),
    )

    def test_good(self):
        for tmpl, ctx, output in self.TEST_CASES:
            t = Template(tmpl)
            c = Context(ctx)
            o = t.render(c)
            self.assertEqual(o, output)


if __name__ == '__main__':
    unittest.main()

@@ -733,16 +733,119 @@
 oo %7D%7D'),
+%0A%0A        # For tag%0A        ('%7B%25 for x in y %25%7D%7B%7B x %7D%7D%7B%25 endfor %25%7D', %7B'x': 'BAD', 'y': range(3)%7D, '012')
 %0A    )%0A%0A

Add test for ForNode