From 07fb89d4b8cbb4ee10f27662d5db2244c823608c Mon Sep 17 00:00:00 2001 From: Jason Axelson Date: Mon, 22 Jul 2024 08:33:23 -0500 Subject: [PATCH] Support comments and Obsidian markdown table format (#16) 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. --- lib/parameterized_test.ex | 8 +++++--- test/parameterized_test_test.exs | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/parameterized_test.ex b/lib/parameterized_test.ex index 5b6ea0d..365e4b6 100644 --- a/lib/parameterized_test.ex +++ b/lib/parameterized_test.ex @@ -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 @@ -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 diff --git a/test/parameterized_test_test.exs b/test/parameterized_test_test.exs index ba38122..3acbeb6 100644 --- a/test/parameterized_test_test.exs +++ b/test/parameterized_test_test.exs @@ -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", %{