package io.digdag.standards.operator.td;

import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.*;
import static io.digdag.standards.operator.td.TdOperatorFactory.insertCommandStatement;

public class TdOperatorFactoryTest
{
    @Test
    public void verifyCommandInserts()
    {
        assertEquals("INSERT\nselect 1",
                insertCommandStatement("INSERT",
                    "select 1"));

        assertEquals("with a as (select 1)\nINSERT\nselect 1",
                insertCommandStatement("INSERT",
                    "with a as (select 1)\n-- DIGDAG_INSERT_LINE\nselect 1"));

        assertEquals("with a as (select 1)\nINSERT\nselect 1",
                insertCommandStatement("INSERT",
                    "with a as (select 1)\n-- DIGDAG_INSERT_LINE xyz\nselect 1"));

        assertEquals("with a as (select 1)\nINSERT\n-- comment\nselect 1",
                insertCommandStatement("INSERT",
                    "with a as (select 1)\n--DIGDAG_INSERT_LINE\n-- comment\nselect 1"));

        assertEquals("-- comment\nINSERT\nselect 1",
                insertCommandStatement("INSERT",
                    "-- comment\nselect 1"));

        assertEquals("-- comment\nINSERT\r\nselect 1",
                insertCommandStatement("INSERT",
                    "-- comment\r\nselect 1"));

        assertEquals("-- comment1\n--comment2\nINSERT\nselect 1",
                insertCommandStatement("INSERT",
                    "-- comment1\n--comment2\nselect 1"));
    }
}

@@ -62,83 +62,8 @@
 st;%0A
-import org.junit.rules.ExpectedException;%0Aimport static org.junit.Assert.*;
 %0Aimp
@@ -146,16 +146,144 @@
 atement;
+%0Aimport static org.hamcrest.Matchers.is;%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertThat;
 %0A%0Apublic
@@ -1571,16 +1571,352 @@
 ct 1%22));
+%0A%0A        %7B%0A            String command = %22INSERT%22;%0A            String query = %22SELECT%5Cn%22 +%0A                    %22-- comment1%5Cn%22 +%0A                    %221;%5Cn%22 +%0A                    %22-- comment2%5Cn%22;%0A            String expected = command + %22%5Cn%22 + query;%0A            assertThat(insertCommandStatement(command, query), is(expected));%0A        %7D
 %0A    %7D%0A%7D

add failing test