File: GeneratorTest.java

package info (click to toggle)
trove3 3.0.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,924 kB
  • sloc: java: 16,429; xml: 331; makefile: 21; sh: 10
file content (98 lines) | stat: -rw-r--r-- 4,263 bytes parent folder | download | duplicates (5)
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
/*
 * ///////////////////////////////////////////////////////////////////////////////
 * // Copyright (c) 2009, Rob Eden All Rights Reserved.
 * //
 * // This library is free software; you can redistribute it and/or
 * // modify it under the terms of the GNU Lesser General Public
 * // License as published by the Free Software Foundation; either
 * // version 2.1 of the License, or (at your option) any later version.
 * //
 * // This library is distributed in the hope that it will be useful,
 * // but WITHOUT ANY WARRANTY; without even the implied warranty of
 * // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * // GNU General Public License for more details.
 * //
 * // You should have received a copy of the GNU Lesser General Public
 * // License along with this program; if not, write to the Free Software
 * // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * ///////////////////////////////////////////////////////////////////////////////
 */
package gnu.trove.generator;

import junit.framework.TestCase;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


/**
 *
 */
public class GeneratorTest extends TestCase {
	public void testReplicatedContentNoMatch() throws IOException {
		String test = "This is a test\nLine 2\nLine 3";

		StringBuilder buf = new StringBuilder();
		assertNull( Generator.findReplicatedBlocks( test, buf ) );
		assertEquals( 0, buf.length() );
	}

	public void testReplicatedContent() throws IOException {
		String test = "This is a test\nLine 2\n====START_REPLICATED_CONTENT #1====\n" +
			"Replicated 1\n=====END_REPLICATED_CONTENT #1=====\n" +
			"====START_REPLICATED_CONTENT #2====\n" +
			"Replicated 2\n=====END_REPLICATED_CONTENT #2=====\n";

		StringBuilder buf = new StringBuilder();
		Map<Integer,String> map = Generator.findReplicatedBlocks( test, buf );

		assertNotNull( map );
		assertEquals( 2, map.size() );
		assertEquals( "Replicated 1", map.get( Integer.valueOf( 1 ) ) );
		assertEquals( "Replicated 2", map.get( Integer.valueOf( 2 ) ) );
		assertEquals( "This is a test\nLine 2", buf.toString() );
	}

	public void testProcessReplication() {
		String test = "Line 1\n#REPLICATED1#\n#REPLICATED2#\nLine 4";

		Map<Integer,String> map = new HashMap<Integer,String>();
		map.put( Integer.valueOf( 1 ), "Line 2 - #E#" );
		map.put( Integer.valueOf( 2 ), "Line 3 - #K# #V#" );
		
		String output = Generator.processReplication( test, map );
		
		String goal = "Line 1\n" +
			
			"Line 2 - Double\n\n" + "Line 2 - Float\n\n" + "Line 2 - Int\n\n" + 
			"Line 2 - Long\n\n" + "Line 2 - Byte\n\n" + "Line 2 - Short\n\n" +
			"Line 2 - Char\n" +
			
			"Line 3 - Double Double\n\n" + "Line 3 - Double Float\n\n" + "Line 3 - Double Int\n\n" + 
			"Line 3 - Double Long\n\n" + "Line 3 - Double Byte\n\n" + "Line 3 - Double Short\n\n" +
			"Line 3 - Double Char\n\n" +
			"Line 3 - Float Double\n\n" + "Line 3 - Float Float\n\n" + "Line 3 - Float Int\n\n" + 
			"Line 3 - Float Long\n\n" + "Line 3 - Float Byte\n\n" + "Line 3 - Float Short\n\n" +
			"Line 3 - Float Char\n\n" +
			"Line 3 - Int Double\n\n" + "Line 3 - Int Float\n\n" + "Line 3 - Int Int\n\n" + 
			"Line 3 - Int Long\n\n" + "Line 3 - Int Byte\n\n" + "Line 3 - Int Short\n\n" +
			"Line 3 - Int Char\n\n" +
			"Line 3 - Long Double\n\n" + "Line 3 - Long Float\n\n" + "Line 3 - Long Int\n\n" + 
			"Line 3 - Long Long\n\n" + "Line 3 - Long Byte\n\n" + "Line 3 - Long Short\n\n" +
			"Line 3 - Long Char\n\n" +
			"Line 3 - Byte Double\n\n" + "Line 3 - Byte Float\n\n" + "Line 3 - Byte Int\n\n" + 
			"Line 3 - Byte Long\n\n" + "Line 3 - Byte Byte\n\n" + "Line 3 - Byte Short\n\n" +
			"Line 3 - Byte Char\n\n" +
			"Line 3 - Short Double\n\n" + "Line 3 - Short Float\n\n" + "Line 3 - Short Int\n\n" + 
			"Line 3 - Short Long\n\n" + "Line 3 - Short Byte\n\n" + "Line 3 - Short Short\n\n" +
			"Line 3 - Short Char\n\n" +
			"Line 3 - Char Double\n\n" + "Line 3 - Char Float\n\n" + "Line 3 - Char Int\n\n" + 
			"Line 3 - Char Long\n\n" + "Line 3 - Char Byte\n\n" + "Line 3 - Char Short\n\n" +
			"Line 3 - Char Char\n" +
			
			"Line 4";

		assertEquals( goal, output );
	}
}