Tabular v1.0.0 Tabular.TestSupport View Source

Functions to simplify testing with ascii tables.

compare/2 compares two ascii tables, producing a matrix of the individual comparisons. equal?/1 examines the matrix generated by compare/2 and returns true if all cells are true and false otherwise.

Link to this section Summary

Functions

Compares two ascii tables producing a matrix of individual cell comparison results. Optional comparator functions can be provided.

Examines the matrix produced by compare/2. Returns false if any cell is false. Otherwise returns true.

Link to this section Functions

Link to this function

assert_equal(results_table) View Source

Link to this function

compare(actual_table, expected_table, opts \\ [comparators: %{}]) View Source

Compares two ascii tables producing a matrix of individual cell comparison results. Optional comparator functions can be provided.

Examples

iex> table1 = """
...>   +---------+-------+
...>   | name    | count |
...>   +---------+-------+
...>   | Malcolm | 10    |
...>   +---------+-------+
...>   | Zoe     | 5     |
...>   +---------+-------+
...> """
...>
...> table2 = """
...>   +---------+-------+
...>   | name    | count |
...>   +---------+-------+
...>   | Mike    | 11    |
...>   +---------+-------+
...>   | Zoe     | 20    |
...>   +---------+-------+
...> """
...>
...> comparators = %{"count" => &(abs(String.to_integer(&1) - String.to_integer(&2)) < 2)}
...>
...> Tabular.TestSupport.compare(table1, table2, comparators: comparators)
[
  [false, true],
  [true, false]
]

Examines the matrix produced by compare/2. Returns false if any cell is false. Otherwise returns true.

Examples

iex> results_table = [
...>   [true, true, true],
...>   [true, false, true],
...>   [true, true, true]
...> ]
...>
...> Tabular.TestSupport.equal?(results_table)
false
Link to this function

format_cells(results_table) View Source

Link to this function

generate_error_message(list) View Source