Skip to content

Commit 89d9cc8

Browse files
author
José Valim
committed
Ensure IO.ANSI.Docs can correctly fill missing columns
1 parent 7b0cbb1 commit 89d9cc8

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lib/elixir/lib/io/ansi/docs.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ defmodule IO.ANSI.Docs do
277277
end
278278

279279
defp pad_to_number_of_columns(cols, col_count),
280-
do: cols ++ List.duplicate("", col_count - length(cols))
280+
do: cols ++ List.duplicate({"", 0}, col_count - length(cols))
281281

282282
defp max_column_widths(cols, widths),
283283
do: Enum.zip(cols, widths) |> Enum.map(fn {a,b} -> max(a,b) end)

lib/elixir/test/elixir/io/ansi/docs_test.exs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,27 +218,32 @@ defmodule IO.ANSI.DocsTest do
218218
end
219219

220220
test "lone thing that looks like a table line isn't" do
221-
result = format("one\n2 | 3\ntwo\n")
222-
assert result == "one 2 | 3 two\n\e[0m"
221+
assert format("one\n2 | 3\ntwo\n") ==
222+
"one 2 | 3 two\n\e[0m"
223223
end
224224

225225
test "lone table line at end of input isn't" do
226-
result = format("one\n2 | 3")
227-
assert result == "one 2 | 3\n\e[0m"
226+
assert format("one\n2 | 3") ==
227+
"one 2 | 3\n\e[0m"
228228
end
229229

230230
test "two successive table lines are a table" do
231-
result = format("a | b\none | two\n")
232-
assert result == "a | b \none | two\n\e[0m" # note spacing
231+
assert format("a | b\none | two\n") ==
232+
"a | b \none | two\n\e[0m" # note spacing
233233
end
234234

235235
test "table with heading" do
236-
result = format("column 1 | and 2\n-- | --\na | b\none | two\n")
237-
assert result == "\e[7mcolumn 1 | and 2\e[0m\na | b \none | two \n\e[0m"
236+
assert format("column 1 | and 2\n-- | --\na | b\none | two\n") ==
237+
"\e[7mcolumn 1 | and 2\e[0m\na | b \none | two \n\e[0m"
238238
end
239239

240-
test "formatting in a table cell works" do
241-
result = format("`a` | _b_\nc | d")
242-
assert result == "\e[36ma\e[0m | \e[4mb\e[0m\nc | d\n\e[0m"
240+
test "table with formatting in cells" do
241+
assert format("`a` | _b_\nc | d") ==
242+
"\e[36ma\e[0m | \e[4mb\e[0m\nc | d\n\e[0m"
243+
end
244+
245+
test "table with variable number of columns" do
246+
assert format("a | b | c\nd | e") ==
247+
"a | b | c\nd | e | \n\e[0m"
243248
end
244249
end

0 commit comments

Comments
 (0)