HEX
Server: Apache/2.4.18 (Ubuntu)
System: Linux ubuntu 7.0.5-x86_64-linode173 #1 SMP PREEMPT_DYNAMIC Fri May 8 10:12:05 EDT 2026 x86_64
User: root (0)
PHP: 7.2.28-1+ubuntu16.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //usr/local/bin/python37_/lib/python3.7/site-packages/cssutils/tests/test_helper.py
"""Testcases for cssutils.helper"""

from cssutils.helper import normalize, string, stringvalue, uri, urivalue


class TestHelper:
    def test_normalize(self):
        "helper._normalize()"
        tests = {
            'abcdefg ABCDEFG äöü߀ AÖÜ': r'abcdefg abcdefg äöü߀ aöü',
            r'\ga\Ga\\\ ': r'gaga\ ',
            r'0123456789': r'0123456789',
            r'"\x"': r'"x"',
            # unicode escape seqs should have been done by
            # the tokenizer...
        }
        for test, exp in list(tests.items()):
            assert normalize(test) == exp
            # static too
            assert normalize(test) == exp

    #    def test_normalnumber(self):
    #        "helper.normalnumber()"
    #        tests = {
    #                 '0': '0',
    #                 '00': '0',
    #                 '0.0': '0',
    #                 '00.0': '0',
    #                 '1': '1',
    #                 '01': '1',
    #                 '00.1': '0.1',
    #                 '0.00001': '0.00001',
    #                 '-0': '0',
    #                 '-00': '0',
    #                 '-0.0': '0',
    #                 '-00.0': '0',
    #                 '-1': '-1',
    #                 '-01': '-1',
    #                 '-00.1': '-0.1',
    #                 '-0.00001': '-0.00001',
    #                 }
    #        for test, exp in tests.items():
    #            self.assertEqual(exp, normalnumber(test))

    def test_string(self):
        "helper.string()"
        assert '"x"' == string('x')
        assert '"1 2ä€"' == string('1 2ä€')
        assert r'''"'"''' == string("'")
        assert r'"\""' == string('"')
        # \n = 0xa, \r = 0xd, \f = 0xc
        assert r'"\a "' == string(
            '''
'''
        )
        assert r'"\c "' == string('\f')
        assert r'"\d "' == string('\r')
        assert r'"\d \a "' == string('\r\n')

    def test_stringvalue(self):
        "helper.stringvalue()"
        assert 'x' == stringvalue('"x"')
        assert '"' == stringvalue('"\\""')
        assert r'x' == stringvalue(r"\x ")

        # escapes should have been done by tokenizer
        # so this shoule not happen at all:
        assert r'a' == stringvalue(r"\a ")

    def test_uri(self):
        "helper.uri()"
        assert 'url(x)' == uri('x')
        assert 'url("(")' == uri('(')
        assert 'url(")")' == uri(')')
        assert 'url(" ")' == uri(' ')
        assert 'url(";")' == uri(';')
        assert 'url(",")' == uri(',')
        assert 'url("x)x")' == uri('x)x')

    def test_urivalue(self):
        "helper.urivalue()"
        assert 'x' == urivalue('url(x)')
        assert 'x' == urivalue('url("x")')
        assert ')' == urivalue('url(")")')