package ch.flurischt.html2rtf;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

import org.junit.Test;

import com.tutego.jrtf.Rtf;

public class ParserTest {

	private static final String SIMPLE = "mach mal e <b>test</b> fertig";
	private static final String COMPLEX = "<i>dies ist ein <b>fe<u>tt</u>er</b> test</i>";

	private static final String FILENAME = "/tmp/test.rtf";

	/**
	 * 
	 */
	@Test
	public void testSimpleHtml() {
		Rtf rtf = Parser.parse(SIMPLE);
		assertNotNull(rtf);
		toFile(rtf, FILENAME);
	}

	/**
	 * 
	 */
	@Test
	public void testComplexHtml() {
		Rtf r = Parser.parse(COMPLEX);
		assertNotNull(r);
		toFile(r, FILENAME);
	}

	private void toFile(Rtf rtf, String filename) {
		try {
			rtf.out(new FileWriter(filename));
		} catch (IOException e) {
			fail("No File written");
		}

		// make sure jrtf wrote this thing
		File f = new File(FILENAME);
		assertTrue(f.exists());
	}

}

@@ -267,16 +267,413 @@
 rtf.Rtf;
+%0Aimport static com.tutego.jrtf.Rtf.rtf;%0Aimport static com.tutego.jrtf.RtfDocfmt.*;%0Aimport static com.tutego.jrtf.RtfHeader.*;%0Aimport static com.tutego.jrtf.RtfInfo.*;%0Aimport static com.tutego.jrtf.RtfFields.*;%0Aimport static com.tutego.jrtf.RtfPara.*;%0Aimport static com.tutego.jrtf.RtfSectionFormatAndHeaderFooter.*;%0Aimport static com.tutego.jrtf.RtfText.*;%0Aimport static com.tutego.jrtf.RtfUnit.*;
 %0A%0Apublic
@@ -1185,16 +1185,234 @@
 E);%0A%09%7D%0A%0A
+%09@Test%0A%09public void testJrtFSyntax() throws IOException%7B%0A%09%09rtf().section(%0A%09%09%09%09p(%0A%09%09%09%09%09%09text(%22test%22),%0A%09%09%09%09%09%09italic(%22bla%22)%0A%09%09%09%09), %0A%09%09%09%09p(%0A%09%09%09%09%09%09text(%22neuer absatz%22)%0A%09%09%09%09)%0A%09%09%09%09).out(new FileWriter(%22/tmp/jrtf.rtf%22));%0A%09%7D%0A%09%0A
 %09private

add a "test" method to play with the jrtf API