ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant ProjectTest.java
Date Wed, 08 Aug 2001 09:01:11 GMT
bodewig     01/08/08 02:01:11

  Modified:    src/testcases/org/apache/tools/ant ProjectTest.java
  Log:
  Testcase for Project.resolveFile
  
  Revision  Changes    Path
  1.4       +61 -0     jakarta-ant/src/testcases/org/apache/tools/ant/ProjectTest.java
  
  Index: ProjectTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/ProjectTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProjectTest.java	2001/01/03 14:18:48	1.3
  +++ ProjectTest.java	2001/08/08 09:01:11	1.4
  @@ -56,6 +56,8 @@
   
   import org.apache.tools.ant.types.*;
   
  +import java.io.File;
  +
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -87,5 +89,64 @@
           assert("PatternSet", 
                  p.createDataType("patternset") instanceof PatternSet);
           assert("Path", p.createDataType("path") instanceof Path);
  +    }
  +
  +    public void testResolveFile() {
  +        /*
  +         * Start with simple absolute file names.
  +         */
  +        assertEquals(File.separator, 
  +                     p.resolveFile("/", null).getPath());
  +        assertEquals(File.separator, 
  +                     p.resolveFile("\\", null).getPath());
  +
  +        /*
  +         * throw in drive letters
  +         */
  +        String driveSpec = "C:";
  +        assertEquals(driveSpec + "\\", 
  +                     p.resolveFile(driveSpec + "/", null).getPath());
  +        assertEquals(driveSpec + "\\", 
  +                     p.resolveFile(driveSpec + "\\", null).getPath());
  +        String driveSpecLower = "c:";
  +        assertEquals(driveSpec + "\\", 
  +                     p.resolveFile(driveSpecLower + "/", null).getPath());
  +        assertEquals(driveSpec + "\\", 
  +                     p.resolveFile(driveSpecLower + "\\", null).getPath());
  +        /*
  +         * promised to eliminate consecutive slashes after drive letter.
  +         */
  +        assertEquals(driveSpec + "\\", 
  +                     p.resolveFile(driveSpec + "/////", null).getPath());
  +        assertEquals(driveSpec + "\\", 
  +                     p.resolveFile(driveSpec + "\\\\\\\\\\\\", null).getPath());
  +
  +        /*
  +         * Now test some relative file name magic.
  +         */
  +        assertEquals(localize("/1/2/3/4"),
  +                     p.resolveFile("4", new File(localize("/1/2/3"))).getPath());
  +        assertEquals(localize("/1/2/3/4"),
  +                     p.resolveFile("./4", new File(localize("/1/2/3"))).getPath());
  +        assertEquals(localize("/1/2/3/4"),
  +                     p.resolveFile(".\\4", new File(localize("/1/2/3"))).getPath());
  +        assertEquals(localize("/1/2/3/4"),
  +                     p.resolveFile("./.\\4", new File(localize("/1/2/3"))).getPath());
  +        assertEquals(localize("/1/2/3/4"),
  +                     p.resolveFile("../3/4", new File(localize("/1/2/3"))).getPath());
  +        assertEquals(localize("/1/2/3/4"),
  +                     p.resolveFile("..\\3\\4", new File(localize("/1/2/3"))).getPath());
  +        assertEquals(localize("/1/2/3/4"),
  +                     p.resolveFile("../../5/.././2/./3/6/../4", new File(localize("/1/2/3"))).getPath());
  +        assertEquals(localize("/1/2/3/4"),
  +                     p.resolveFile("..\\../5/..\\./2/./3/6\\../4", new File(localize("/1/2/3"))).getPath());
  +
  +    }
  +
  +    /**
  +     * adapt file separators to local conventions
  +     */
  +    private String localize(String path) {
  +        return path.replace('\\', File.separatorChar).replace('/', File.separatorChar);
       }
   }
  
  
  

Mime
View raw message