예제 #1
0
 public void TestFormatNoColumns()
 {
     Table table = new Table();
     table.Rows.Add();
     table.Rows.Add();
     IEnumerable<string > actual = Formatter.Format(table);
     MoreAssert.HasCount(2, actual);
     foreach(string line in actual)
     {
         MoreAssert.IsEmpty(line);
     }
 }
예제 #2
0
 public void TestFormat2x2()
 {
     Table table = new Table();
     table.Columns.Add("thing", typeof(int));
     table.Columns.Add("stuff", typeof(char));
     table.Rows.Add(1, 'a');
     table.Rows.Add(2, 'b');
     table.Rows.Add(3, 'c');
     IEnumerable<string > expected = new List<string> { "1 a", "2 b", "3 c", };
     IEnumerable<string > actual = Formatter.Format(table);
     MoreAssert.CollectionsEqual(expected, actual);
 }
예제 #3
0
 internal InnerFormatter(Table table, char leftBorder, char columnSeparator, char rightBorder, char topBorder, char bottomBorder, char corner)
 {
     if(table == null)
     {
         throw new ArgumentNullException("table");
     }
     Table = table;
     ColumnWidths = Table.GetColumnWidths().ToList();
     TopBorderChar = topBorder;
     BottomBorderChar = bottomBorder;
     LeftBorderChar = leftBorder;
     ColumnSeparatorChar = columnSeparator;
     RightBorderChar = rightBorder;
     CornerChar = corner;
 }
예제 #4
0
 private InnerFormatter GetFormatterFor(Table table)
 {
     if(table == null)
     {
         throw new ArgumentNullException("table");
     }
     return new InnerFormatter(table, LeftBorderChar, ColumnSeparatorChar, RightBorderChar, TopBorderChar, BottomBorderChar, CornerChar);
 }
예제 #5
0
 /// <summary>
 /// Get a row separator for the specified <see cref="Table" />.
 /// </summary>
 /// <param name="table">
 /// The <see cref="Table" /> for which to get the row separator.
 /// </param>
 /// <param name="separator">
 /// The character to use to separate the two.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// Thrown if <paramref name="table"/> is <see langword="null" />.
 /// </exception>
 public string GetRowSeparator(Table table, char separator)
 {
     if(table == null)
     {
         throw new ArgumentNullException("table");
     }
     return GetFormatterFor(table).GetRowSeparator(separator);
 }
예제 #6
0
 /// <summary>
 /// Format a <see cref="Table" /> to be printed on the console.
 /// </summary>
 /// <param name="table">
 /// The <see cref="Table" /> to format.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// Thrown if <paramref name="table"/> is <see langword="null" />.
 /// </exception>
 public IEnumerable<string> Format(Table table)
 {
     if(table == null)
     {
         throw new ArgumentNullException("table");
     }
     return GetFormatterFor(table).Format();
 }
 internal InnerFormatter(Table table, char leftBorder, char columnSeparator, char rightBorder, char topBorder, char bottomBorder, char bodyTop, char corner)
     : base(table, leftBorder, columnSeparator, rightBorder, bodyTop, bottomBorder, corner)
 {
     ColumnWidths = Table.GetColumnWidths(true);
     TopBorderChar = topBorder;
 }
 /// <summary>
 /// Format a <see cref="Table" /> to be pritned on the console.
 /// </summary>
 /// <param name="table">
 /// The sequence of values in the table.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// Thrown if <paramref name="values"/> is <see langword="null" />.
 /// </exception>
 public new IEnumerable<string> Format(Table table)
 {
     if(table == null)
     {
         throw new ArgumentNullException("table");
     }
     return new InnerFormatter(table, LeftBorderChar, ColumnSeparatorChar, RightBorderChar, TopBorderChar, BottomBorderChar, BodyTopChar, CornerChar).Format();
 }
예제 #9
0
 public void TestFormatNoRows()
 {
     Table table = new Table();
     table.Columns.Add("x");
     table.Columns.Add("y");
     IEnumerable<string > actual = Formatter.Format(table);
     MoreAssert.IsEmpty(actual);
     actual = FormatterT.Format(table);
     MoreAssert.HasCount(1, actual);
     Assert.AreEqual("+", actual.First());
     actual = FormatterTB.Format(table);
     MoreAssert.HasCount(2, actual);
     foreach(string line in actual)
     {
         Assert.AreEqual("-", line);
     }
 }
예제 #10
0
 public void TestGetRowSeparator()
 {
     Table table = new Table();
     table.Columns.Add("thing", typeof(string));
     table.Columns.Add("stuff", typeof(string));
     table.Rows.Add("xx", "zzz");
     table.Rows.Add("walrus", "thingything");
     TableFormatter formatter = new TableFormatter('\0', '|', '\0', '\0', '\0', '+');
     Assert.AreEqual("------+-----------", formatter.GetRowSeparator(table, '-'));
     formatter = new TableFormatter('|', '|', '\0', '\0', '\0', '+');
     Assert.AreEqual("+------+-----------", formatter.GetRowSeparator(table, '-'));
     formatter = new TableFormatter('\0', '|', '|', '\0', '\0', '+');
     Assert.AreEqual("------+-----------+", formatter.GetRowSeparator(table, '-'));
     formatter = new TableFormatter('|', '|', '|', '\0', '\0', '+');
     Assert.AreEqual("+------+-----------+", formatter.GetRowSeparator(table, '-'));
 }