From: David F. <dav...@us...> - 2006-04-28 10:58:15
|
Update of /cvsroot/translate/src/translate/misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv459 Modified Files: test_quote.py quote.py Log Message: added tests for find_all and extract, so I can try speed them up further improved docstrings Index: test_quote.py =================================================================== RCS file: /cvsroot/translate/src/translate/misc/test_quote.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- test_quote.py 11 Apr 2006 09:23:51 -0000 1.2 +++ test_quote.py 28 Apr 2006 10:58:11 -0000 1.3 @@ -2,6 +2,25 @@ from translate.misc import quote +def test_find_all(): + """tests the find_all function""" + assert quote.find_all("", "a") == [] + assert quote.find_all("a", "b") == [] + assert quote.find_all("a", "a") == [0] + assert quote.find_all("aa", "a") == [0, 1] + assert quote.find_all("abba", "ba") == [2] + # check we skip the whole instance + assert quote.find_all("banana", "ana") == [1] + +def test_extract(): + """tests the extract function""" + assert quote.extract("the <quoted> part", "<", ">", "\\", 0) == ("<quoted>", False) + assert quote.extract("the 'quoted' part", "'", "'", "\\", 0) == ("'quoted'", False) + assert quote.extract("the 'isn\\'t escaping fun' part", "'", "'", "\\", 0) == ("'isn\\'t escaping fun'", False) + assert quote.extract("the 'isn\\'t something ", "'", "'", "\\", 0) == ("'isn\\'t something ", True) + assert quote.extract("<quoted>\\", "<", ">", "\\", 0) == ("<quoted>", False) + assert quote.extract("<quoted>\\\\<again>", "<", ">", "\\", 0) == ("<quoted><again>", False) + class TestQuote: def test_mozilla_control_escapes(self): Index: quote.py =================================================================== RCS file: /cvsroot/translate/src/translate/misc/quote.py,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- quote.py 28 Apr 2006 10:46:08 -0000 1.27 +++ quote.py 28 Apr 2006 10:58:11 -0000 1.28 @@ -22,7 +22,8 @@ """string processing utilities for extracting strings with various kinds of delimiters""" def find_all(searchin, substr): - """returns a list of locations where substr occurs in searchin""" + """returns a list of locations where substr occurs in searchin + locations are not allowed to overlap""" location = 0 locations = [] while location != -1: @@ -33,7 +34,8 @@ return locations def extract(source,startdelim,enddelim,escape,startinstring=0): - """Extracts a doublequote-delimited string from a string, allowing for backslash-escaping""" + """Extracts a doublequote-delimited string from a string, allowing for backslash-escaping + returns tuple of (quoted string with quotes, still in string at end)""" # note that this returns the quote characters as well... even internally instring = startinstring inescape = 0 |