<commit_before>package org.jsapar.schema;

import java.io.IOException;
import java.io.StringWriter;

import org.jsapar.JSaParException;
import org.jsapar.Line;
import org.jsapar.StringCell;
import org.jsapar.input.LineErrorEvent;
import org.jsapar.input.LineParsedEvent;
import org.jsapar.input.ParseException;
import org.jsapar.input.ParsingEventListener;
import static  org.junit.Assert.*;
import org.junit.Test;

public class CSVSchemaLineTest  {

    boolean foundError=false;
    
    private class NullParsingEventListener implements ParsingEventListener {
	public void lineErrorEvent(LineErrorEvent event) throws ParseException {
	}

	public void lineParsedEvent(LineParsedEvent event) throws JSaParException {
	}
    }

    @Test
    public final void testCSVSchemaLine()  {
        CsvSchemaLine schemaLine = new CsvSchemaLine();
        assertEquals("", schemaLine.getLineType());
        assertEquals("", schemaLine.getLineTypeControlValue());
    }

    @Test
    public final void testCSVSchemaLine_String()  {
        CsvSchemaLine schemaLine = new CsvSchemaLine("LineType");
        assertEquals("LineType", schemaLine.getLineType());
        assertEquals("LineType", schemaLine.getLineTypeControlValue());
    }
    
    @Test
    public void testBuild() throws JSaParException {
	CsvSchemaLine schemaLine = new CsvSchemaLine(1);
	String sLine = "Jonas;Stenberg;Hemvgen 19;111 22;Stockholm";
	boolean rc = schemaLine.parse(1, sLine, new ParsingEventListener() {

	    @Override
	    public void lineErrorEvent(LineErrorEvent event) throws ParseException {
	    }

	    @Override
	    public void lineParsedEvent(LineParsedEvent event) throws JSaParException {
		Line line = event.getLine();
		assertEquals("Jonas", line.getCell(0).getStringValue());
		assertEquals("Stenberg", line.getCell(1).getStringValue());
	    }
	});

	assertEquals(true, rc);
    }

    @Test
    public void testBuild_quoted() throws JSaParException {
	CsvSchemaLine schemaLine = new CsvSchemaLine(1);
	schemaLine.setQuoteChar('\"');
	String sLine = "Jonas;Stenberg;\"Hemvgen ;19\";111 22;Stockholm";
	boolean rc = schemaLine.parse(1, sLine, new ParsingEventListener() {

	    @Override
	    public void lineErrorEvent(LineErrorEvent event) throws ParseException {
	    }

	    @Override
	    public void lineParsedEvent(LineParsedEvent event) throws JSaParException {
		Line line = event.getLine();
		assertEquals(5, line.getNumberOfCells());
		assertEquals("Jonas", line.getCell(0).getStringValue());
		assertEquals("Stenberg", line.getCell(1).getStringValue());
		assertEquals("Hemvgen ;19", line.getCell(2).getStringValue());
		assertEquals("111 22", line.getCell(3).getStringValue());
		assertEquals("Stockholm", line.getCell(4).getStringValue());
	    }
	});

	assertEquals(true, rc);
    }

    @Test
    public void testBuild_quoted_last() throws JSaParException {
        CsvSchemaLine schemaLine = new CsvSchemaLine(1);
        schemaLine.setQuoteChar('\"');
        String sLine = "Jonas;Stenberg;\"Hemvgen ;19\"";
        boolean rc = schemaLine.parse(1, sLine, new ParsingEventListener() {

            @Override
            public void lineErrorEvent(LineErrorEvent event) throws ParseException {
            }

            @Override
            public void lineParsedEvent(LineParsedEvent event) throws JSaParException {
                Line line = event.getLine();
                assertEquals(3, line.getNumberOfCells());
                assertEquals("Jonas", line.getCell(0).getStringValue());
                assertEquals("Stenberg", line.getCell(1).getStringValue());
                assertEquals("Hemvgen ;19", line.getCell(2).getStringValue());
            }
        });

        assertEquals(true, rc);
    }
    
    @Test
    public void testBuild_quoted_missing_end() throws JSaParException {
	CsvSchemaLine schemaLine = new CsvSchemaLine(1);
	schemaLine.setQuoteChar('\"');
	String sLine = "Jonas;Stenberg;\"Hemvgen ;19;111 22;Stockholm";
	try {
	    @SuppressWarnings("unused")
	    boolean rc = schemaLine.parse(1, sLine, new NullParsingEventListener());
	} catch (ParseException e) {
	    return;
	}
	fail("Should throw ParseException for missing end quote");
    }

