package morfologik.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

import org.junit.Assert;
import org.junit.Test;

/*
 * 
 */
public class MorphEncodingToolTest {

	@Test
	public void testTool() throws Exception {
		// Create a simple plain text file.
		File input = File.createTempFile("input", "in");
		File output = File.createTempFile("output", "fsa.txt");
		input.deleteOnExit();
		output.deleteOnExit();

		// Populate the file with data.
		PrintWriter w = new PrintWriter(new OutputStreamWriter(
				new FileOutputStream(input), "UTF-8"));
		w.println("passagère\tpassager\ttag");
		w.println("nieduży\tduży\ttest");
		w.println("abcd\tabc\txyz");
		w.close();

		// suffix
		MorphEncodingTool.main(new String[] { 
				"--input", input.getAbsolutePath(), 
				"--output", output.getAbsolutePath(), 
				"-suf" });

		BufferedReader testOutput = new BufferedReader(new InputStreamReader(
				new FileInputStream(output.getAbsolutePath()), "UTF-8"));
		Assert.assertEquals("passagère+Eer+tag", testOutput.readLine());
		Assert.assertEquals("nieduży+Iduży+test", testOutput.readLine());
		Assert.assertEquals("abcd+B+xyz", testOutput.readLine());

		testOutput.close();

		// prefix
		MorphEncodingTool.main(new String[] { 
				"--input", input.getAbsolutePath(), 
				"--output", output.getAbsolutePath(), 
				"-pre" });

		testOutput = new BufferedReader(new InputStreamReader(
				new FileInputStream(output.getAbsolutePath()), "UTF-8"));
		Assert.assertEquals("passagère+AEer+tag", testOutput.readLine());
		Assert.assertEquals("nieduży+DA+test", testOutput.readLine());
		Assert.assertEquals("abcd+AB+xyz", testOutput.readLine());

		testOutput.close();

		// infix
		MorphEncodingTool.main(new String[] { 
				"--input", input.getAbsolutePath(), 
				"--output", output.getAbsolutePath(), 
				"-inf" });

		testOutput = new BufferedReader(new InputStreamReader(
				new FileInputStream(output.getAbsolutePath()), "UTF-8"));
		Assert.assertEquals("passagère+AAEer+tag", testOutput.readLine());
		Assert.assertEquals("nieduży+ADA+test", testOutput.readLine());
		Assert.assertEquals("abcd+AAB+xyz", testOutput.readLine());

		testOutput.close();

	}

	/* */
	@Test
	public void testStemmingFile() throws Exception {
		// Create a simple plain text file.
		File input = File.createTempFile("input", "in");
		File output = File.createTempFile("output", "fsa.txt");
		input.deleteOnExit();
		output.deleteOnExit();

		// Populate the file with data.
		
		// stemming only
		PrintWriter w = new PrintWriter(new OutputStreamWriter(
				new FileOutputStream(input), "UTF-8"));
		w.println("passagère\tpassager");
		w.println("nieduży\tduży");
		w.println("abcd\tabc");
		w.close();

		MorphEncodingTool.main(new String[] { "--input",
				input.getAbsolutePath(), "--output", output.getAbsolutePath(),
		"-suf" });

		BufferedReader testOutput = new BufferedReader(new InputStreamReader(
				new FileInputStream(output.getAbsolutePath()), "UTF-8"));
		Assert.assertEquals("passagère+Eer+", testOutput.readLine());
		Assert.assertEquals("nieduży+Iduży+", testOutput.readLine());
		Assert.assertEquals("abcd+B+", testOutput.readLine());

		testOutput.close();
	}
}

@@ -2402,16 +2402,676 @@
 e();%0D%0A%0D%0A
+%09%09// custom annotation - test tabs%0D%0A        MorphEncodingTool.main(new String%5B%5D %7B%0D%0A                %22--annotation%22, %22%5Ct%22,%0D%0A                %22--input%22, input.getAbsolutePath(), %0D%0A                %22--output%22, output.getAbsolutePath(), %0D%0A                %22-inf%22 %7D);%0D%0A%0D%0A        testOutput = new BufferedReader(new InputStreamReader(%0D%0A                new FileInputStream(output.getAbsolutePath()), %22UTF-8%22));%0D%0A        Assert.assertEquals(%22passag%C3%A8re%5CtAAEer%5Cttag%22, testOutput.readLine());%0D%0A        Assert.assertEquals(%22niedu%C5%BCy%5CtADA%5Cttest%22, testOutput.readLine());%0D%0A        Assert.assertEquals(%22abcd%5CtAAB%5Ctxyz%22, testOutput.readLine());%0D%0A%0D%0A        testOutput.close();%0D%0A%09%09%0D%0A
 %09%7D%0D%0A%0D%0A%09/

add JUnit test for custom annotation format