Package cssutils :: Package tests :: Module test_util |
[hide private]
[frames] | no frames]

# Source Code for Module cssutils.tests.test_util

     1  # -*- coding: iso-8859-1 -*-
     2  """
     3  testcases for cssutils.util
     4  """
     5  __author__ = '$LastChangedBy: cthedot $'
     6  __date__ = '$LastChangedDate: 2007-06-13 20:38:01 +0200 (Mi, 13 Jun 2007) $'
     7  __version__ = '0.9.2a2, $LastChangedRevision: 56 $'
     8
     9  import sys
    10  import xml.dom
    11
    12  import basetest
    13
    14  from cssutils.token import Token
    15  from cssutils.util import Base
    16
    17
    18 -class UtilTestCase(basetest.BaseTestCase):
    19
    20 -    def test_tokenupto(self):
    21          "util.Base._tokensupto()"
    22
    23          # tests nested blocks of {} [] or ()
    24          b = Base()
    25
    26          # tokenstring, callid, exp
    27          tests = [
    28              (1, u'a[{1}]({2}) { } NOT', u'a[{1}]({2}) { }', False),
    29              (1, u'a[{1}]({2}) { } NOT', u'a[{1}]func({2}) { }', True),
    30              (2, u'a[{1}]({2}) { NOT', u'a[{1}]({2}) {', False),
    31              (2, u'a[{1}]({2}) { NOT', u'a[{1}]func({2}) {', True),
    32              (4, u'a[(2)1] { }2 : a;', u'a[(2)1] { }2 :', False),
    33              (4, u'a[(2)1] { }2 : a;', u'a[func(2)1] { }2 :', True),
    34              (5, u'a{;{;}[;](;)}[;{;}[;](;)](;{;}[;](;)) 1; NOT',
    35                  u'a{;{;}[;](;)}[;{;}[;](;)](;{;}[;](;)) 1;', False),
    36              (5, u'a{;{;}[;](;)}[;{;}[;](;)](;{;}[;](;)) 1; NOT',
    37                  u'a{;{;}[;]func(;)}[;{;}[;]func(;)]func(;{;}[;]func(;)) 1;', True),
    38              (7, u'a{[1]}([3])[{[1]}[2]([3])] NOT',
    39                  u'a{[1]}([3])[{[1]}[2]([3])]', False),
    40              (7, u'a{[1]}([3])[{[1]}[2]([3])] NOT',
    41                  u'a{[1]}func([3])[{[1]}[2]func([3])]', True),
    42              (8, u'a[()]{()}([()]{()}()) NOT',
    43                  u'a[()]{()}([()]{()}())', False),
    44              (8, u'a[()]{()}([()]{()}()) NOT',
    45                  u'a[func()]{func()}func([func()]{func()}func())', True)
    46              ]
    47
    48          for callid, values, exp, paransasfunc in tests:
    49
    50              def maketokens(valuelist):
    51                  # returns list of Token objects
    52                  return [Token(value=v) for v in valuelist]
    53
    54              tokens = maketokens(list(values))
    55              if paransasfunc:
    56                  for i, t in enumerate(tokens):
    57                      if u'(' == t.value:
    58                          tokens[i].value = u'func('
    59                          tokens[i].type = Token.FUNCTION
    60
    61              if 1 == callid:
    62                  restokens, i = b._tokensupto(tokens)
    63              elif 2 == callid:
    64                  restokens, i = b._tokensupto(
    65                      tokens, blockstartonly=True)
    66              elif 4 == callid:
    67                  restokens, i = b._tokensupto(
    68                      tokens, propertynameendonly=True)
    69              elif 5 == callid:
    70                  restokens, i = b._tokensupto(
    71                      tokens, propertyvalueendonly=True)
    72              elif 8 == callid:
    73                  restokens, i = b._tokensupto(
    74                      tokens, funcendonly=True)
    75              elif 7 == callid:
    76                  restokens, i = b._tokensupto(
    77                      tokens, selectorattendonly=True)
    78
    79
    80              res = u''.join([t.value for t in restokens])
    81
    82              self.assertEqual(True, (lambda x: i > 1)(i))
    83              self.assertEqual(exp, res)
    84
    85
    86
    87  if __name__ == '__main__':
    88      import unittest
    89      unittest.main()
    90