49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
##############################################################################
|
|
#
|
|
# OpenERP, Open Source Management Solution
|
|
# Copyright (C) 2010 OpenERP S.A. http://www.openerp.com
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
##############################################################################
|
|
|
|
import unittest
|
|
from tools.translate import quote, unquote
|
|
|
|
class TranslationToolsTestCase(unittest.TestCase):
|
|
|
|
def test_quote_unquote(self):
|
|
|
|
def test_string(str):
|
|
quoted = quote(str)
|
|
#print "\n1:", repr(str)
|
|
#print "2:", repr(quoted)
|
|
unquoted = unquote("".join(quoted.split('"\n"')))
|
|
#print "3:", repr(unquoted)
|
|
self.assertEquals(str, unquoted)
|
|
|
|
test_string("""test \nall kinds\n \n o\r
|
|
\\\\ nope\n\n"
|
|
""")
|
|
|
|
# The ones with 1+ backslashes directly followed by
|
|
# a newline or literal N can fail... we would need a
|
|
# state-machine parser to handle these, but this would
|
|
# be much slower so it's better to avoid them at the moment
|
|
self.assertRaises(AssertionError, quote, """test \nall kinds\n\no\r
|
|
\\\\nope\n\n"
|
|
""")
|
|
|