// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package routing.demo.convert.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.Test;

import routing.demo.convert.ConvertCSV2JSON;

public class TestCSV2JSON {
    @Test
    public void testSimple() {
        try {
            String csv = "1,\"xxx\"";
            String json = ConvertCSV2JSON.convert(csv, "a,b", ',', '"');
            assertEquals("json", "{ \"a\": 1, \"b\": \"xxx\" }", json);
        } catch (Exception e) {
            fail("Unexpected exception: " + e.getMessage());
        }
    }
    @Test
    public void testTricky() {
        try {
            String csv = "1,\"xxx\",\"y,y\",\"z\"\"z\"";
            String json = ConvertCSV2JSON.convert(csv, "a,b,c,d", ',', '"');
            assertEquals("json", "{ \"a\": 1, \"b\": \"xxx\", \"c\": \"y,y\", \"d\": \"z\\\"z\" }", json);
        } catch (Exception e) {
            fail("Unexpected exception: " + e.getMessage());
        }
    }
}
