jstrachan    2002/10/12 05:27:52

  Modified:    jelly/src/test/org/apache/commons/jelly TestCoreTags.java
                        suite.jelly
  Log:
  Added more unit test cases for <forEach> and for whitespace handling and to help fix 
the text trimming bugs
  
  Revision  Changes    Path
  1.10      +42 -5     
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestCoreTags.java
  
  Index: TestCoreTags.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestCoreTags.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestCoreTags.java 7 Jun 2002 09:36:11 -0000       1.9
  +++ TestCoreTags.java 12 Oct 2002 12:27:52 -0000      1.10
  @@ -74,6 +74,7 @@
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.impl.TextScript;
   import org.apache.commons.jelly.parser.XMLParser;
   
   import org.apache.commons.logging.Log;
  @@ -119,5 +120,41 @@
               log.debug(text);
           }
           assertEquals("Produces the correct output", "one two three", text);
  +    }
  +    
  +    public void testTrimEndWhitespace() throws Exception {
  +        TextScript textScript = new TextScript(" ");
  +        textScript.trimEndWhitespace();
  +        assertEquals("", textScript.getText());
  +
  +        textScript = new TextScript("");
  +        textScript.trimEndWhitespace();
  +        assertEquals("", textScript.getText());
  +
  +        textScript = new TextScript(" foo ");
  +        textScript.trimEndWhitespace();
  +        assertEquals(" foo", textScript.getText());
  +
  +        textScript = new TextScript("foo");
  +        textScript.trimEndWhitespace();
  +        assertEquals("foo", textScript.getText());
  +    }
  +    
  +    public void testTrimStartWhitespace() throws Exception {
  +        TextScript textScript = new TextScript(" ");
  +        textScript.trimStartWhitespace();
  +        assertEquals("", textScript.getText());
  +
  +        textScript = new TextScript("");
  +        textScript.trimStartWhitespace();
  +        assertEquals("", textScript.getText());
  +
  +        textScript = new TextScript(" foo ");
  +        textScript.trimStartWhitespace();
  +        assertEquals("foo ", textScript.getText());
  +
  +        textScript = new TextScript("foo");
  +        textScript.trimStartWhitespace();
  +        assertEquals("foo", textScript.getText());
       }
   }
  
  
  
  1.7       +37 -0     
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/suite.jelly,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- suite.jelly       3 Oct 2002 07:52:37 -0000       1.6
  +++ suite.jelly       12 Oct 2002 12:27:52 -0000      1.7
  @@ -152,4 +152,41 @@
                        expected='&lt;foo x="1"&gt;hello&lt;/foo&gt;' 
                        actual="${foo}"/>
     </test:case>
  +
  +
  +     <!-- whitespace trimming tests -->
  +     <test:case name="testTrim">
  +             
  +             <j:set var="foo">
  +                     <j:forEach var="i" begin="1" end="3" trim="false">  ${i} 
</j:forEach>
  +             </j:set>
  +
  +             <test:assertEquals 
  +                     expected="  1   2   3 "
  +                     actual="${foo}"/>
  +             
  +             <j:set var="foo">
  +                     <j:forEach var="i" begin="1" end="3" trim="true">  ${i} 
</j:forEach>
  +             </j:set>
  +
  +             <test:assertEquals 
  +                     expected="123"
  +                     actual="${foo}"/>
  +             
  +             <j:set var="foo">
  +                     <j:forEach var="i" begin="1" end="3" trim="true">  foo ${i} 
</j:forEach>
  +             </j:set>
  +
  +             <test:assertEquals 
  +                     expected="foo 1foo 2foo 3"
  +                     actual="${foo}"/>
  +
  +             <j:set var="foo">
  +                     <j:forEach var="i" begin="1" end="3" trim="true">  foo ${i} 
bar </j:forEach>
  +             </j:set>
  +
  +             <test:assertEquals 
  +                     expected="foo 1 barfoo 2 barfoo 3 bar"
  +                     actual="${foo}"/>
  +  </test:case>
   </test:suite>
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to