commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mart...@apache.org
Subject cvs commit: jakarta-commons/io/src/test/org/apache/commons/io/find FileFinderTest.java
Date Sun, 24 Oct 2004 00:10:05 GMT
martinc     2004/10/23 17:10:05

  Modified:    io/src/test/org/apache/commons/io FilenameUtilsTestCase.java
               io/src/test/org/apache/commons/io/find FileFinderTest.java
  Log:
  The tests were using explicit Unix-style path separators, whereas the utils
  themselves were using File.separator, so the tests failed on Windows. Now
  the tests also use File.separator, and work on Windows. The one tricky part
  is that paths for regex searches need to be escaped if the separator is a
  backslash.
  
  Revision  Changes    Path
  1.9       +7 -7      jakarta-commons/io/src/test/org/apache/commons/io/FilenameUtilsTestCase.java
  
  Index: FilenameUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/FilenameUtilsTestCase.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FilenameUtilsTestCase.java	13 Jun 2004 05:13:57 -0000	1.8
  +++ FilenameUtilsTestCase.java	24 Oct 2004 00:10:05 -0000	1.9
  @@ -208,9 +208,9 @@
                   { "README", "" }, 
                   { "domain.dot.com", "com" }, 
                   { "image.jpeg", "jpeg" },
  -                { "a.b/c", "" },
  -                { "a.b/c.txt", "txt" },
  -                { "a/b/c", "" },
  +                { "a.b" + File.separator + "c", "" },
  +                { "a.b" + File.separator + "c.txt", "txt" },
  +                { "a" + File.separator + "b" + File.separator + "c", "" },
           };
           for (int i = 0; i < tests.length; i++) {
               assertEquals(tests[i][1], FilenameUtils.getExtension(tests[i][0]));
  @@ -244,9 +244,9 @@
                   { "README", "README" }, 
                   { "domain.dot.com", "domain.dot" }, 
                   { "image.jpeg", "image" },
  -                { "a.b/c", "a.b/c" },
  -                { "a.b/c.txt", "a.b/c" },
  -                { "a/b/c", "a/b/c" },
  +                { "a.b" + File.separator + "c", "a.b" + File.separator + "c" },
  +                { "a.b" + File.separator + "c.txt", "a.b" + File.separator + "c" },
  +                { "a" + File.separator + "b" + File.separator + "c", "a" + File.separator
+ "b" + File.separator + "c" },
           };
   
           for (int i = 0; i < tests.length; i++) {
  
  
  
  1.3       +19 -5     jakarta-commons/io/src/test/org/apache/commons/io/find/FileFinderTest.java
  
  Index: FileFinderTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/find/FileFinderTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileFinderTest.java	22 Sep 2004 02:02:35 -0000	1.2
  +++ FileFinderTest.java	24 Oct 2004 00:10:05 -0000	1.3
  @@ -29,7 +29,7 @@
   
       private HashMap options;
       private FileFinder finder;
  -    private String dirStr = "src/test/find-data/";
  +    private String dirStr = "src" + File.separator + "test" + File.separator + "find-data"
+ File.separator;
       private File dir = new File(dirStr);
   
       public FileFinderTest(String name) {
  @@ -61,13 +61,13 @@
       }
   
       public void testFindPath() {
  -        options.put(Finder.PATH, dirStr+"path/dir/file");
  +        options.put(Finder.PATH, dirStr+"path" + File.separator + "dir" + File.separator
+ "file");
           File[] files = finder.find(new File(dir, "path"), options);
           assertEquals(1, files.length);
       }
   
       public void testFindIPath() {
  -        options.put(Finder.IPATH, dirStr+"PAth/dIR/fILe");
  +        options.put(Finder.IPATH, dirStr+"PAth" + File.separator + "dIR" + File.separator
+ "fILe");
           File[] files = finder.find(new File(dir, "path"), options);
           assertEquals(1, files.length);
       }
  @@ -79,13 +79,13 @@
       }
   
       public void testFindRegex() {
  -        options.put(Finder.REGEX, dirStr+"regex/f.*");
  +        options.put(Finder.REGEX, escapePath(dirStr+"regex" + File.separator + "f.*"));
           File[] files = finder.find(new File(dir, "regex"), options);
           assertEquals(3, files.length);
       }
   
       public void testFindIRegex() {
  -        options.put(Finder.IREGEX, dirStr+"REgeX/F.*");
  +        options.put(Finder.IREGEX, escapePath(dirStr+"REgeX" + File.separator + "F.*"));
           File[] files = finder.find(new File(dir, "regex"), options);
           assertEquals(3, files.length);
       }
  @@ -138,6 +138,20 @@
           options.put(Finder.CAN_READ, "false");
           File[] files = finder.find(new File(dir, "can_read"), options);
           assertEquals(0, files.length);
  +    }
  +
  +    private static String escapePath(String text) {
  +        String repl = "\\";
  +        String with = "\\\\";
  +
  +        StringBuffer buf = new StringBuffer(text.length());
  +        int start = 0, end = 0;
  +        while ((end = text.indexOf(repl, start)) != -1) {
  +            buf.append(text.substring(start, end)).append(with);
  +            start = end + repl.length();
  +        }
  +        buf.append(text.substring(start));
  +        return buf.toString();
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message