Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
20c10a5c
Commit
20c10a5c
authored
Mar 28, 2001
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TAL testcases. Still to do METAL testcases.
parent
6fffa8d4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
378 additions
and
66 deletions
+378
-66
lib/python/TAL/test/test_htmltalparser.py
lib/python/TAL/test/test_htmltalparser.py
+189
-33
lib/python/TAL/tests/test_htmltalparser.py
lib/python/TAL/tests/test_htmltalparser.py
+189
-33
No files found.
lib/python/TAL/test/test_htmltalparser.py
View file @
20c10a5c
...
...
@@ -11,12 +11,25 @@ from TAL import HTMLTALParser
from
TAL.TALDefs
import
TAL_VERSION
class
HTMLTALParserTestCases
(
unittest
.
TestCase
):
class
TestCaseBase
(
unittest
.
TestCase
):
prologue
=
""
epilogue
=
""
initial_program
=
[(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
)]
final_program
=
[]
def
_merge
(
self
,
p1
,
p2
):
if
p1
and
p2
and
p1
[
-
1
][
0
]
==
'rawtext'
and
p2
[
0
][
0
]
==
'rawtext'
:
return
p1
[:
-
1
]
+
[(
'rawtext'
,
p1
[
-
1
][
1
]
+
p2
[
0
][
1
])]
+
p2
[
1
:]
else
:
return
p1
+
p2
def
_run_check
(
self
,
source
,
program
,
macros
=
{}):
parser
=
HTMLTALParser
.
HTMLTALParser
()
parser
.
parseString
(
s
ourc
e
)
parser
.
parseString
(
s
elf
.
prologue
+
source
+
self
.
epilogu
e
)
got_program
,
got_macros
=
parser
.
getCode
()
program
=
self
.
_merge
(
self
.
initial_program
,
program
)
program
=
self
.
_merge
(
program
,
self
.
final_program
)
self
.
assert_
(
got_program
==
program
,
got_program
)
self
.
assert_
(
got_macros
==
macros
,
got_macros
)
...
...
@@ -27,23 +40,20 @@ class HTMLTALParserTestCases(unittest.TestCase):
pprint
.
pprint
(
got_program
)
pprint
.
pprint
(
got_macros
)
class
HTMLTALParserTestCases
(
TestCaseBase
):
def
check_code_simple_identity
(
self
):
self
.
_run_check
(
"""<html a='b' b="c" c=d><title>My Title</html>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<html a="b" b="c" c="d">'
'<title>My Title</title></html>'
),
])
def
check_code_implied_list_closings
(
self
):
self
.
_run_check
(
"""<ul><li><p><p><li></ul>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<ul><li><p></p><p></p></li><li></li></ul>'
),
])
self
.
_run_check
(
"""<dl><dt><dt><dd><dd><ol><li><li></ol></dl>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<dl><dt></dt><dt></dt><dd></dd>'
'<dd><ol><li></li><li></li></ol></dd></dl>'
),
])
...
...
@@ -51,16 +61,12 @@ class HTMLTALParserTestCases(unittest.TestCase):
def
check_code_implied_table_closings
(
self
):
self
.
_run_check
(
"""<p>text <table><tr><th>head
\
t
<tr><td>cell
\
t
"""
"""<table><tr><td>cell
\
n
\
t
\
n
<tr>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<p>text</p> <table><tr><th>head</th>'
'</tr>
\
t
<tr><td>cell
\
t
<table><tr><td>cell</td>'
'</tr>
\
n
\
t
\
n
<tr></tr></table></td></tr></table>'
),
])
self
.
_run_check
(
"""<table><tr><td>cell """
"""<table><tr><td>cell </table></table>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<table><tr><td>cell <table><tr><td>cell</td></tr>'
' </table></td></tr></table>'
),
])
...
...
@@ -72,8 +78,6 @@ class HTMLTALParserTestCases(unittest.TestCase):
def
check_code_attr_syntax
(
self
):
output
=
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="v" c="v" d="v" e></a>'
),
]
self
.
_run_check
(
"""<a b='v' c="v" d=v e>"""
,
output
)
...
...
@@ -84,68 +88,220 @@ class HTMLTALParserTestCases(unittest.TestCase):
def
check_code_attr_values
(
self
):
self
.
_run_check
(
"""<a b='xxx
\
n
\
t
xxx' c="yyy
\
t
\
n
yyy" d='
\
t
xyz
\
n
'>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="xxx
\
n
\
t
xxx" c="yyy
\
t
\
n
yyy" d="
\
t
xyz
\
n
"></a>'
)])
self
.
_run_check
(
"""<a b='' c="" d=>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="" c="" d=""></a>'
),
])
def
check_code_attr_entity_replacement
(
self
):
# we expect entities *not* to be replaced by HTLMParser!
self
.
_run_check
(
"""<a b='&><"''>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="&><"
\
'
"></a>'
),
])
self
.
_run_check
(
"""<a b='
\
"
'>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
"<a b='
\
"
'></a>"
),
])
self
.
_run_check
(
"""<a b='&'>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="&"></a>'
),
])
self
.
_run_check
(
"""<a b='<'>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="<"></a>'
),
])
def
check_code_attr_funky_names
(
self
):
self
.
_run_check
(
"""<a a.b='v' c:d=v e-f=v>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a a.b="v" c:d="v" e-f="v"></a>'
),
])
def
check_code_pcdata_entityref
(
self
):
self
.
_run_check
(
""" """
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
' '
),
])
def
check_code_short_endtags
(
self
):
self
.
_run_check
(
"""<html><img/></html>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<html><img/></html>'
),
])
class
TALGeneratorTestCases
(
TestCaseBase
):
def
check_null
(
self
):
self
.
_run_check
(
""
,
[])
def
check_define
(
self
):
self
.
_run_check
(
"<p tal:define='xyzzy string:spam'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'xyzzy'
,
'$string:spam$'
),
(
'rawtext'
,
'<p tal:define="xyzzy string:spam"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='local xyzzy string:spam'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'xyzzy'
,
'$string:spam$'
),
(
'rawtext'
,
'<p tal:define="local xyzzy string:spam"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='global xyzzy string:spam'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setGlobal'
,
'xyzzy'
,
'$string:spam$'
),
(
'rawtext'
,
'<p tal:define="global xyzzy string:spam"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='x string:spam; y x'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'x'
,
'$string:spam$'
),
(
'setLocal'
,
'y'
,
'$x$'
),
(
'rawtext'
,
'<p tal:define="x string:spam; y x"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='x string:;;;;; y x'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'x'
,
'$string:;;$'
),
(
'setLocal'
,
'y'
,
'$x$'
),
(
'rawtext'
,
'<p tal:define="x string:;;;;; y x"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='x string:spam; global y x; local z y'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'x'
,
'$string:spam$'
),
(
'setGlobal'
,
'y'
,
'$x$'
),
(
'setLocal'
,
'z'
,
'$y$'
),
(
'rawtext'
,
'<p tal:define="x string:spam; global y x; local z y"></p>'
),
(
'endScope'
,),
])
def
check_condition
(
self
):
self
.
_run_check
(
"<p><span tal:condition='python:1'><b>foo</b></span></p>"
,
[
(
'rawtext'
,
'<p>'
),
(
'setPosition'
,
(
1
,
3
)),
(
'condition'
,
'$python:1$'
,
[(
'rawtext'
,
'<span tal:condition="python:1"><b>foo</b></span>'
)]),
(
'rawtext'
,
'</p>'
),
])
def
check_content
(
self
):
self
.
_run_check
(
"<p tal:content='string:foo'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'rawtext'
,
'<p tal:content="string:foo">'
),
(
'insertText'
,
'$string:foo$'
,
[(
'rawtext'
,
'bar'
)]),
(
'rawtext'
,
'</p>'
),
])
self
.
_run_check
(
"<p tal:content='text string:foo'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'rawtext'
,
'<p tal:content="text string:foo">'
),
(
'insertText'
,
'$string:foo$'
,
[(
'rawtext'
,
'bar'
)]),
(
'rawtext'
,
'</p>'
),
])
self
.
_run_check
(
"<p tal:content='structure string:<br>'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'rawtext'
,
'<p tal:content="structure string:<br>">'
),
(
'insertStructure'
,
'$string:<br>$'
,
{},
[(
'rawtext'
,
'bar'
)]),
(
'rawtext'
,
'</p>'
),
])
def
check_replace
(
self
):
self
.
_run_check
(
"<p tal:replace='string:foo'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'insertText'
,
'$string:foo$'
,
[(
'rawtext'
,
'<p tal:replace="string:foo">bar</p>'
)]),
])
self
.
_run_check
(
"<p tal:replace='text string:foo'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'insertText'
,
'$string:foo$'
,
[(
'rawtext'
,
'<p tal:replace="text string:foo">bar</p>'
)]),
])
self
.
_run_check
(
"<p tal:replace='structure string:<br>'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'insertStructure'
,
'$string:<br>$'
,
{},
[(
'rawtext'
,
'<p tal:replace="structure string:<br>">bar</p>'
)]),
])
def
check_repeat
(
self
):
self
.
_run_check
(
"<p tal:repeat='x python:(1,2,3)'>"
"<span tal:replace='x'>dummy</span></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'loop'
,
'x'
,
'$python:(1,2,3)$'
,
[(
'rawtext'
,
'<p tal:repeat="x python:(1,2,3)">'
),
(
'setPosition'
,
(
1
,
33
)),
(
'insertText'
,
'$x$'
,
[(
'rawtext'
,
'<span tal:replace="x">dummy</span>'
)]),
(
'rawtext'
,
'</p>'
)]),
(
'endScope'
,),
])
def
check_attributes
(
self
):
self
.
_run_check
(
"<a href='foo' name='bar' tal:attributes="
"'href string:http://www.zope.org; x string:y'>"
"link</a>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'startTag'
,
'a'
,
[(
'href'
,
'foo'
,
'replace'
,
'$string:http://www.zope.org$'
),
(
'name'
,
'bar'
),
(
'tal:attributes'
,
'href string:http://www.zope.org; x string:y'
),
(
'x'
,
''
,
'replace'
,
'$string:y$'
)]),
(
'rawtext'
,
'link</a>'
),
])
self
.
_run_check
(
"<p tal:replace='structure string:<img>' "
"tal:attributes='src string:foo.png'>duh</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'insertStructure'
,
'$string:<img>$'
,
{
'src'
:
'$string:foo.png$'
},
[(
'rawtext'
,
'<p tal:replace="structure string:<img>" '
'tal:attributes="src string:foo.png">duh</p>'
)]),
])
def
check_on_error
(
self
):
self
.
_run_check
(
"<p tal:on-error='string:error' "
"tal:content='notHere'>okay</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'onError'
,
[(
'rawtext'
,
'<p tal:on-error="string:error" tal:content="notHere">'
),
(
'insertText'
,
'$notHere$'
,
[(
'rawtext'
,
'okay'
)]),
(
'rawtext'
,
'</p>'
)],
[(
'rawtext'
,
'<p tal:on-error="string:error" tal:content="notHere">'
),
(
'insertText'
,
'$string:error$'
,
[]),
(
'rawtext'
,
'</p>'
)]),
])
self
.
_run_check
(
"<p tal:on-error='string:error' "
"tal:replace='notHere'>okay</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'onError'
,
[(
'insertText'
,
'$notHere$'
,
[(
'rawtext'
,
'<p tal:on-error="string:error" '
'tal:replace="notHere">okay</p>'
)])],
[(
'rawtext'
,
'<p tal:on-error="string:error" tal:replace="notHere">'
),
(
'insertText'
,
'$string:error$'
,
[]),
(
'rawtext'
,
'</p>'
)]),
])
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
HTMLTALParserTestCases
,
"check_"
))
suite
.
addTest
(
unittest
.
makeSuite
(
TALGeneratorTestCases
,
"check_"
))
return
suite
if
__name__
==
"__main__"
:
errs
=
utils
.
run_suite
(
test_suite
())
sys
.
exit
(
errs
and
1
or
0
)
lib/python/TAL/tests/test_htmltalparser.py
View file @
20c10a5c
...
...
@@ -11,12 +11,25 @@ from TAL import HTMLTALParser
from
TAL.TALDefs
import
TAL_VERSION
class
HTMLTALParserTestCases
(
unittest
.
TestCase
):
class
TestCaseBase
(
unittest
.
TestCase
):
prologue
=
""
epilogue
=
""
initial_program
=
[(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
)]
final_program
=
[]
def
_merge
(
self
,
p1
,
p2
):
if
p1
and
p2
and
p1
[
-
1
][
0
]
==
'rawtext'
and
p2
[
0
][
0
]
==
'rawtext'
:
return
p1
[:
-
1
]
+
[(
'rawtext'
,
p1
[
-
1
][
1
]
+
p2
[
0
][
1
])]
+
p2
[
1
:]
else
:
return
p1
+
p2
def
_run_check
(
self
,
source
,
program
,
macros
=
{}):
parser
=
HTMLTALParser
.
HTMLTALParser
()
parser
.
parseString
(
s
ourc
e
)
parser
.
parseString
(
s
elf
.
prologue
+
source
+
self
.
epilogu
e
)
got_program
,
got_macros
=
parser
.
getCode
()
program
=
self
.
_merge
(
self
.
initial_program
,
program
)
program
=
self
.
_merge
(
program
,
self
.
final_program
)
self
.
assert_
(
got_program
==
program
,
got_program
)
self
.
assert_
(
got_macros
==
macros
,
got_macros
)
...
...
@@ -27,23 +40,20 @@ class HTMLTALParserTestCases(unittest.TestCase):
pprint
.
pprint
(
got_program
)
pprint
.
pprint
(
got_macros
)
class
HTMLTALParserTestCases
(
TestCaseBase
):
def
check_code_simple_identity
(
self
):
self
.
_run_check
(
"""<html a='b' b="c" c=d><title>My Title</html>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<html a="b" b="c" c="d">'
'<title>My Title</title></html>'
),
])
def
check_code_implied_list_closings
(
self
):
self
.
_run_check
(
"""<ul><li><p><p><li></ul>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<ul><li><p></p><p></p></li><li></li></ul>'
),
])
self
.
_run_check
(
"""<dl><dt><dt><dd><dd><ol><li><li></ol></dl>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<dl><dt></dt><dt></dt><dd></dd>'
'<dd><ol><li></li><li></li></ol></dd></dl>'
),
])
...
...
@@ -51,16 +61,12 @@ class HTMLTALParserTestCases(unittest.TestCase):
def
check_code_implied_table_closings
(
self
):
self
.
_run_check
(
"""<p>text <table><tr><th>head
\
t
<tr><td>cell
\
t
"""
"""<table><tr><td>cell
\
n
\
t
\
n
<tr>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<p>text</p> <table><tr><th>head</th>'
'</tr>
\
t
<tr><td>cell
\
t
<table><tr><td>cell</td>'
'</tr>
\
n
\
t
\
n
<tr></tr></table></td></tr></table>'
),
])
self
.
_run_check
(
"""<table><tr><td>cell """
"""<table><tr><td>cell </table></table>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<table><tr><td>cell <table><tr><td>cell</td></tr>'
' </table></td></tr></table>'
),
])
...
...
@@ -72,8 +78,6 @@ class HTMLTALParserTestCases(unittest.TestCase):
def
check_code_attr_syntax
(
self
):
output
=
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="v" c="v" d="v" e></a>'
),
]
self
.
_run_check
(
"""<a b='v' c="v" d=v e>"""
,
output
)
...
...
@@ -84,68 +88,220 @@ class HTMLTALParserTestCases(unittest.TestCase):
def
check_code_attr_values
(
self
):
self
.
_run_check
(
"""<a b='xxx
\
n
\
t
xxx' c="yyy
\
t
\
n
yyy" d='
\
t
xyz
\
n
'>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="xxx
\
n
\
t
xxx" c="yyy
\
t
\
n
yyy" d="
\
t
xyz
\
n
"></a>'
)])
self
.
_run_check
(
"""<a b='' c="" d=>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="" c="" d=""></a>'
),
])
def
check_code_attr_entity_replacement
(
self
):
# we expect entities *not* to be replaced by HTLMParser!
self
.
_run_check
(
"""<a b='&><"''>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="&><"
\
'
"></a>'
),
])
self
.
_run_check
(
"""<a b='
\
"
'>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
"<a b='
\
"
'></a>"
),
])
self
.
_run_check
(
"""<a b='&'>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="&"></a>'
),
])
self
.
_run_check
(
"""<a b='<'>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a b="<"></a>'
),
])
def
check_code_attr_funky_names
(
self
):
self
.
_run_check
(
"""<a a.b='v' c:d=v e-f=v>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<a a.b="v" c:d="v" e-f="v"></a>'
),
])
def
check_code_pcdata_entityref
(
self
):
self
.
_run_check
(
""" """
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
' '
),
])
def
check_code_short_endtags
(
self
):
self
.
_run_check
(
"""<html><img/></html>"""
,
[
(
'version'
,
TAL_VERSION
),
(
'mode'
,
'html'
),
(
'rawtext'
,
'<html><img/></html>'
),
])
class
TALGeneratorTestCases
(
TestCaseBase
):
def
check_null
(
self
):
self
.
_run_check
(
""
,
[])
def
check_define
(
self
):
self
.
_run_check
(
"<p tal:define='xyzzy string:spam'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'xyzzy'
,
'$string:spam$'
),
(
'rawtext'
,
'<p tal:define="xyzzy string:spam"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='local xyzzy string:spam'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'xyzzy'
,
'$string:spam$'
),
(
'rawtext'
,
'<p tal:define="local xyzzy string:spam"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='global xyzzy string:spam'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setGlobal'
,
'xyzzy'
,
'$string:spam$'
),
(
'rawtext'
,
'<p tal:define="global xyzzy string:spam"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='x string:spam; y x'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'x'
,
'$string:spam$'
),
(
'setLocal'
,
'y'
,
'$x$'
),
(
'rawtext'
,
'<p tal:define="x string:spam; y x"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='x string:;;;;; y x'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'x'
,
'$string:;;$'
),
(
'setLocal'
,
'y'
,
'$x$'
),
(
'rawtext'
,
'<p tal:define="x string:;;;;; y x"></p>'
),
(
'endScope'
,),
])
self
.
_run_check
(
"<p tal:define='x string:spam; global y x; local z y'></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'setLocal'
,
'x'
,
'$string:spam$'
),
(
'setGlobal'
,
'y'
,
'$x$'
),
(
'setLocal'
,
'z'
,
'$y$'
),
(
'rawtext'
,
'<p tal:define="x string:spam; global y x; local z y"></p>'
),
(
'endScope'
,),
])
def
check_condition
(
self
):
self
.
_run_check
(
"<p><span tal:condition='python:1'><b>foo</b></span></p>"
,
[
(
'rawtext'
,
'<p>'
),
(
'setPosition'
,
(
1
,
3
)),
(
'condition'
,
'$python:1$'
,
[(
'rawtext'
,
'<span tal:condition="python:1"><b>foo</b></span>'
)]),
(
'rawtext'
,
'</p>'
),
])
def
check_content
(
self
):
self
.
_run_check
(
"<p tal:content='string:foo'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'rawtext'
,
'<p tal:content="string:foo">'
),
(
'insertText'
,
'$string:foo$'
,
[(
'rawtext'
,
'bar'
)]),
(
'rawtext'
,
'</p>'
),
])
self
.
_run_check
(
"<p tal:content='text string:foo'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'rawtext'
,
'<p tal:content="text string:foo">'
),
(
'insertText'
,
'$string:foo$'
,
[(
'rawtext'
,
'bar'
)]),
(
'rawtext'
,
'</p>'
),
])
self
.
_run_check
(
"<p tal:content='structure string:<br>'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'rawtext'
,
'<p tal:content="structure string:<br>">'
),
(
'insertStructure'
,
'$string:<br>$'
,
{},
[(
'rawtext'
,
'bar'
)]),
(
'rawtext'
,
'</p>'
),
])
def
check_replace
(
self
):
self
.
_run_check
(
"<p tal:replace='string:foo'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'insertText'
,
'$string:foo$'
,
[(
'rawtext'
,
'<p tal:replace="string:foo">bar</p>'
)]),
])
self
.
_run_check
(
"<p tal:replace='text string:foo'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'insertText'
,
'$string:foo$'
,
[(
'rawtext'
,
'<p tal:replace="text string:foo">bar</p>'
)]),
])
self
.
_run_check
(
"<p tal:replace='structure string:<br>'>bar</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'insertStructure'
,
'$string:<br>$'
,
{},
[(
'rawtext'
,
'<p tal:replace="structure string:<br>">bar</p>'
)]),
])
def
check_repeat
(
self
):
self
.
_run_check
(
"<p tal:repeat='x python:(1,2,3)'>"
"<span tal:replace='x'>dummy</span></p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'beginScope'
,),
(
'loop'
,
'x'
,
'$python:(1,2,3)$'
,
[(
'rawtext'
,
'<p tal:repeat="x python:(1,2,3)">'
),
(
'setPosition'
,
(
1
,
33
)),
(
'insertText'
,
'$x$'
,
[(
'rawtext'
,
'<span tal:replace="x">dummy</span>'
)]),
(
'rawtext'
,
'</p>'
)]),
(
'endScope'
,),
])
def
check_attributes
(
self
):
self
.
_run_check
(
"<a href='foo' name='bar' tal:attributes="
"'href string:http://www.zope.org; x string:y'>"
"link</a>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'startTag'
,
'a'
,
[(
'href'
,
'foo'
,
'replace'
,
'$string:http://www.zope.org$'
),
(
'name'
,
'bar'
),
(
'tal:attributes'
,
'href string:http://www.zope.org; x string:y'
),
(
'x'
,
''
,
'replace'
,
'$string:y$'
)]),
(
'rawtext'
,
'link</a>'
),
])
self
.
_run_check
(
"<p tal:replace='structure string:<img>' "
"tal:attributes='src string:foo.png'>duh</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'insertStructure'
,
'$string:<img>$'
,
{
'src'
:
'$string:foo.png$'
},
[(
'rawtext'
,
'<p tal:replace="structure string:<img>" '
'tal:attributes="src string:foo.png">duh</p>'
)]),
])
def
check_on_error
(
self
):
self
.
_run_check
(
"<p tal:on-error='string:error' "
"tal:content='notHere'>okay</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'onError'
,
[(
'rawtext'
,
'<p tal:on-error="string:error" tal:content="notHere">'
),
(
'insertText'
,
'$notHere$'
,
[(
'rawtext'
,
'okay'
)]),
(
'rawtext'
,
'</p>'
)],
[(
'rawtext'
,
'<p tal:on-error="string:error" tal:content="notHere">'
),
(
'insertText'
,
'$string:error$'
,
[]),
(
'rawtext'
,
'</p>'
)]),
])
self
.
_run_check
(
"<p tal:on-error='string:error' "
"tal:replace='notHere'>okay</p>"
,
[
(
'setPosition'
,
(
1
,
0
)),
(
'onError'
,
[(
'insertText'
,
'$notHere$'
,
[(
'rawtext'
,
'<p tal:on-error="string:error" '
'tal:replace="notHere">okay</p>'
)])],
[(
'rawtext'
,
'<p tal:on-error="string:error" tal:replace="notHere">'
),
(
'insertText'
,
'$string:error$'
,
[]),
(
'rawtext'
,
'</p>'
)]),
])
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
HTMLTALParserTestCases
,
"check_"
))
suite
.
addTest
(
unittest
.
makeSuite
(
TALGeneratorTestCases
,
"check_"
))
return
suite
if
__name__
==
"__main__"
:
errs
=
utils
.
run_suite
(
test_suite
())
sys
.
exit
(
errs
and
1
or
0
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment