Skip to content

Commit 5c43dc9

Browse files
committed
Fix to accepting unquoted strings
1 parent a3edb3d commit 5c43dc9

4 files changed

Lines changed: 26 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.3.1
4+
5+
Bug fix to accept more unquoted strings, including those that have Elixir delimiters in them like quotes, parentheses, etc.
6+
37
## v0.3.0
48

59
### New features

lib/parameterized_test.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ defmodule ParameterizedTest do
260260
end
261261

262262
defp eval_cell(cell, row, _context) do
263-
case Code.eval_string(cell) do
263+
case Code.eval_string(cell, [], log: false) do
264264
{val, []} -> val
265265
_ -> raise "Failed to evaluate example cell `#{cell}` in row `#{row}`}"
266266
end
267267
rescue
268-
_e in [SyntaxError, CompileError] ->
268+
_e in [SyntaxError, CompileError, TokenMissingError] ->
269269
String.trim(cell)
270270

271271
e ->

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule ParameterizedTest.MixProject do
66
def project do
77
[
88
app: :parameterized_test,
9-
version: "0.3.0",
9+
version: "0.3.1",
1010
elixir: "~> 1.14",
1111
elixirc_paths: elixirc_paths(Mix.env()),
1212
start_permanent: Mix.env() == :prod,

test/parameterized_test_test.exs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,30 @@ defmodule ParameterizedTestTest do
155155

156156
param_test "interprets otherwise unparseable values as strings",
157157
"""
158-
| value | unquoted string key |
159-
|---------|---------------------|
160-
| 1 | foo, bar |
161-
| 2 3 4 | |
158+
| value | unquoted string key |
159+
|---------|------------------------------|
160+
| 1 | foo, bar & baz |
161+
| 2 3 4 | |
162+
| 5 | Won't error out |
163+
| 6 | a !@#$%^&*():"_;',./][}{<> z |
164+
| 7 | %{shoes: 19_99, |
162165
""",
163166
%{value: value, "unquoted string key": unquoted} do
164167
case value do
165168
1 ->
166-
assert unquoted == "foo, bar"
169+
assert unquoted == "foo, bar & baz"
167170

168171
"2 3 4" ->
169172
assert is_nil(unquoted)
173+
174+
5 ->
175+
assert unquoted == "Won't error out"
176+
177+
6 ->
178+
assert unquoted == "a !@#$%^&*():\"_;',./][}{<> z"
179+
180+
7 ->
181+
assert unquoted == "%{shoes: 19_99,"
170182
end
171183
end
172184

@@ -298,28 +310,10 @@ defmodule ParameterizedTestTest do
298310
end
299311
end
300312

301-
test "fails to compile Markdown rows with invalid Elixir in them" do
302-
assert_raise RuntimeError, fn ->
303-
defmodule FailToEvaluateBadMarkdownTest do
304-
use ExUnit.Case, async: true
305-
306-
import ParameterizedTest
307-
308-
param_test "test with invalid Elixir in a cell",
309-
"""
310-
| spending_by_category |
311-
| %{shoes: 19_99, |
312-
""",
313-
%{gets_free_shipping?: gets_free_shipping?} do
314-
assert gets_free_shipping?
315-
end
316-
end
317-
end
318-
end
319-
320313
test "fails to compile when the keys in a handrolled list don't all match" do
321314
assert_raise RuntimeError, fn ->
322-
defmodule FailToEvaluateBadMarkdownTest do
315+
defmodule FailToEvaluateMismatchedKeys do
316+
@moduledoc false
323317
use ExUnit.Case, async: true
324318

325319
import ParameterizedTest

0 commit comments

Comments
 (0)