<commit_before>
package no.priv.garshol.duke.test;

import org.junit.Test;
import org.junit.Before;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.assertEquals;
import junit.framework.AssertionFailedError;

import java.util.List;
import java.util.ArrayList;
import java.io.IOException;
import java.io.StringReader;
import java.io.ByteArrayOutputStream;

import no.priv.garshol.duke.utils.NTriplesParser;
import no.priv.garshol.duke.utils.NTriplesWriter;

public class NTriplesWriterTest {
  private ByteArrayOutputStream out;
  private NTriplesWriter writer;
  private List<NTriplesParserTest.Statement> model;

  @Before
  public void setup() {
    out = new ByteArrayOutputStream();
    writer = new NTriplesWriter(out);
  }
  
  @Test
  public void testEmpty() throws IOException {
    writer.done();
    model = getModel();
    assertTrue("empty data didn't produce empty model", model.isEmpty());
  }

  @Test
  public void testOneStatement() throws IOException {
    writer.statement("http://a", "http://b", "foo", true);
    writer.done();
    model = getModel();
    assertEquals(1, model.size());

    NTriplesParserTest.Statement stmt = model.get(0);
    assertEquals("http://a", stmt.subject);
    assertEquals("http://b", stmt.property);
    assertEquals("foo", stmt.object);
    assertEquals(true, stmt.literal);
  }

  @Test
  public void testOneStatementURI() throws IOException {
    writer.statement("http://a", "http://b", "http://c", false);
    writer.done();
    model = getModel();
    assertEquals(1, model.size());

    NTriplesParserTest.Statement stmt = model.get(0);
    assertEquals("http://a", stmt.subject);
    assertEquals("http://b", stmt.property);
    assertEquals("http://c", stmt.object);
    assertEquals(false, stmt.literal);
  }

  @Test
  public void testBlankNode() throws IOException {
    writer.statement("_:foo", "http://b", "foo", true);
    writer.done();
    model = getModel();
    assertEquals(1, model.size());

    NTriplesParserTest.Statement stmt = model.get(0);
    assertEquals("_:foo", stmt.subject);
    assertEquals("http://b", stmt.property);
    assertEquals("foo", stmt.object);
    assertEquals(true, stmt.literal);
  }

  @Test
  public void testNonAscii() throws IOException {
    writer.statement("http://a", "http://b", "f\u00d8\u00d8", true);
    writer.done();
    model = getModel();
    assertEquals(1, model.size());

    NTriplesParserTest.Statement stmt = model.get(0);
    assertEquals("http://a", stmt.subject);
    assertEquals("http://b", stmt.property);
    assertEquals("f\u00d8\u00d8", stmt.object);
    assertEquals(true, stmt.literal);
  }

  @Test
  public void testEscapingQuote() throws IOException {<commit_msg>Added another test to make sure.<commit_after>
package no.priv.garshol.duke.test;

import org.junit.Test;
import org.junit.Before;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.assertEquals;
import junit.framework.AssertionFailedError;

import java.util.List;
import java.util.ArrayList;
import java.io.IOException;
import java.io.StringReader;
import java.io.ByteArrayOutputStream;

import no.priv.garshol.duke.utils.NTriplesParser;
import no.priv.garshol.duke.utils.NTriplesWriter;

public class NTriplesWriterTest {
  private ByteArrayOutputStream out;
  private NTriplesWriter writer;
  private List<NTriplesParserTest.Statement> model;

  @Before
  public void setup() {
    out = new ByteArrayOutputStream();
    writer = new NTriplesWriter(out);
  }
  
  @Test
  public void testEmpty() throws IOException {
    writer.done();
    model = getModel();
    assertTrue("empty data didn't produce empty model", model.isEmpty());
  }

  @Test
  public void testOneStatement() throws IOException {
    writer.statement("http://a", "http://b", "foo", true);
    writer.done();
    model = getModel();
    assertEquals(1, model.size());

    NTriplesParserTest.Statement stmt = model.get(0);
    assertEquals("http://a", stmt.subject);
    assertEquals("http://b", stmt.property);
    assertEquals("foo", stmt.object);
    assertEquals(true, stmt.literal);
  }

  @Test
  public void testOneStatementURI() throws IOException {
    writer.statement("http://a", "http://b", "http://c", false);
    writer.done();
    model = getModel();
    assertEquals(1, model.size());

    NTriplesParserTest.Statement stmt = model.get(0);
    assertEquals("http://a", stmt.subject);
    assertEquals("http://b", stmt.property);
    assertEquals("http://c", stmt.object);
    assertEquals(false, stmt.literal);
  }

  @Test
  public void testBlankNode() throws IOException {
    writer.statement("_:foo", "http://b", "foo", true);
    writer.done();
    model = getModel();
    assertEquals(1, model.size());

    NTriplesParserTest.Statement stmt = model.get(0);
    assertEquals("_:foo", stmt.subject);
    assertEquals("http://b", stmt.property);
    assertEquals("foo", stmt.object);
    assertEquals(true, stmt.literal);
  }

  @Test
  public void testNonAscii() throws IOException {
    writer.statement("http://a", "http://b", "f\u00d8\u00d8", true);
    writer.done();
    model = getModel();
    assertEquals(1, model.size());

    NTriplesParserTest.Statement stmt = model.get(0);
    assertEquals("http://a", stmt.subject);
    assertEquals("http://b", stmt.property);
    assertEquals("f\u00d8\u00d8", stmt.object);
    assertEquals(true, stmt.literal);
  }

  @Test
  public void testReallyNonAscii() throws IOException {
    writer.statement("http://a", "http://b", "yi syllable tuox: \uA126", true);
    writer.done();
    model = getModel();
    assertEquals(1, model.size());

    NTriplesParserTest.Statement stmt = model.get(0);
    assertEquals("http://a", stmt.subject);
    assertEquals("http://b", stmt.property);
    assertEquals("yi syllable tuox: \uA126", stmt.object);
    assertEquals(true, stmt.literal);
  }

  @Test
  public void testEscapingQuote() throws IOException {
{'fraction_non_alphanumeric': 0.15227234613449606, 'fraction_numerical': 0.008049639443233272, 'mean_word_length': 4.037162162162162, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6960216', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1826, 'n_words': 391}