Package translate :: Package filters :: Module test_decoration

[hide private]
[frames] | no frames]

# Source Code for Module translate.filters.test_decoration

     1  # -*- coding: utf-8 -*-
     2
     3  """tests decoration handling functions that are used by checks"""
     4
     5  from translate.filters import decoration
     6
     7 -def test_spacestart():
     8      """test operation of spacestart()"""
     9      assert decoration.spacestart("  Start") == "  "
    10      assert decoration.spacestart(u"\u0020\u00a0Start") == u"\u0020\u00a0"
    11      # non-breaking space
    12      assert decoration.spacestart(u"\u00a0\u202fStart") == u"\u00a0\u202f"
    13      # zero width space
    14      assert decoration.spacestart(u"\u200bStart") == u"\u200b"
    15      # Some exotic spaces
    16      assert decoration.spacestart(u"\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200aStart") == u"\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a"
    17
    18 -def test_isvalidaccelerator():
    19      """test the isvalidaccelerator() function"""
    20      # Mostly this tests the old code path where acceptlist is None
    21      assert decoration.isvalidaccelerator(u"") == False
    22      assert decoration.isvalidaccelerator(u"a") == True
    23      assert decoration.isvalidaccelerator(u"1") == True
    24      assert decoration.isvalidaccelerator(u"ḽ") == False
    25      # Test new code path where we actually have an acceptlist
    26      assert decoration.isvalidaccelerator(u"a", u"aeiou") == True
    27      assert decoration.isvalidaccelerator(u"ḽ", u"ḓṱḽṋṅ") == True
    28      assert decoration.isvalidaccelerator(u"a", u"ḓṱḽṋṅ") == False
    29
    30 -def test_find_marked_variables():
    31      """check that we cna identify variables correctly, first value is start location, i
    32      second is avtual variable sans decoations"""
    33      variables = decoration.findmarkedvariables("The <variable> string", "<", ">")
    34      assert variables == [(4, "variable")]
    35      variables = decoration.findmarkedvariables("The $variable string", "$", 1)
    36      assert variables == [(4, "v")]
    37      variables = decoration.findmarkedvariables("The $variable string", "$", None)
    38      assert variables == [(4, "variable")]
    39      variables = decoration.findmarkedvariables("The $variable string", "$", 0)
    40      assert variables == [(4, "")]
    41      variables = decoration.findmarkedvariables("The &variable; string", "&", ";")
    42      assert variables == [(4, "variable")]
    43      variables = decoration.findmarkedvariables("The &variable.variable; string", "&", ";")
    44      assert variables == [(4, "variable.variable")]
    45
    46 -def test_getnumbers():
    47      """test operation of getnumbers()"""
    48      assert decoration.getnumbers(u"") == []
    49      assert decoration.getnumbers(u"No numbers") == []
    50      assert decoration.getnumbers(u"Nine 9 nine") == ["9"]
    51      assert decoration.getnumbers(u"Two numbers: 2 and 3") == ["2", "3"]
    52      assert decoration.getnumbers(u"R5.99") == ["5.99"]
    53      # TODO fix these so that we are able to consider locale specific numbers
    54      #assert decoration.getnumbers(u"R5,99") == ["5.99"]
    55      #assert decoration.getnumbers(u"1\u00a0000,99") == ["1000.99"]
    56      assert decoration.getnumbers(u"36°") == [u"36°"]
    57
    58 -def test_getfunctions():
    59      """test operation of getfunctions()"""
    60      punctuation = "().?!"
    61      assert decoration.getfunctions(u"", punctuation) == []
    62      assert decoration.getfunctions(u"There is no function", punctuation) == []
    63      assert decoration.getfunctions(u"Use the getfunction() function.", punctuation) == ["getfunction()"]
    64      assert decoration.getfunctions(u"The module.getfunction() method", punctuation) == ["module.getfunction()"]
    65      assert decoration.getfunctions(u"The function().function() function", punctuation) == ["function().function()"]
    66      assert decoration.getfunctions(u"Deprecated, use function().", punctuation) == ["function()"]
    67      assert decoration.getfunctions(u"Deprecated, use function() or other().", punctuation) == ["function()", "other()"]
    68