[Zope-Checkins] CVS: Zope/lib/python/TAL/tests - test_htmltalparser.py:1.28.8.1

Barry Warsaw barry@wooz.org
Mon, 1 Jul 2002 18:46:04 -0400


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

Modified Files:
      Tag: zope2-tal-i18n-branch
	test_htmltalparser.py 
Log Message:
Internationalization TALS support ported from Zope3+Python2.2 to
Zope2+Python2.1.  This lives on a branch until the Zope 2.6 branch is
cut from the trunk.

Note that there's still one mysterious test failure in the METAL
input/output comparion files.


=== Zope/lib/python/TAL/tests/test_htmltalparser.py 1.28 => 1.28.8.1 === (595/695 lines abridged)
+#! /usr/bin/env python
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+# 
+##############################################################################
 """Tests for the HTMLTALParser code generator."""
 
 import pprint
 import sys
 
-from TAL.tests import utils
+from Zope.TAL.tests import utils
 import unittest
 
-from string import rfind
 
-from TAL import HTMLTALParser
-from TAL.TALDefs import TAL_VERSION, TALError, METALError
+from Zope.TAL import HTMLTALParser
+from Zope.TAL.TALDefs import TAL_VERSION, TALError, METALError
 
 
 class TestCaseBase(unittest.TestCase):
@@ -24,7 +36,7 @@
         if p1 and p2:
             op1, args1 = p1[-1]
             op2, args2 = p2[0]
-            if op1[:7] == 'rawtext' and op2[:7] == 'rawtext':
+            if op1.startswith('rawtext') and op2.startswith('rawtext'):
                 return (p1[:-1]
                         + [rawtext(args1[0] + args2[0])]
                         + p2[1:])
@@ -60,7 +72,7 @@
 def rawtext(s):
     """Compile raw text to the appropriate instruction."""
     if "\n" in s:
-        return ("rawtextColumn", (s, len(s) - (rfind(s, "\n") + 1)))
+        return ("rawtextColumn", (s, len(s) - (s.rfind("\n") + 1)))
     else:
         return ("rawtextOffset", (s, len(s)))
 

[-=- -=- -=- 595 lines omitted -=- -=- -=-]

+       None)),
+     ('endScope', ()),
+     ('rawtextColumn', ('\n', 0))])),
+  ('endScope', ()),
+  ('rawtextColumn', ('</p>\n', 0))
+  ])
+
+    def check_i18n_name_with_tal_content(self):
+        # input/test27.html
+        self._run_check('''\
+<p i18n:translate="verify">Your contact email address is recorded as
+    <a href="mailto:user@example.com"
+       tal:content="request/submitter"
+       i18n:name="email">user@host.com</a>
+</p>
+''', [
+  ('setPosition', (1, 0)),
+  ('beginScope', {'i18n:translate': 'verify'}),
+  ('startTag', ('p', [('i18n:translate', 'verify', 'i18n')])),
+  ('insertTranslation',
+   ('verify',
+    [('rawtextBeginScope',
+      ('Your contact email address is recorded as\n    ',
+       4,
+       (2, 4),
+       0,
+       {'href': 'mailto:user@example.com',
+        'i18n:name': 'email',
+        'tal:content': 'request/submitter'})),
+     ('i18nVariable',
+      ('email',
+       [('startTag',
+         ('a',
+          [('href', 'href="mailto:user@example.com"'),
+           ('tal:content', 'request/submitter', 'tal'),
+           ('i18n:name', 'email', 'i18n')])),
+        ('insertText',
+         ('$request/submitter$',
+          [('rawtextOffset', ('user@host.com', 13))])),
+        ('rawtextOffset', ('</a>', 4))],
+       None)),
+     ('endScope', ()),
+     ('rawtextColumn', ('\n', 0))])),
+  ('endScope', ()),
+  ('rawtextColumn', ('</p>\n', 0))
+  ])
+
 
 def test_suite():
     suite = unittest.TestSuite()