package io.ebean.dbmigration.ddl;

import org.testng.annotations.Test;

import java.io.StringReader;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class DdlParserTest {


  private DdlParser parser = new DdlParser();

  @Test
  public void parse_ignoresEmptyLines() throws Exception {

    List<String> stmts = parser.parse(new StringReader("\n\none;\n\ntwo;\n\n"));

    assertThat(stmts).hasSize(2);
    assertThat(stmts).contains("one;","two;");
  }

  @Test
  public void parse_ignoresComments_whenFirst() throws Exception {

    List<String> stmts = parser.parse(new StringReader("-- comment\ntwo;"));

    assertThat(stmts).hasSize(1);
    assertThat(stmts).contains("two;");
  }

  @Test
  public void parse_ignoresEmptyLines_whenFirst() throws Exception {

    List<String> stmts = parser.parse(new StringReader("\n\n-- comment\ntwo;\n\n"));
    assertThat(stmts).hasSize(1);
    assertThat(stmts).contains("two;");
  }

  @Test
  public void parse_inlineEmptyLines_replacedWithSpace() throws Exception {

    List<String> stmts = parser.parse(new StringReader("\n\n-- comment\none\ntwo;\n\n"));
    assertThat(stmts).hasSize(1);
    assertThat(stmts).contains("one two;");
  }


  @Test
  public void parse_ignoresComments() throws Exception {

    List<String> stmts = parser.parse(new StringReader("one;\n-- comment\ntwo;"));

    assertThat(stmts).hasSize(2);
    assertThat(stmts).contains("one;","two;");
  }
}
@@ -32,45 +32,8 @@
 l;%0A%0A
-import org.testng.annotations.Test;%0A%0A
 impo
@@ -80,16 +80,51 @@
 l.List;%0A
+import org.testng.annotations.Test;
 %0Aimport 
@@ -1458,9 +1458,226 @@
 %22);%0A  %7D%0A
-%7D
+%0A  @Test%0A  public void parse_ignoresEndOfLineComments() throws Exception %7B%0A    List%3CString%3E stmts = parser.parse(new StringReader(%22one; -- comment%5Cntwo;%22));%0A    assertThat(stmts).containsExactly(%22one;%22, %22two;%22);%0A  %7D%0A%7D%0A

Add test for end-of-line comments that get parsed incorrectly.