diff --git a/lib/csv.ex b/lib/csv.ex index e07b9f1..a56540b 100644 --- a/lib/csv.ex +++ b/lib/csv.ex @@ -152,8 +152,10 @@ defmodule CSV do | {:validate_row_length, boolean()} | {:escape_character, char()} | {:escape_max_lines, integer()} + | ({:redact_errors, boolean()} + | {:unredact_exceptions, boolean()}) - @spec decode(Enumerable.t(), [decode_options() | {:redact_errors, boolean()}]) :: Enumerable.t() + @spec decode(Enumerable.t(), [decode_options()]) :: Enumerable.t() def decode(stream, options \\ []) do stream |> Decoder.decode(options) |> inline_errors!(options) end @@ -288,8 +290,7 @@ defmodule CSV do """ - @spec decode!(Enumerable.t(), [decode_options() | {:unredact_exceptions, boolean()}]) :: - Enumerable.t() + @spec decode!(Enumerable.t(), [decode_options()]) :: Enumerable.t() def decode!(stream, options \\ []) do stream |> Decoder.decode(options) |> raise_errors!(options) end diff --git a/test/dialyzer/decode_typespectest.ex b/test/dialyzer/decode_typespectest.ex index df39f2e..e2a823c 100644 --- a/test/dialyzer/decode_typespectest.ex +++ b/test/dialyzer/decode_typespectest.ex @@ -1,6 +1,10 @@ defmodule DecodeTypespectest do @moduledoc "Test decoding typespecs" + def test_decode_no_options do + ["dummy,input"] |> CSV.decode() |> Enum.to_list() + end + def test_decode_option_escape_character do ["dummy,input"] |> CSV.decode(escape_character: ?.) |> Enum.to_list() end @@ -32,4 +36,28 @@ defmodule DecodeTypespectest do def test_decode_option_headers_atom_list do ["dummy,input"] |> CSV.decode(headers: [:a, :b]) |> Enum.to_list() end + + def test_decode_combined do + ["dummy,input"] |> CSV.decode(headers: [:a, :b], separator: ?,, validate_row_length: true) |> Enum.to_list() + end + + def test_decode_option_combine_with_redact_errors do + ["dummy,input"] |> CSV.decode(headers: [:a, :b], redact_errors: false) |> Enum.to_list() + end + + def test_decode_strict_no_options do + ["dummy,input"] |> CSV.decode!() |> Enum.to_list() + end + + def test_decode_strict_headers do + ["dummy,input"] |> CSV.decode!(headers: [:a, :b]) |> Enum.to_list() + end + + def test_decode_strict_combined do + ["dummy,input"] |> CSV.decode!(headers: [:a, :b], separator: ?,, validate_row_length: true) |> Enum.to_list() + end + + def test_decode_strict_option_combine_with_unredact_exceptions do + ["dummy,input"] |> CSV.decode!(headers: [:a, :b], unredact_exceptions: true) |> Enum.to_list() + end end