JAL-1805 test envirionment separation
[jalview.git] / test / com / stevesoft / pat / RegexWriterTest.java
1 package com.stevesoft.pat;
2
3 import static org.testng.AssertJUnit.assertEquals;
4
5 import java.io.IOException;
6 import java.io.StringWriter;
7
8 import org.testng.annotations.DataProvider;
9 import org.testng.annotations.Test;
10
11 /**
12  * Test class refactored from RegexWriter main method
13  */
14 public class RegexWriterTest
15 {
16
17   /**
18    * Asserts that the result of performing 'replaceAll' on the input using the
19    * regular expression is the same as the output of a RegexWriter, constructed
20    * from the regular expression, writing out each character of the input
21    * string.
22    * 
23    * @param re
24    *          a regular expression
25    * @param inp
26    *          an input string
27    * @throws Exception
28    */
29
30   @Test(groups =
31   { "Functional" }, dataProvider = "testWriteParam")
32   void test(String re, String inp) throws IOException
33   {
34     StringWriter sw = new StringWriter();
35     Regex rex = Regex.perlCode(re);
36     String res1 = rex.replaceAll(inp);
37     RegexWriter rw = new RegexWriter(rex, sw);
38     for (int i = 0; i < inp.length(); i++)
39     {
40       rw.write(inp.charAt(i));
41     }
42     rw.close();
43     String res2 = sw.toString();
44     if (!res1.equals(res2))
45     {
46       System.out.println("re=" + re);
47       System.out.println("inp=" + inp);
48       System.out.println("res1=" + res1);
49       System.out.println("res2=" + res2);
50       assertEquals(res1, res2);
51     }
52   }
53
54   // @Test(groups ={ "Functional" })
55   // public void testWrite() throws IOException
56   // {
57   // for (int n = 1; n <= 1; n++)
58   // {
59   // test("s/x/y/", "-----x123456789");
60   // test("s/x/y/", "x123456789");
61   // test("s/x/y/", "-----x");
62   // test("s/x.*?x/y/", ".xx..x..x...x...x....x....x");
63   // test("s/x.*x/[$&]/", "--x........x--xx");
64   // test("s/x.*x/[$&]/", "--x........x------");
65   // test("s/.$/a/m", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbbbbbbbbbbbb");
66   // test("s/.$/a/", "123");
67   // test("s/.$/a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb");
68   // test("s/^./a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb");
69   // test("s/$/a/", "bbb");
70   // test("s/^/a/", "bbb");
71   // test("s/^/a/", "");
72   // test("s{.*}{N}", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
73   // test("s/.{0,7}/y/", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
74   // test("s/x/$&/", "xxx");
75   // }
76   // }
77
78   @DataProvider(name = "testWriteParam")
79   public Object[][] regexTestParams()
80   {
81     return new Object[][]
82     {
83     { "s/x/y/", "-----x123456789" },
84     { "s/x/y/", "x123456789" },
85     { "s/x/y/", "-----x" },
86     { "s/x.*?x/y/", ".xx..x..x...x...x....x....x" },
87     { "s/x.*x/[$&]/", "--x........x--xx" },
88     { "s/x.*x/[$&]/", "--x........x------" },
89     { "s/.$/a/m", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbbbbbbbbbbbb" },
90     { "s/.$/a/", "123" },
91     { "s/.$/a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb" },
92     { "s/^./a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb" },
93     { "s/$/a/", "bbb" },
94     { "s/^/a/", "bbb" },
95     { "s/^/a/", "" },
96     { "s{.*}{N}", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" },
97     { "s/.{0,7}/y/", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" },
98     { "s/x/$&/", "xxx" } };
99   }
100 }