changed hex_metadata.config
 
@@ -11,4 +11,4 @@
11
11
{<<"links">>,[{<<"GitHub">>,<<"https://github.com/kellyfelkins/tabular">>}]}.
12
12
{<<"name">>,<<"tabular">>}.
13
13
{<<"requirements">>,[]}.
14
- {<<"version">>,<<"0.3.1">>}.
14
+ {<<"version">>,<<"0.3.2">>}.
changed lib/tabular/test_support.ex
 
@@ -1,4 +1,51 @@
1
1
defmodule Tabular.TestSupport do
2
+ @moduledoc """
3
+ Functions to simplify testing with ascii tables.
4
+
5
+ `compare/2` compares two ascii tables, producing a
6
+ matrix of the individual comparisons. `equal?/1`
7
+ examines the matrix generated by `compare/2` and
8
+ returns true if all cells are true and false
9
+ otherwise.
10
+ """
11
+
12
+ @doc ~S'''
13
+
14
+ Compares two ascii tables producing a matrix of
15
+ individual cell comparison results. Optional
16
+ comparator functions can be provided.
17
+
18
+ ## Examples
19
+
20
+ iex> table1 = """
21
+ ...> +---------+-------+
22
+ ...> | name | count |
23
+ ...> +---------+-------+
24
+ ...> | Malcolm | 10 |
25
+ ...> +---------+-------+
26
+ ...> | Zoe | 5 |
27
+ ...> +---------+-------+
28
+ ...> """
29
+ ...>
30
+ ...> table2 = """
31
+ ...> +---------+-------+
32
+ ...> | name | count |
33
+ ...> +---------+-------+
34
+ ...> | Mike | 11 |
35
+ ...> +---------+-------+
36
+ ...> | Zoe | 20 |
37
+ ...> +---------+-------+
38
+ ...> """
39
+ ...>
40
+ ...> comparators = %{"count" => &(abs(String.to_integer(&1) - String.to_integer(&2)) < 2)}
41
+ ...>
42
+ ...> Tabular.TestSupport.compare(table1, table2, comparators: comparators)
43
+ [
44
+ [false, true],
45
+ [true, false]
46
+ ]
47
+ '''
48
+
2
49
def compare(actual_table, expected_table, opts \\ [comparators: %{}]) do
3
50
actual_table_data = actual_table |> Tabular.to_list_of_lists()
4
51
expected_table_data = expected_table |> Tabular.to_list_of_lists()
 
@@ -18,6 +65,23 @@ defmodule Tabular.TestSupport do
18
65
end)
19
66
end
20
67
68
+ @doc ~S'''
69
+
70
+ Examines the matrix produced by `compare/2`. Returns false
71
+ if any cell is false. Otherwise returns true.
72
+
73
+ ## Examples
74
+
75
+ iex> results_table = [
76
+ ...> [true, true, true],
77
+ ...> [true, false, true],
78
+ ...> [true, true, true]
79
+ ...> ]
80
+ ...>
81
+ ...> Tabular.TestSupport.equal?(results_table)
82
+ false
83
+ '''
84
+
21
85
def equal?(compare_result) do
22
86
Enum.all?(compare_result, fn row ->
23
87
Enum.all?(row, & &1)
changed mix.exs
 
@@ -5,7 +5,7 @@ defmodule Tabular.MixProject do
5
5
[
6
6
app: :tabular,
7
7
description: description(),
8
- version: "0.3.1",
8
+ version: "0.3.2",
9
9
elixir: "~> 1.8",
10
10
deps: deps(),
11
11
name: "Tabular",