1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.jelly;
17  
18  import junit.framework.Test;
19  import junit.framework.TestCase;
20  import junit.framework.TestSuite;
21  import junit.textui.TestRunner;
22  
23  import org.apache.commons.jelly.impl.TextScript;
24  
25  /***
26   * Tests the whitespace triming of scripts.
27   *
28   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
29   * @version $Revision: 155420 $
30   */
31  public class TestTrim extends TestCase {
32  
33      public static void main(String[] args) {
34          TestRunner.run(suite());
35      }
36  
37      public static Test suite() {
38          return new TestSuite(TestTrim.class);
39      }
40  
41      public TestTrim(String testName) {
42          super(testName);
43      }
44  
45      public void testTrim() throws Exception {
46          TextScript script = new TextScript( "   foo    " );
47          script.trimWhitespace();
48  
49          assertEquals( "foo", script.getText() );
50  
51          script = new TextScript( " foo " );
52          script.trimWhitespace();
53  
54          assertEquals( "foo", script.getText() );
55  
56          script = new TextScript( "foo" );
57          script.trimWhitespace();
58  
59          assertEquals( "foo", script.getText() );
60      }
61  
62      public void testTrimStart() throws Exception {
63          TextScript script = new TextScript( "   foo    " );
64          script.trimStartWhitespace();
65  
66          assertEquals( "foo    ", script.getText() );
67  
68          script = new TextScript( " foo " );
69          script.trimStartWhitespace();
70  
71          assertEquals( "foo ", script.getText() );
72  
73          script = new TextScript( "foo" );
74          script.trimStartWhitespace();
75  
76          assertEquals( "foo", script.getText() );
77      }
78  
79      public void testTrimEnd() throws Exception {
80          TextScript script = new TextScript( "   foo    " );
81          script.trimEndWhitespace();
82  
83          assertEquals( "   foo", script.getText() );
84  
85          script = new TextScript( " foo " );
86          script.trimEndWhitespace();
87  
88          assertEquals( " foo", script.getText() );
89  
90          script = new TextScript( "foo" );
91          script.trimEndWhitespace();
92  
93          assertEquals( "foo", script.getText() );
94      }
95  }