    @Test
    public void testBuild_quoted_miss_placed_start() throws JSaParException {<commit_msg>Added test case for extra cell separator.<commit_after>package org.jsapar.schema;

import java.io.IOException;
import java.io.StringWriter;

import org.jsapar.JSaParException;
import org.jsapar.Line;
import org.jsapar.StringCell;
import org.jsapar.input.LineErrorEvent;
import org.jsapar.input.LineParsedEvent;
import org.jsapar.input.ParseException;
import org.jsapar.input.ParsingEventListener;
import static  org.junit.Assert.*;
import org.junit.Test;

public class CSVSchemaLineTest  {

    boolean foundError=false;
    
    private class NullParsingEventListener implements ParsingEventListener {
	public void lineErrorEvent(LineErrorEvent event) throws ParseException {
	}

	public void lineParsedEvent(LineParsedEvent event) throws JSaParException {
	}
    }

    @Test
    public final void testCSVSchemaLine()  {
        CsvSchemaLine schemaLine = new CsvSchemaLine();
        assertEquals("", schemaLine.getLineType());
        assertEquals("", schemaLine.getLineTypeControlValue());
    }

    @Test
    public final void testCSVSchemaLine_String()  {
        CsvSchemaLine schemaLine = new CsvSchemaLine("LineType");
        assertEquals("LineType", schemaLine.getLineType());
        assertEquals("LineType", schemaLine.getLineTypeControlValue());
    }
    
    @Test
    public void testBuild() throws JSaParException {
	CsvSchemaLine schemaLine = new CsvSchemaLine(1);
	String sLine = "Jonas;Stenberg;Hemvgen 19;111 22;Stockholm";
	boolean rc = schemaLine.parse(1, sLine, new ParsingEventListener() {

	    @Override
	    public void lineErrorEvent(LineErrorEvent event) throws ParseException {
	    }

	    @Override
	    public void lineParsedEvent(LineParsedEvent event) throws JSaParException {
		Line line = event.getLine();
		assertEquals("Jonas", line.getCell(0).getStringValue());
		assertEquals("Stenberg", line.getCell(1).getStringValue());
	    }
	});

	assertEquals(true, rc);
    }

    @Test
    public void testBuild_quoted() throws JSaParException {
	CsvSchemaLine schemaLine = new CsvSchemaLine(1);
	schemaLine.setQuoteChar('\"');
	String sLine = "Jonas;Stenberg;\"Hemvgen ;19\";111 22;Stockholm";
	boolean rc = schemaLine.parse(1, sLine, new ParsingEventListener() {

	    @Override
	    public void lineErrorEvent(LineErrorEvent event) throws ParseException {
	    }

	    @Override
	    public void lineParsedEvent(LineParsedEvent event) throws JSaParException {
		Line line = event.getLine();
		assertEquals(5, line.getNumberOfCells());
		assertEquals("Jonas", line.getCell(0).getStringValue());
		assertEquals("Stenberg", line.getCell(1).getStringValue());
		assertEquals("Hemvgen ;19", line.getCell(2).getStringValue());
		assertEquals("111 22", line.getCell(3).getStringValue());
		assertEquals("Stockholm", line.getCell(4).getStringValue());
	    }
	});

	assertEquals(true, rc);
    }

    @Test
    public void testBuild_quoted_last() throws JSaParException {
        CsvSchemaLine schemaLine = new CsvSchemaLine(1);
        schemaLine.setQuoteChar('\"');
        String sLine = "Jonas;Stenberg;\"Hemvgen ;19\"";
        boolean rc = schemaLine.parse(1, sLine, new ParsingEventListener() {

            @Override
            public void lineErrorEvent(LineErrorEvent event) throws ParseException {
            }

            @Override
            public void lineParsedEvent(LineParsedEvent event) throws JSaParException {
                Line line = event.getLine();
                assertEquals(3, line.getNumberOfCells());
                assertEquals("Jonas", line.getCell(0).getStringValue());
                assertEquals("Stenberg", line.getCell(1).getStringValue());
                assertEquals("Hemvgen ;19", line.getCell(2).getStringValue());
            }
        });

        assertEquals(true, rc);
    }

    @Test
    public void testBuild_quoted_last_cellsep() throws JSaParException {
        CsvSchemaLine schemaLine = new CsvSchemaLine(1);
        schemaLine.setQuoteChar('\"');
        String sLine = "Jonas;Stenberg;\"Hemvgen ;19\";";
        boolean rc = schemaLine.parse(1, sLine, new ParsingEventListener() {

            @Override
            public void lineErrorEvent(LineErrorEvent event) throws ParseException {
            }

            @Override
            public void lineParsedEvent(LineParsedEvent event) throws JSaParException {
                Line line = event.getLine();
                assertEquals(3, line.getNumberOfCells());
                assertEquals("Jonas", line.getCell(0).getStringValue());
                assertEquals("Stenberg", line.getCell(1).getStringValue());
                assertEquals("Hemvgen ;19", line.getCell(2).getStringValue());
            }
        });

        assertEquals(true, rc);
    }
    
    @Test
    public void testBuild_quoted_missing_end() throws JSaParException {
	CsvSchemaLine schemaLine = new CsvSchemaLine(1);
	schemaLine.setQuoteChar('\"');
	String sLine = "Jonas;Stenberg;\"Hemvgen ;19;111 22;Stockholm";
	try {
	    @SuppressWarnings("unused")
	    boolean rc = schemaLine.parse(1, sLine, new NullParsingEventListener());
	} catch (ParseException e) {
	    return;
	}
	fail("Should throw ParseException for missing end quote");
    }

    @Test
    public void testBuild_quoted_miss_placed_start() throws JSaParException {
{'fraction_non_alphanumeric': 0.10999371464487744, 'fraction_numerical': 0.011942174732872407, 'mean_word_length': 3.603182256509161, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4323874', 'n_tokens_mistral': 2918, 'n_tokens_neox': 2717, 'n_words': 579}