package picocli;


import static org.junit.Assert.assertEquals;
import static picocli.CommandLine.Help.Column.Overflow.SPAN;
import static picocli.CommandLine.Help.Column.Overflow.WRAP;
import static picocli.CommandLine.Help.TextTable.forColumns;

import org.junit.Test;

public class TextTableTest
{

  private final String key = "<query>";
  private final String newline = String.format("%n");
  private final String value = "Shows results of SQL <query>\n"
                               + "The query itself can contain the variables ${table}, ${columns} "
                               + "and ${tabletype}, or system properties referenced as ${<system-property-name>}\n"
                               + "Queries without any variables are executed exactly once\n"
                               + "Queries with variables are executed once for each table, "
                               + "with the variables substituted";

  @Test
  public void addRowValues()
  {
    CommandLine.Help.TextTable textTable = emptyTable();
    textTable.addRowValues(key, value);
    assertEquals(" <query>        Shows results of SQL <query>\n"
                 + "The query itself can contain the\n"
                 + "                  variables ${table}, ${columns} and ${tabletype}, or system\n"
                 + "                  properties referenced as ${<system-property-name>}\n"
                 + "Queries\n"
                 + "                  without any variables are executed exactly once\n"
                 + "Queries with\n"
                 + "                  variables are executed once for each table, with the\n"
                 + "                  variables substituted\n",
                 normalizeNewlines(textTable));
  }

  @Test
  public void addRowValuesWithNewlines()
  {
    CommandLine.Help.TextTable textTable = emptyTable();
    textTable.addRowValuesWithNewlines(key, value);
    assertEquals(" <query>        Shows results of SQL <query>\n"
                 + "                The query itself can contain the variables ${table}, ${columns}\n"
                 + "                  and ${tabletype}, or system properties referenced as\n"
                 + "                  ${<system-property-name>}\n"
                 + "                Queries without any variables are executed exactly once\n"
                 + "                Queries with variables are executed once for each table, with\n"
                 + "                  the variables substituted\n",
                 normalizeNewlines(textTable));
  }

  private CommandLine.Help.TextTable emptyTable()
  {
    return forColumns(CommandLine.Help.Ansi.OFF,
                      new CommandLine.Help.Column(15, 1, SPAN),
                      new CommandLine.Help.Column(65, 1, WRAP));
  }

  private String normalizeNewlines(final CommandLine.Help.TextTable textTable)
  {
    return textTable.toString().replaceAll(newline, "\n");
  }

}

@@ -2543,32 +2543,283 @@
 xtTable));%0A  %7D%0A%0A
+  @Test%0A  public void addRowValuesWithNewlines_nulls()%0A  %7B%0A    CommandLine.Help.TextTable textTable = emptyTable();%0A    textTable.addRowValuesWithNewlines(key, null);%0A    assertEquals(%22 %3Cquery%3E%5Cn%22,%0A                 normalizeNewlines(textTable));%0A  %7D%0A%0A
   private Comman

Add coverage for TextTable tests