<commit_before>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());
	}

}
<commit_msg>add a "test" method to play with the jrtf API<commit_after>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;
import static com.tutego.jrtf.Rtf.rtf;
import static com.tutego.jrtf.RtfDocfmt.*;
import static com.tutego.jrtf.RtfHeader.*;
import static com.tutego.jrtf.RtfInfo.*;
import static com.tutego.jrtf.RtfFields.*;
import static com.tutego.jrtf.RtfPara.*;
import static com.tutego.jrtf.RtfSectionFormatAndHeaderFooter.*;
import static com.tutego.jrtf.RtfText.*;
import static com.tutego.jrtf.RtfUnit.*;

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);
	}

	@Test
	public void testJrtFSyntax() throws IOException{
		rtf().section(
				p(
						text("test"),
						italic("bla")
				), 
				p(
						text("neuer absatz")
				)
				).out(new FileWriter("/tmp/jrtf.rtf"));
	}
	
	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());
	}

}

{'fraction_non_alphanumeric': 0.14127720299678914, 'fraction_numerical': 0.0007135212272565109, 'mean_word_length': 3.7687074829931975, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1789977', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1037, 'n_words': 241}