Skip to content

Commit

Permalink
Support comments and Obsidian markdown table format (#16)
Browse files Browse the repository at this point in the history
Fixes #15

Obsidian formats markdown tables with a space between the `|`
characters. Also comments are very helpful when debugging or to provide
additional detail to the table.
  • Loading branch information
axelson authored Jul 22, 2024
1 parent 83f60d0 commit 07fb89d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/parameterized_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ defmodule ParameterizedTest do
|> Enum.map(&String.to_atom/1)

rows
|> Enum.reject(&separator_row?/1)
|> Enum.reject(&separator_or_comment_row?/1)
|> Enum.map(fn row ->
cells =
row
Expand Down Expand Up @@ -284,9 +284,11 @@ defmodule ParameterizedTest do
end

# A regex to match rows consisting of pipes separated by hyphens, like |------|-----|
@separator_regex ~r/^\|(-+\|)+$/
@separator_regex ~r/^\|( ?-+ ?\|)+$/

defp separator_row?(row) do
defp separator_or_comment_row?("#" <> _), do: true

defp separator_or_comment_row?(row) do
Regex.match?(@separator_regex, row)
end

Expand Down
34 changes: 34 additions & 0 deletions test/parameterized_test_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,40 @@ defmodule ParameterizedTestTest do
assert free_shipping? == gets_free_shipping?
end

param_test "ignores commented lines",
"""
| spending_by_category | coupon | gets_free_shipping? |
|-------------------------------|-------------|---------------------|
# Temporarily disable
#| %{shoes: 19_99, pants: 29_99} | | false |
| %{shoes: 59_99, pants: 49_99} | | true |
""",
%{
spending_by_category: spending_by_category,
coupon: coupon,
gets_free_shipping?: gets_free_shipping?
} do
shipping_cost = ExampleShippingCalculator.calculate_shipping(spending_by_category, coupon)
free_shipping? = shipping_cost == 0
assert free_shipping? == gets_free_shipping?
end

param_test "supports obsidian-flavored markdown table separator rows",
"""
| spending_by_category | coupon | gets_free_shipping? |
| ----------------------------- | ----------- | ------------------- |
| %{shoes: 59_99, pants: 49_99} | | true |
""",
%{
spending_by_category: spending_by_category,
coupon: coupon,
gets_free_shipping?: gets_free_shipping?
} do
shipping_cost = ExampleShippingCalculator.calculate_shipping(spending_by_category, coupon)
free_shipping? = shipping_cost == 0
assert free_shipping? == gets_free_shipping?
end

param_test "supports Markdown files as input",
"test/fixtures/params.md",
%{
Expand Down

0 comments on commit 07fb89d

Please sign in to comment.