[ZPT] CVS: Zope3/lib/python/Zope/TAL/tests - test_htmltalparser.py:1.25.14.2.6.1 test_talinterpreter.py:1.3.14.1.8.1

Fred L. Drake, Jr. fdrake@acm.org
Wed, 20 Mar 2002 18:36:31 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/TAL/tests
In directory cvs.zope.org:/tmp/cvs-serv20026/tests

Modified Files:
      Tag: fdrake-tal-i18n-branch
	test_htmltalparser.py test_talinterpreter.py 
Log Message:
Preliminary attempts to start the I18N support for TAL.
This initial checkin is not quite working yet, but we have come a long way.
(we = Fred & Stephen Richter)


=== Zope3/lib/python/Zope/TAL/tests/test_htmltalparser.py 1.25.14.2 => 1.25.14.2.6.1 ===
               'name': 'bar', 'href': 'foo'}),
             ('startTag', ('a',
-             [('href', 'foo', 0, '$string:http://www.zope.org$'),
+             [('href', 'foo', 0, '$string:http://www.zope.org$', 0),
               ('name', 'name="bar"'),
               ('tal:attributes',
                'href string:http://www.zope.org; x string:y', 3),
-              ('x', None, 1, '$string:y$')])),
+              ('x', None, 1, '$string:y$', 0)])),
             ('endScope', ()),
             rawtext('link</a>'),
             ])
@@ -403,12 +403,13 @@
             ('beginScope',
              {'tal:attributes': 'src string:foo.png',
               'tal:replace': 'structure string:<img>'}),
-            ('insertStructure', ('$string:<img>$',
-             {'src': '$string:foo.png$'},
-             [('startTag', ('p',
-               [('tal:replace', 'structure string:<img>', 3),
-                ('tal:attributes', 'src string:foo.png', 3)])),
-              rawtext('duh</p>')])),
+            ('insertStructure',
+             ('$string:<img>$',
+              {'src': ('$string:foo.png$', 0)},
+              [('startTag', ('p',
+                             [('tal:replace', 'structure string:<img>', 3),
+                              ('tal:attributes', 'src string:foo.png', 3)])),
+               rawtext('duh</p>')])),
             ('endScope', ()),
             ])
 
@@ -471,6 +472,18 @@
                            2*"<p metal:fill-slot='y' />" + "</html>", exc)
         self._should_error("<p metal:foobar='x' />", exc)
         self._should_error("<p metal:define-macro='x'>", exc)
+
+    #
+    #  I18N test cases
+    #
+
+    def check_i18n_attributes(self):
+        self._run_check("<img alt='foo' i18n:attributes='alt'>", [
+            ('setPosition', (1, 0)),
+            ('startTag', ('img',
+             [('alt', 'foo', 0, None, 1),
+              ('i18n:attributes', 'alt', 3)])),
+            ])
         
 
 def test_suite():


=== Zope3/lib/python/Zope/TAL/tests/test_talinterpreter.py 1.3.14.1 => 1.3.14.1.8.1 ===
 from StringIO import StringIO
 
-from Zope.TAL.TALDefs import METALError
+from Zope.TAL.TALDefs import METALError, I18NError
 from Zope.TAL.HTMLTALParser import HTMLTALParser
 from Zope.TAL.TALInterpreter import TALInterpreter
 from Zope.TAL.DummyEngine import DummyEngine
@@ -47,6 +47,29 @@
         self.macro[0] = ("version", "duh")
 
 
+class I18NErrorsTestCase(TestCaseBase):
+
+    def _check(self, src, msg):
+        try:
+            self._compile(src)
+        except I18NError:
+            pass
+        else:
+            self.fail(msg)
+
+    def check_id_with_replace(self):
+        self._check('<p i18n:id="foo" tal:replace="string:splat"></p>',
+                    "expected i18n:id with tal:replace to be denied")
+
+    def check_missing_values(self):
+        self._check('<p i18n:attributes=""></p>',
+                    "missing i18n:attributes value not caught")
+        self._check('<p i18n:data=""></p>',
+                    "missing i18n:data value not caught")
+        self._check('<p i18n:id=""></p>',
+                    "missing i18n:id value not caught")
+
+
 class OutputPresentationTestCase(TestCaseBase):
 
     def check_attribute_wrapping(self):
@@ -71,6 +94,7 @@
 
 def test_suite():
     suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(I18NErrorsTestCase, "check_"))
     suite.addTest(unittest.makeSuite(MacroErrorsTestCase, "check_"))
     suite.addTest(unittest.makeSuite(OutputPresentationTestCase, "check_"))
     return suite