package io.ebean.dbmigration.ddl;

import java.io.StringReader;
import java.util.List;
import org.testng.annotations.Test;
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;");
  }

  @Test
  public void parse_ignoresEndOfLineComments() throws Exception {
    List<String> stmts = parser.parse(new StringReader("one; -- comment\ntwo;"));
    assertThat(stmts).containsExactly("one;", "two;");
  }
}

@@ -405,43 +405,8 @@
 %22));
-%0A%0A    assertThat(stmts).hasSize(2);
 %0A   
@@ -424,32 +424,39 @@
 (stmts).contains
+Exactly
 (%22one;%22,%22two;%22);
@@ -617,43 +617,8 @@
 %22));
-%0A%0A    assertThat(stmts).hasSize(1);
 %0A   
@@ -636,32 +636,39 @@
 (stmts).contains
+Exactly
 (%22two;%22);%0A  %7D%0A%0A 
@@ -833,42 +833,8 @@
 ));%0A
-    assertThat(stmts).hasSize(1);%0A
     
@@ -859,16 +859,23 @@
 contains
+Exactly
 (%22two;%22)
@@ -1060,42 +1060,8 @@
 ));%0A
-    assertThat(stmts).hasSize(1);%0A
     
@@ -1082,24 +1082,31 @@
 ts).contains
+Exactly
 (%22one two;%22)
@@ -1265,43 +1265,8 @@
 %22));
-%0A%0A    assertThat(stmts).hasSize(2);
 %0A   
@@ -1292,16 +1292,23 @@
 contains
+Exactly
 (%22one;%22,
@@ -1395,16 +1395,17 @@
 ption %7B%0A
+%0A
     List

Tidy (containsExactly() produces nicer failures than size/contains)