|
From: Andre R. <and...@us...> - 2006-02-18 20:13:57
|
Update of /cvsroot/frontierkernel/odbs/frontierRoot/suites/fUnit/testSuperStress In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25310/testSuperStress Modified Files: Tag: fUnit_Suite-branch testRegularExpressions Log Message: Check named group patterns more thoroughly, managed to locate a bug in the re.replace kernel verb. Index: testRegularExpressions =================================================================== RCS file: /cvsroot/frontierkernel/odbs/frontierRoot/suites/fUnit/testSuperStress/Attic/testRegularExpressions,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** testRegularExpressions 18 Feb 2006 13:13:41 -0000 1.1.2.1 --- testRegularExpressions 18 Feb 2006 20:13:49 -0000 1.1.2.2 *************** *** 1,3 **** FrontierVcsFile:1:scpt:suites.fUnit.testSuperStress.testRegularExpressions ! on testRegularExpressions () { assert (defined (system.compiler.["kernel"].re), "The regular expressions verbs are not implemented in this application."); bundle { //re.match local (cp, matchInfo, s1 = "a123four", s2 = "bop bebe bop"); cp = re.compile ("[a-zA-Z]+[0-9]+"); assert (re.match (cp, s1, adrMatchInfoTable:@matchInfo), "re.match is broken."); assertEqual (matchInfo.matchString, "a123", "re.match is broken."); cp = re.compile ("(be){1,2}"); assert (re.match (cp, s2, adrMatchInfoTable:@matchInfo), "re.search is broken."); assertEqual (matchInfo.matchString, "bebe", "re.search is broken.")}; bundle { //re.extract local { cp; complexLinkPat = "<a[ \t\r\n]*[^>]*href[ \t\r\n]*=[ \t\r\n]*\"?([-_~%@:/\\.A-Za-z0-9]+)\"?[^>]*>([^<]*)"; simpleLinkPat = "<a[ \t\r\n]+[^>]*href[ \t\r\n]*=[ \t\r\n]*\"([^\"]*)\"[^>]*>([^<]*)"; s = string (re.testing.data.html); theList}; cp = re.compile (simpleLinkPat); theList = re.extract (cp, s, {2,1}); assertEqual (sizeOf (theList), 59, "re.extract is broken."); assertEqual (theList[57][1] , "Roget's Thesaurus:", "re.extract is broken."); assertEqual (theList[57][2] , "http://www2.thesaurus.com/thesaurus/", "re.extract is broken."); cp = re.compile (complexLinkPat); theList = re.extract (cp, s, {2,1}); assertEqual (sizeOf (theList), 59, "re.extract is broken."); assertEqual (theList[25][1] , "FileMaker", "re.extract is broken."); assertEqual (theList[25][2] , "http://www.scripting.com/apps/filemaker.html", "re.extract is broken.")}; bundle { //re.grep local (cp); local (theList = {"aa", "aab", "a", "ab", ""}); local (s = "aa\raab\ra\rab\r\r"); cp = re.compile ("^aa"); assertEqual (re.grep (cp, theList), {"aa", "aab"}, "re.grep is broken."); assertEqual (re.grep (cp, s), {"aa", "aab"}, "re.grep is broken."); assertEqual (re.grep (cp, theList, flIncludeMatches:false), {"a", "ab", ""}, "re.grep is broken."); assertEqual (re.grep (cp, theList, flIncludeMatches:false), {"a", "ab", ""}, "re.grep is broken.")}; bundle { //re.join local (listA = {"a", "b", "c"}, listB = {"abcd", "", "efgh", ""}); assertEqual (re.join ("|", listA), "a|b|c", "re.join is broken."); assertEqual (re.join ("", listA), "abc", "re.join is broken."); assertEqual (re.join ("+/+", listB), "abcd+/++/+efgh+/+", "re.join is broken.")}; bundle { //re.split local (cp); local (s = "<title>test</title>\r<body>\rtest body\r</body>"); cp = re.compile ("<[^>]*>"); assertEqual (re.split (cp, s), {"", "test", "\r", "\rtest body\r", ""}, "re.split is broken."); assertEqual (re.split (cp, s, maxSplits:4), {"", "test", "\r", "\rtest body\r</body>"}, "re.split is broken."); cp = re.compile ("(<[^>]*>)"); assertEqual (re.split (cp, s), {"", "<title>", "test", "</title>", "\r", "<body>", "\rtest body\r", "</body>", ""}, "re.split is broken."); assertEqual (re.split (cp, s, maxSplits:3), {"", "<title>", "test", "</title>", "\r<body>\rtest body\r</body>"}, "re.split is broken."); local (s2 = "aBcDeFg"); cp = re.compile ("[a-z]+", flCaseSensitive:true); assertEqual (re.split (cp, s2), {"", "B", "D", "F", ""}, "re.split is broken."); cp = re.compile ("[^a-z]+", flCaseSensitive:true); assertEqual (re.split (cp, s2), {"a", "c", "e", "g"}, "re.split is broken."); cp = re.compile ("[A-Z]+", flCaseSensitive:true); assertEqual (re.split (cp, s2), {"a", "c", "e", "g"}, "re.split is broken."); cp = re.compile ("[^A-Z]+", flCaseSensitive:true); assertEqual (re.split (cp, s2), {"", "B", "D", "F", ""}, "re.split is broken.")}; bundle { //re.replace local (cp, ct); local (s = "To be or not to be", s2); cp = re.compile ("(be)"); s = re.replace (cp, "\\1BOP", s); assertEqual (s, "To beBOP or not to beBOP", "re.replace is broken."); cp = re.compile ("(be)(bop)", flCaseSensitive:false); s = re.replace (cp, "\\2\\1", s); assertEqual (s, "To BOPbe or not to BOPbe", "re.replace is broken."); cp = re.compile ("(BOP)(be)"); s = re.replace (cp, "\\2\\1", s, maxReplacements:1); assertEqual (s, "To beBOP or not to BOPbe", "re.replace is broken."); cp = re.compile ("(BOP)(be)"); s = re.replace (cp, "\\2\\1", s, adrReplacementCount:@ct); assertEqual (s, "To beBOP or not to beBOP", "re.replace is broken."); assertEqual (ct, 1, "re.replace is broken."); local (test = "Check http://www.muppets.com/~gonzo/ for more info, send your q's to mailto:go...@mu...."); local (result = "Check <A HREF=\"http://www.muppets.com/~gonzo/\">http://www.muppets.com/~gonzo/</A> for more info, send your q's to <A HREF=\"mailto:go...@mu...\">mailto:go...@mu...</A>."); cp = re.compile ("(http|mailto)(:[/]*[A-Za-z0-9]+[-_~%@:/\\.A-Za-z0-9]+[A-Za-z/0-9])"); test = re.replace (cp, "<A HREF=\"\\1\\2\">\\0</A>", test); assertEqual (test, result, "re.replace is broken.")}; bundle { //re.visit local (hits = 0); local (test = " <A href ='index.html' > <A href= 'index2.html' > "); on testCallback (adrTable) { case ++hits { 1 { assertEqual (adrTable^.matchOffset, 2, "re.visit is broken."); assertEqual (adrTable^.matchLength, 25, "re.visit is broken."); assertEqual (adrTable^.matchString, "<A href ='index.html' >", "re.visit is broken.")}; 2 { assertEqual (adrTable^.matchOffset, 28, "re.visit is broken."); assertEqual (adrTable^.matchLength, 33, "re.visit is broken."); assertEqual (adrTable^.matchString, "<A href= 'index2.html' >", "re.visit is broken.")}} else { abort ("re.visit is broken.")}; return (true)}; local (cp = re.compile ("<([^>]+)>")); re.visit (cp, test, @testCallback); assertEqual (hits, 2, "re.visit is broken.")}; bundle { //re.expand local (pat, mi); pat = re.compile ("(?P<date>(?P<year>(\\d\\d)?\\d\\d)-(?P<month>\\d\\d)-(?P<day>\\d\\d))", flAutoCapture:false); assert (re.match (pat, "2003-05-30", adrMatchInfoTable:@mi, flMakeGroups:true, flMakeNamedGroups:true), "re.match is broken"); assertEqual (re.expand ("\\g<date>", @mi), "2003-05-30", "re.expand is broken."); assertEqual (re.expand ("\\g<day>.\\g<month>.\\g<year>", @mi), "30.05.2003", "re.expand is broken."); assertEqual (re.expand ("\\g<4>.\\g<3>.\\g<2>", @mi), "30.05.2003", "re.expand is broken."); assertEqual (re.expand ("\\4.\\3.\\2", @mi), "30.05.2003", "re.expand is broken."); temp.mi = mi}}; Çbundle //group references Çlocal (cp, s = "To beBOP or not to beBOP") Çcp = re.compile ("(?P<x>be)(?P<x2>bop)", flCaseSensitive:false) ÇassertEqual (re.replace (cp, "\\g<2>\\g<1>", s), "To BOPbe or not to BOPbe", "numbered groups are broken.") ÇassertEqual (re.replace (cp, "\\g<x2>\\g<x>", s), "To BOPbe or not to BOPbe", "named groups are broken.") bundle { //debug code fUnit.runners.run (parentOf(this^), testCaseToRun: this)} \ No newline at end of file --- 1,3 ---- FrontierVcsFile:1:scpt:suites.fUnit.testSuperStress.testRegularExpressions ! on testRegularExpressions () { assert (defined (system.compiler.["kernel"].re), "The regular expressions verbs are not implemented in this application."); bundle { //re.match local (cp, matchInfo, s1 = "a123four", s2 = "bop bebe bop"); cp = re.compile ("[a-zA-Z]+[0-9]+"); assert (re.match (cp, s1, adrMatchInfoTable:@matchInfo), "re.match is broken."); assertEqual (matchInfo.matchString, "a123", "re.match is broken."); cp = re.compile ("(be){1,2}"); assert (re.match (cp, s2, adrMatchInfoTable:@matchInfo), "re.search is broken."); assertEqual (matchInfo.matchString, "bebe", "re.search is broken.")}; bundle { //re.extract local { cp; complexLinkPat = "<a[ \t\r\n]*[^>]*href[ \t\r\n]*=[ \t\r\n]*\"?([-_~%@:/\\.A-Za-z0-9]+)\"?[^>]*>([^<]*)"; simpleLinkPat = "<a[ \t\r\n]+[^>]*href[ \t\r\n]*=[ \t\r\n]*\"([^\"]*)\"[^>]*>([^<]*)"; s = string (re.testing.data.html); theList}; cp = re.compile (simpleLinkPat); theList = re.extract (cp, s, {2,1}); assertEqual (sizeOf (theList), 59, "re.extract is broken."); assertEqual (theList[57][1] , "Roget's Thesaurus:", "re.extract is broken."); assertEqual (theList[57][2] , "http://www2.thesaurus.com/thesaurus/", "re.extract is broken."); cp = re.compile (complexLinkPat); theList = re.extract (cp, s, {2,1}); assertEqual (sizeOf (theList), 59, "re.extract is broken."); assertEqual (theList[25][1] , "FileMaker", "re.extract is broken."); assertEqual (theList[25][2] , "http://www.scripting.com/apps/filemaker.html", "re.extract is broken.")}; bundle { //re.grep local (cp); local (theList = {"aa", "aab", "a", "ab", ""}); local (s = "aa\raab\ra\rab\r\r"); cp = re.compile ("^aa"); assertEqual (re.grep (cp, theList), {"aa", "aab"}, "re.grep is broken."); assertEqual (re.grep (cp, s), {"aa", "aab"}, "re.grep is broken."); assertEqual (re.grep (cp, theList, flIncludeMatches:false), {"a", "ab", ""}, "re.grep is broken."); assertEqual (re.grep (cp, theList, flIncludeMatches:false), {"a", "ab", ""}, "re.grep is broken.")}; bundle { //re.join local (listA = {"a", "b", "c"}, listB = {"abcd", "", "efgh", ""}); assertEqual (re.join ("|", listA), "a|b|c", "re.join is broken."); assertEqual (re.join ("", listA), "abc", "re.join is broken."); assertEqual (re.join ("+/+", listB), "abcd+/++/+efgh+/+", "re.join is broken.")}; bundle { //re.split local (cp); local (s = "<title>test</title>\r<body>\rtest body\r</body>"); cp = re.compile ("<[^>]*>"); assertEqual (re.split (cp, s), {"", "test", "\r", "\rtest body\r", ""}, "re.split is broken."); assertEqual (re.split (cp, s, maxSplits:4), {"", "test", "\r", "\rtest body\r</body>"}, "re.split is broken."); cp = re.compile ("(<[^>]*>)"); assertEqual (re.split (cp, s), {"", "<title>", "test", "</title>", "\r", "<body>", "\rtest body\r", "</body>", ""}, "re.split is broken."); assertEqual (re.split (cp, s, maxSplits:3), {"", "<title>", "test", "</title>", "\r<body>\rtest body\r</body>"}, "re.split is broken."); local (s2 = "aBcDeFg"); cp = re.compile ("[a-z]+", flCaseSensitive:true); assertEqual (re.split (cp, s2), {"", "B", "D", "F", ""}, "re.split is broken."); cp = re.compile ("[^a-z]+", flCaseSensitive:true); assertEqual (re.split (cp, s2), {"a", "c", "e", "g"}, "re.split is broken."); cp = re.compile ("[A-Z]+", flCaseSensitive:true); assertEqual (re.split (cp, s2), {"a", "c", "e", "g"}, "re.split is broken."); cp = re.compile ("[^A-Z]+", flCaseSensitive:true); assertEqual (re.split (cp, s2), {"", "B", "D", "F", ""}, "re.split is broken.")}; bundle { //re.replace local (cp, ct); local (s = "To be or not to be", s2); cp = re.compile ("(be)"); s = re.replace (cp, "\\1BOP", s); assertEqual (s, "To beBOP or not to beBOP", "re.replace is broken."); cp = re.compile ("(be)(bop)", flCaseSensitive:false); s = re.replace (cp, "\\2\\1", s); assertEqual (s, "To BOPbe or not to BOPbe", "re.replace is broken."); cp = re.compile ("(BOP)(be)"); s = re.replace (cp, "\\2\\1", s, maxReplacements:1); assertEqual (s, "To beBOP or not to BOPbe", "re.replace is broken."); cp = re.compile ("(BOP)(be)"); s = re.replace (cp, "\\2\\1", s, adrReplacementCount:@ct); assertEqual (s, "To beBOP or not to beBOP", "re.replace is broken."); assertEqual (ct, 1, "re.replace is broken."); local (test = "Check http://www.muppets.com/~gonzo/ for more info, send your q's to mailto:go...@mu...."); local (result = "Check <A HREF=\"http://www.muppets.com/~gonzo/\">http://www.muppets.com/~gonzo/</A> for more info, send your q's to <A HREF=\"mailto:go...@mu...\">mailto:go...@mu...</A>."); cp = re.compile ("(http|mailto)(:[/]*[A-Za-z0-9]+[-_~%@:/\\.A-Za-z0-9]+[A-Za-z/0-9])"); test = re.replace (cp, "<A HREF=\"\\1\\2\">\\0</A>", test); assertEqual (test, result, "re.replace is broken.")}; bundle { //re.visit local (hits = 0); local (test = " <A href ='index.html' > <A href= 'index2.html' > "); on testCallback (adrTable) { case ++hits { 1 { assertEqual (adrTable^.matchOffset, 2, "re.visit is broken."); assertEqual (adrTable^.matchLength, 25, "re.visit is broken."); assertEqual (adrTable^.matchString, "<A href ='index.html' >", "re.visit is broken.")}; 2 { assertEqual (adrTable^.matchOffset, 28, "re.visit is broken."); assertEqual (adrTable^.matchLength, 33, "re.visit is broken."); assertEqual (adrTable^.matchString, "<A href= 'index2.html' >", "re.visit is broken.")}} else { abort ("re.visit is broken.")}; return (true)}; local (cp = re.compile ("<([^>]+)>")); re.visit (cp, test, @testCallback); assertEqual (hits, 2, "re.visit is broken.")}; bundle { //re.expand local (pat, mi); pat = re.compile ("(?P<date>(?P<year>(\\d\\d)?\\d\\d)-(?P<month>\\d\\d)-(?P<day>\\d\\d))", flAutoCapture:false); assert (re.match (pat, "2003-05-30", adrMatchInfoTable:@mi, flMakeGroups:true, flMakeNamedGroups:true), "re.match is broken"); assertEqual (re.expand ("\\g<date>", @mi), "2003-05-30", "re.expand is broken."); assertEqual (re.expand ("\\g<day>.\\g<month>.\\g<year>", @mi), "30.05.2003", "re.expand is broken."); assertEqual (re.expand ("\\g<4>.\\g<3>.\\g<2>", @mi), "30.05.2003", "re.expand is broken."); assertEqual (re.expand ("\\4.\\3.\\2", @mi), "30.05.2003", "re.expand is broken."); temp.mi = mi}; bundle { //group references local (cp, s = "To beBOP or not to beBOP", mi); cp = re.compile ("(?P<a>be)(?P<b>bop)", flCaseSensitive:false); assert (re.match (cp, s, adrMatchInfoTable:@mi, flMakeGroups:true, flMakeNamedGroups:true), "named groups are broken in re.match"); assertEqual (mi.namedGroups.a.groupNumber, 1, "named groups are broken in re.match"); assertEqual (mi.namedGroups.a.matchString, "be", "named groups are broken in re.match"); assertEqual (mi.namedGroups.a.matchOffset, 4, "named groups are broken in re.match"); assertEqual (mi.namedGroups.a.matchLength, 2, "named groups are broken in re.match"); assertEqual (mi.namedGroups.b.groupNumber, 2, "named groups are broken in re.match"); assertEqual (mi.namedGroups.b.matchString, "BOP", "named groups are broken in re.match"); assertEqual (mi.namedGroups.b.matchOffset, 6, "named groups are broken in re.match"); assertEqual (mi.namedGroups.b.matchLength, 3, "named groups are broken in re.match"); assertEqual (re.replace (cp, "\\g<b>\\g<a>", s), "To BOPbe or not to BOPbe", "named groups are broken in re.replace"); cp = re.compile ("(?P<x>be)(?P<xy>bop)", flCaseSensitive:false); assertEqual (re.replace (cp, "\\g<xy>\\g<x>", s), "To BOPbe or not to BOPbe", "named groups are broken in re.replace"); cp = re.compile ("(?P<x>be)(?P<xx>bop)", flCaseSensitive:false); assertEqual (re.replace (cp, "\\g<xx>\\g<x>", s), "To BOPbe or not to BOPbe", "named groups are broken in re.replace"); cp = re.compile ("(?P<x>be)(?P<xz>bop)", flCaseSensitive:false); assertEqual (re.replace (cp, "\\g<xz>\\g<x>", s), "To BOPbe or not to BOPbe", "named groups are broken in re.replace")}}; bundle { //debug code fUnit.runners.run (parentOf(this^), testCaseToRun: this)} \ No newline at end of file |