From: <be...@us...> - 2006-10-20 09:53:45
|
Revision: 108 http://svn.sourceforge.net/pzfilereader/?rev=108&view=rev Author: benoitx Date: 2006-10-20 02:53:38 -0700 (Fri, 20 Oct 2006) Log Message: ----------- Took liberty to make the tests more explicit in order to detect any potential side effect, say the lTrim would correctly remove the leading space and leave the last one but mangle the text in between, the original tests would not have spotted that. I have also added a space in the middle of the word to detect more potential issues. Finally, I have added a method at the bottom and this has raised a question about the exacts spec... Paul, please have a look. i.e. lTrimWithKeepTabs, what if the string starts with a tab and then a space and then some text "\t blabla" what should the result be??? "\t blabla" (now) or "\tblabla" ??? Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/LTrimTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/LTrimTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/LTrimTest.java 2006-10-20 09:49:59 UTC (rev 107) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/LTrimTest.java 2006-10-20 09:53:38 UTC (rev 108) @@ -23,16 +23,13 @@ * @author paul zepernick */ public class LTrimTest extends TestCase{ - - - /** * Make sure all spaces are properly removed from the front of the String * */ public void testTrimLeadingSpaces(){ - final String testS = " RemoveAllSpacesFromMe"; - assertEquals(true , ParserUtils.lTrim(testS).indexOf(" ") == -1); + final String testS = " RemoveAll SpacesFromMe"; + assertEquals("RemoveAll SpacesFromMe" , ParserUtils.lTrim(testS)); } /** @@ -41,9 +38,9 @@ * */ public void testTrimLeadingSpacesWithTrailingSpaces(){ - final String testS = " RemoveAllSpacesFromMe "; + final String testS = " RemoveAll SpacesFromMe "; final String tResult = ParserUtils.lTrim(testS); - assertEquals(true , !tResult.startsWith(" ") && tResult.endsWith(" ")); + assertEquals("RemoveAll SpacesFromMe " , tResult); } @@ -53,9 +50,9 @@ * */ public void testTrimLeadingTabs(){ - final String testS = "\t\t\tRemoveAllSpacesFromMe "; + final String testS = "\t\t\tRemoveAll SpacesFromMe "; final String tResult = ParserUtils.lTrim(testS); - assertEquals(true , !tResult.startsWith("\t") && tResult.endsWith(" ")); + assertEquals("RemoveAll SpacesFromMe " , tResult); } @@ -65,11 +62,22 @@ * */ public void testKeepLeadingTabs(){ - final String testS = " \t\t\tRemoveAllSpacesFromMe "; + final String testS = " \t\t\tRemoveAll SpacesFromMe "; final String tResult = ParserUtils.lTrimKeepTabs(testS); - assertEquals(true , tResult.startsWith("\t") && tResult.endsWith(" ")); + assertEquals("\t\t\tRemoveAll SpacesFromMe " , tResult); } + /** + * Ensure that spaces and tabs in the middle of the string will + * not be removed. + */ + public void testWithTabsInMiddleAndEnd() { + assertEquals("RemoveAll \tSpaces \t\t",ParserUtils.lTrim("\t \t RemoveAll \tSpaces \t\t")); + + // Paul what should happen for the following tests, should they skip the tab and get rid of the spaces or stop at the first tab?? + assertEquals("\t \t RemoveAll \tSpaces \t\t ",ParserUtils.lTrimKeepTabs(" \t \t RemoveAll \tSpaces \t\t ")); + assertEquals("\t\tRemoveAll \tSpaces \t\t",ParserUtils.lTrimKeepTabs("\t \t RemoveAll \tSpaces \t\t")); + } public static void main(final String[] args) { junit.textui.TestRunner.run(LTrimTest.class); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |