package com.axiomalaska.jdbc;

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

import java.io.File;
import java.io.IOException;
import java.util.List;

import static org.hamcrest.core.Is.is;

import org.junit.Test;

import com.axiomalaska.jdbc.NamedParameterPreparedStatement;
import com.axiomalaska.jdbc.NamedParameterPreparedStatement.ParseResult;
import com.google.common.collect.Lists;

public class TestNamedParameterPreparedStatement {
    @Test
    public void testParsing(){
        String testQuery = "SELECT * FROM table WHERE afield = ':not me' AND bfield = :param1 AND cfield = :param2 and dfield = :param2;";
        String expectedParsedQuery = "SELECT * FROM table WHERE afield = ':not me' AND bfield = ? AND cfield = ? and dfield = ?;";
        List<String> expectedParameterList = Lists.newArrayList("param1", "param2", "param2");
        ParseResult parseResult = NamedParameterPreparedStatement.parse(testQuery);
        assertEquals(expectedParsedQuery, parseResult.getSql());
        assertThat(expectedParameterList, is(parseResult.getOrderedParameters()));
    }

    @Test
    public void testParsing2() throws IOException{
        String testQuery = FileUtil.readFile(new File("src/test/resources/test.sql"));
        String expectedParsedQuery = FileUtil.readFile(new File("src/test/resources/expected.sql"));
        List<String> expectedParameterList = Lists.newArrayList("named_parameter1", "named_parameter2");
        ParseResult parseResult = NamedParameterPreparedStatement.parse(testQuery);
        assertEquals(expectedParsedQuery, parseResult.getSql());
        assertThat(expectedParameterList, is(parseResult.getOrderedParameters()));
    }
}

@@ -1712,11 +1712,583 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testDoubleColon() throws IOException%7B%0A        String testQuery = %22SELECT '%7B1,2,3,4,5%7D'::int%5B%5D WHERE some_field = :some_field_value%22;%0A        String expectedParsedQuery = %22SELECT '%7B1,2,3,4,5%7D'::int%5B%5D WHERE some_field = ?%22;%0A        List%3CString%3E expectedParameterList = Lists.newArrayList(%22some_field_value%22);%0A        ParseResult parseResult = NamedParameterPreparedStatement.parse(testQuery);%0A        assertEquals(expectedParsedQuery, parseResult.getSql());%0A        assertThat(expectedParameterList, is(parseResult.getOrderedParameters()));%0A    %7D
 %0A%7D%0A

Add unit test for double colon parsing