ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbaill...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs BasenameTest.java
Date Sat, 13 Jul 2002 09:44:57 GMT
sbailliez    2002/07/13 02:44:57

  Modified:    src/main/org/apache/tools/ant/taskdefs Basename.java
               src/etc/testcases/taskdefs basename.xml
               src/testcases/org/apache/tools/ant/taskdefs
                        BasenameTest.java
  Log:
  Take care of extreme cases to do some suffix magic.
  Added some more testcases to document this behavior.
  
  PR: 10769
  Reported by: jan.grant@bristol.ac.uk (Jan Grant)
  
  Revision  Changes    Path
  1.5       +14 -9     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Basename.java
  
  Index: Basename.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Basename.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Basename.java	9 Jul 2002 21:05:58 -0000	1.4
  +++ Basename.java	13 Jul 2002 09:44:57 -0000	1.5
  @@ -118,20 +118,25 @@
   
     // The method executing the task
     public void execute() throws BuildException {
  -      String value;
         if (property == null) {
             throw new BuildException("property attribute required", location);
         }
         if (file == null) {
             throw new BuildException("file attribute required", location);
  -      } else {
  -        value = file.getName();
  -        if (suffix != null && value.endsWith(suffix)) {
  -            int pos = value.indexOf('.');
  -            value = value.substring(0, pos);
  -        }
  -        getProject().setNewProperty(property, value);
         }
  +      String value = file.getName();
  +      if (suffix != null && value.endsWith(suffix)) {
  +          // if the suffix does not starts with a '.' and the
  +          // char preceding the suffix is a '.', we assume the user
  +          // wants to remove the '.' as well (see docs)
  +          int pos = value.length() - suffix.length();
  +          if (pos > 0 && suffix.charAt(0) != '.' 
  +              && value.charAt(pos - 1) == '.') {
  +              pos--;
  +          }
  +          value = value.substring(0, pos);
  +      }
  +      getProject().setNewProperty(property, value);
     }
   }
   
  
  
  
  1.2       +16 -0     jakarta-ant/src/etc/testcases/taskdefs/basename.xml
  
  Index: basename.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/basename.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- basename.xml	20 Mar 2002 02:48:15 -0000	1.1
  +++ basename.xml	13 Jul 2002 09:44:57 -0000	1.2
  @@ -22,4 +22,20 @@
       <basename property="file.wo.suf" file="foo.txt" suffix="txt"/>
     </target>
   
  +  <target name="testMultipleDots">
  +    <basename property="file.wo.suf" file="foo.bar.txt" suffix="txt"/>
  +  </target>
  +
  +  <target name="testNoDots">
  +    <basename property="file.wo.suf" file="foo.bartxt" suffix="txt"/>
  +  </target>
  +  
  +  <target name="testValueEqualsSuffixWithDot">
  +    <basename property="file.wo.suf" file=".txt" suffix=".txt"/>
  +  </target>
  +
  +  <target name="testValueEqualsSuffixWithoutDot">
  +    <basename property="file.wo.suf" file=".txt" suffix="txt"/>
  +  </target>
  +  
   </project>
  
  
  
  1.3       +26 -8     jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/BasenameTest.java
  
  Index: BasenameTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/BasenameTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BasenameTest.java	20 Mar 2002 02:56:57 -0000	1.2
  +++ BasenameTest.java	13 Jul 2002 09:44:57 -0000	1.3
  @@ -84,20 +84,38 @@
   
       public void test4() { 
           executeTarget("test4");
  -        String expected = "foo.txt";
           String checkprop = project.getProperty("file.w.suf");
  -        if (!checkprop.equals(expected)) { 
  -            fail("basename failed");
  -        }
  +        assertEquals("foo.txt", checkprop);
       }
       
       public void test5() { 
           executeTarget("test5");
  -        String expected = "foo";
           String checkprop = project.getProperty("file.wo.suf");
  -        if (!checkprop.equals(expected)) { 
  -            fail("basename failed");
  -        }
  +        assertEquals("foo", checkprop);
       }
       
  +    public void testMultipleDots() { 
  +        executeTarget("testMultipleDots");
  +        String checkprop = project.getProperty("file.wo.suf");
  +        assertEquals("foo.bar", checkprop);
  +    }
  +    
  +    public void testNoDots() { 
  +        executeTarget("testNoDots");
  +        String checkprop = project.getProperty("file.wo.suf");
  +        assertEquals("foo.bar", checkprop);
  +    }
  +
  +    public void testValueEqualsSuffixWithDot() { 
  +        executeTarget("testValueEqualsSuffixWithDot");
  +        String checkprop = project.getProperty("file.wo.suf");
  +        assertEquals("", checkprop);
  +    }
  +
  +    public void testValueEqualsSuffixWithoutDot() { 
  +        executeTarget("testValueEqualsSuffixWithoutDot");
  +        String checkprop = project.getProperty("file.wo.suf");
  +        assertEquals("", checkprop);
  +    }
  +
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message