Browse Source

Fix StripJavaComments such that it strips out java comments properly. Testcase added.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271789 13f79535-47bb-0310-9956-ffa450edef68
master
Magesh Umasankar 23 years ago
parent
commit
ef35d9d19d
3 changed files with 48 additions and 2 deletions
  1. +37
    -0
      src/etc/testcases/taskdefs/loadfile.xml
  2. +0
    -2
      src/main/org/apache/tools/ant/filters/StripJavaComments.java
  3. +11
    -0
      src/testcases/org/apache/tools/ant/taskdefs/LoadFileTest.java

+ 37
- 0
src/etc/testcases/taskdefs/loadfile.xml View File

@@ -87,6 +87,42 @@ Hello World!</echo>
</loadfile>
</target>

<target name="testStripJavaComments"
depends="init">
<echo file="loadfile1.tmp">
/*
Comment "1"
*/
public class test1 {
//Some comment
int x = 1/2;
private static final String GREETING="*/Hello/*";
private static final String GREETING1="/*Hello*/";

public static void main( String args[] ) {
}
}</echo>
<echo file="nocomments.tmp">

public class test1 {
int x = 1/2;
private static final String GREETING="*/Hello/*";
private static final String GREETING1="/*Hello*/";

public static void main( String args[] ) {
}
}</echo>
<loadfile srcFile="loadfile1.tmp"
property="testStripJavaComments">
<filterchain>
<stripjavacomments/>
</filterchain>
</loadfile>
<loadfile srcFile="nocomments.tmp"
property="expected"/>
</target>

<target name="testOneLine"
depends="init">
<echo
@@ -105,6 +141,7 @@ Hello World!</echo>

<target name="cleanup">
<delete file="loadfile1.tmp"/>
<delete file="nocomments.tmp"/>
</target>

</project>

+ 0
- 2
src/main/org/apache/tools/ant/filters/StripJavaComments.java View File

@@ -62,8 +62,6 @@ import java.io.Reader;
* (if you have more complex Java parsing needs, use a real lexer).
* Since this class heavily relies on the single char read function,
* you are reccomended to make it work on top of a buffered reader.
*
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class StripJavaComments
extends BaseFilterReader


+ 11
- 0
src/testcases/org/apache/tools/ant/taskdefs/LoadFileTest.java View File

@@ -173,6 +173,17 @@ public class LoadFileTest extends BuildFileTest {
}
}

/**
* A unit test for JUnit
*/
public void testStripJavaComments()
throws BuildException {
executeTarget("testStripJavaComments");
String expected = project.getProperty("expected");
if(!project.getProperty("testStripJavaComments").equals(expected)) {
fail("StripJavaComments broken");
}
}

/**
* A unit test for JUnit


Loading…
Cancel
Save