コード例 #1
0
    def test_forHeadBodyFoot(self):
        zbr = zebra.trim("""
            * for people:
                * head:
                    PEOPLE
                    -------
                * body:
                    {?name?} is a nice person.
                * foot:
                    -------
                    THE END
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <for series="people">
            <head>
            PEOPLE<nl/>
            -------<nl/>
            </head>
            <body>
            <var>name</var> is a nice person.<nl/>
            </body>
            <foot>
            -------<nl/>
            THE END<nl/>
            </foot>
            </for>
            </zebra>
            """)

        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "Doesn't do for/head/body/foot right:\n%s" % actual
コード例 #2
0
    def test_exec(self):
        zbr = zebra.trim("""
            * exec:
                name = 'fred'
                xml = '<xml>woohoo!</xml>'
                dict = {}
                dict['a'] = 'b'

                hope(there_was_no_nl_tag_there)
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <exec>
            name = 'fred'
            xml = '&lt;xml&gt;woohoo!&lt;/xml&gt;'
            dict = {}
            dict['a'] = 'b'

            hope(there_was_no_nl_tag_there)
            </exec>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope well with exec:\n%s" % actual
コード例 #3
0
    def test_expr(self):
        zbr = zebra.trim("""
            I will be {:age + 4:} next year.
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            I will be <xpr>age + 4</xpr> next year.<nl/>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope well with {:exprs:}:\n%s" % actual
コード例 #4
0
    def test_invalid(self):
        "check invalid tags"
        zbr = zebra.trim("""
            * thisIsAnInvalidTag
            """)
        try:
            zebra.Z2X().translate(zbr)
        except:
            gotError = 1
        else:
            gotError = 0

        assert gotError, \
               "Didn't get error on invalid tag."
コード例 #5
0
    def test_include(self):
        #@TODO: drop trailing : from include syntax
        zbr = zebra.trim("""
            * include includefile:
            """)

        #@TODO: it should realy be <include file="includefile"/>
        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <include file="includefile">
            </include>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't handle includes right:\n%s" % actual
コード例 #6
0
 def test_comment(self):
     zbr = zebra.trim("""
         *# this is a comment
         this isn't
         *     # this is
         """)
     goal = zebra.trim("""
         <?xml version="1.0"?>
         <zebra>
         <rem>this is a comment</rem>
         this isn't<nl/>
         <rem>this is</rem>
         </zebra>
         """)
     actual = zebra.Z2X().translate(zbr)
     assert actual==goal, \
            "doesn't handle comments right:\n%s" % actual
コード例 #7
0
    def test_var(self):
        zbr = zebra.trim("""
            {
            My name is {?name?}.
            }
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            {<nl/>
            My name is <var>name</var>.<nl/>
            }<nl/>
            </zebra>
            """)
        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "doesn't cope well with {?vars?}:\n%s" % actual
コード例 #8
0
    def test_notBlocks(self):
        zbr = zebra.trim("""
            * if x==1:
                * include page_one;
            * ef x==2:
                * include page_two;
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <if condition="x==1">
            <include file="page_one"/>
            </if>
            <ef condition="x==2">
            <include file="page_two"/>
            </ef>
            </zebra>
            """)

        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "Doesn't handle ; blocks right:\n%s" % actual
コード例 #9
0
    def test_forNone(self):
        zbr = zebra.trim("""
            * for people:
                {?name?} is a nice person.
            * none:
                No people here!
            """)

        goal = zebra.trim("""
            <?xml version="1.0"?>
            <zebra>
            <for series="people">
            <var>name</var> is a nice person.<nl/>
            </for>
            <none>
            No people here!<nl/>
            </none>
            </zebra>
            """)

        actual = zebra.Z2X().translate(zbr)
        assert actual==goal, \
               "Doesn't do for..none right:\n%s" % actual