/*
* YamFormatterTest.java Copyright (c) 1998-2008, The University of Sheffield.
*
* This code is from the GATE project (http://gate.ac.uk/) and is free software
* licenced under the GNU General Public License version 3. It is distributed
* without any warranty. For more details see COPYING.txt in the top level
* directory (or at http://gatewiki.sf.net/COPYING.txt).
*
* Hamish Cunningham, 25 August 2009
*/
package gate.yam.format;
import java.io.*;
import junit.framework.*;
import org.apache.log4j.Logger;
import org.springframework.core.io.*;
import org.springframework.context.support.*;
import gate.util.*;
import gate.yam.*;
import gate.yam.parse.*;
import gate.yam.translate.*;
import gate.yam.convert.*;
import gate.yam.format.*;
/**
* Unit test for the YamFile class.
*/
public class YamFormatterTests extends TestCase {
/** Create the test case */
public YamFormatterTests(String testName) {
super(testName);
}
/** Logger */
static Logger log = Logger.getLogger("gate.yam.format.YamFormatterTests");
/**
* Test word wrapping.
*/
public void testWrapping() throws Exception {
log.info("==== testWrapping... =======================");
String testInName = "/gate/yam/resources/formatter-test-in.txt";
String testOutName = "/gate/yam/resources/formatter-test-out.txt";
// input to test on
String testInFilePath = this.getClass().getResource(testInName).getPath();
// output to compare with
String testOutFilePath = this.getClass().getResource(testOutName).getPath();
BufferedReader textReader = null;
StringBuilder inputText = new StringBuilder();
StringBuilder toCompareWith = new StringBuilder();
try {
// reading the input text
textReader = new BufferedReader(new FileReader(testInFilePath));
String line = textReader.readLine();
while(line != null) {
inputText.append(line);
line = textReader.readLine();
if(line != null) inputText.append("\n");
}
textReader.close();
// reading the text to compare with
textReader = new BufferedReader(new FileReader(testOutFilePath));
line = textReader.readLine();
while(line != null) {
toCompareWith.append(line);
line = textReader.readLine();
if(line != null) toCompareWith.append("\n");
}
} finally {
if(textReader != null) textReader.close();
}
// test one
int test1Start = inputText.indexOf("#test1#") + 8; // length + \n
int test1End = inputText.indexOf("#test1-end#") - 1; // \n
YamFormatter.wrap(inputText, test1Start, test1End, 0, 78, 0, 0);
// test two (unordered list item)
int test2Start = inputText.indexOf("#test2#") + 8; // length + \n
int test2End = inputText.indexOf("#test2-end#") - 1; // \n
YamFormatter.wrap(inputText, test2Start, test2End, 4, 78, 0, 0);
// test three (tab test)
int test3Start = inputText.indexOf("#test3#") + 8; // length + \n
int test3End = inputText.indexOf("#test3-end#") - 1; // \n
YamFormatter.wrap(inputText, test3Start, test3End, 4, 78, 0, 0);
// compare strings
assertEquals(inputText.toString(), toCompareWith.toString());
log.info("====================================");
} // testWrapping()
} // YamFormatterTests