summaryrefslogtreecommitdiff
path: root/src/test/java/bjc/everge/ReplPairTest.java
blob: f88279b11b8a27e46487f4dd0625a52925246c9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package bjc.everge;

import java.io.FileInputStream;
import java.io.IOException;

import java.util.List;
import java.util.Scanner;

import static bjc.everge.TestUtils.*;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * Unit test for ReplPair.
 *
 * @author Ben Culkin
 */
@SuppressWarnings("javadoc")
public class ReplPairTest {
	@Test
	public void testLoadFile() {
		List<ReplPair> lrp = null;
		String fName = "data/test/test1-empty.rp";

		try (FileInputStream fis = new FileInputStream(fName);
				Scanner scn = new Scanner(fis)) {
			lrp = ReplPair.readList(scn);

			assertTrue(lrp.size() == 0);
		} catch (IOException ioex) {
			assertTrue(false);
		}
	}

	@Test
	public void testSingleReplace() {
		assertMultiReplace("data/test/test2-singlereplace.rp", "test2", "test1", "test2", "test2");
	}

	@Test
	public void testMultiReplace() {
		assertMultiReplace("data/test/test3-multireplace.rp", "A B C", "a b c", "A A B", "a a b",
				"AAB", "aab");
	}

	@Test
	public void testReplaceOrder() {
		assertMultiReplace("data/test/test4-implicitorder.rp", "a", "a", "d", "ab");
	}

	@Test
	public void testReplaceExpOrder() {
		assertMultiReplace(false, "data/test/test5-explicitorder.rp", "a", "a", "aa", "ab");
	}

	@Test
	public void testStaging() {
		assertMultiReplace("data/test/test6-staging.rp", "c", "a", "y2", "x");
	}

	@Test
	public void testErrorException() {
		String msg = "[ERROR] An error occured parsing replacement pairs:"
				+ "\n\t[ERROR] line 2, pair 1: Ran out of input looking for"
				+ " replacement body for raw name 'a'"
				+ "\n\t\tContext: No associated line";

		assertThrownMessage(msg, "data/test/test7-error.rp");
	}

	@Test
	public void testPairs() {
		ReplPair rp1 = new ReplPair();
		ReplPair rp2 = new ReplPair("", "");

		rp1.name = rp1.find;

		assertEquals(rp2, rp1);
		assertEquals(rp2.toString(), rp1.toString());
	}

	@Test
	public void testGlobals() {
		assertMultiReplace("data/test/test8-globals.rp", "b1d\n1d\n1b1", "acca");
	}

	@Test
	public void testGuards() {
		assertMultiReplace("data/test/test10-guard.rp", "a", "a", "bbb", "aaa");
	}
	
	@Test
	public void testMultiControl() {
		assertMultiReplace("data/test/test11-bodyinlinemulti.rp", "bc", "a", "z\na", "d", "m", "po");
		
		// NOTE Uncomment when :EndingSlash is fixed 
		//assertMultiReplace("data/test/test11.rp", "q\\", "FG");
	}
}