KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > TestRegexpTranslator


1 package org.jruby;
2
3 import junit.framework.TestCase;
4
5 public class TestRegexpTranslator extends TestCase {
6
7     private RegexpTranslator translator;
8     public void setUp() {
9         translator = new RegexpTranslator();
10     }
11
12     public void testSpaceInClass() {
13         verifyTranslation("[ ]", "[ ]", false);
14         verifyTranslation("[\\x20]", "[ ]", true);
15         verifyTranslation("[A\\x20]", "[A ]", true);
16         verifyTranslation("[A\\x20B]", "[A B]", true);
17         verifyTranslation(" [ ] ", " [ ] ", false);
18         verifyTranslation(" [\\x20] ", " [ ] ", true);
19     }
20
21     public void testSharpInClass() {
22         verifyTranslation("[#]", "[#]", false);
23         verifyTranslation("[\\x23]", "[#]", true);
24         verifyTranslation("[A\\x23]", "[A#]", true);
25         verifyTranslation("[A\\x23B]", "[A#B]", true);
26         verifyTranslation(" [#] ", " [#] ", false);
27         verifyTranslation(" [\\x23] ", " [#] ", true);
28     }
29
30     public void testThreeDigitOctal() {
31         verifyTranslation("\\0177", "\\177",false);
32         verifyTranslation("\\0277", "\\277",false);
33         verifyTranslation("\\0377", "\\377",false);
34         verifyTranslation("\\0477", "\\477",false);
35     }
36
37     private void verifyTranslation(String JavaDoc expected, String JavaDoc rubyRE, boolean withComments) {
38         String JavaDoc actual = translator.translatePattern(rubyRE, withComments);
39         assertEquals(rubyRE + "; withComments=" + withComments, expected, actual);
40     }
41 }
42
Popular Tags