Skip to content

Commit

Permalink
Prepare rel 1.4.40
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertDober committed Sep 12, 2023
1 parent 3fcc7e6 commit 73878e7
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 6 deletions.
15 changes: 12 additions & 3 deletions lib/earmark/cli/implementation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Earmark.Cli.Implementation do

def run(argv) do
argv
|> _parse_args()
|> parse_args()
|> _process()
end

Expand Down Expand Up @@ -79,21 +79,30 @@ defmodule Earmark.Cli.Implementation do
wikilinks
]

defp _parse_args(argv) do
@doc false
def parse_args(argv) do
switches = [
breaks: :boolean,
code_class_prefix: :string,
compact_output: :boolean,
eex: :boolean,
escape: :boolean,
footnotes: :boolean,
footnote_offset: :integer,
gfm: :boolean,
gfm_tables: :boolean,
help: :boolean,
inner_html: :boolean,
ignore_strings: :boolean,
line: :integer,
pedantic: :boolean,
pure_links: :boolean,
smartypants: :boolean,
sub_sup: :boolean,
template: :boolean,
timeout: :integer,
version: :boolean,
wikiklinks: :boolean
wikilinks: :boolean
]

aliases = [
Expand Down
1 change: 0 additions & 1 deletion lib/earmark/options.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ defmodule Earmark.Options do
"""

defstruct annotations: nil,
all: false,
breaks: false,
code_class_prefix: nil,
compact_output: false,
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


@deps [
# {:earmark_parser, "~> 1.4.34" },
{:earmark_parser, "~> 1.4.35", path: "../earmark_parser"},
{:earmark_parser, "~> 1.4.35" },
# {:earmark_parser, "~> 1.4.35", path: "../earmark_parser"},
{:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false},
{:benchfella, "~> 0.3.0", only: [:dev]},
{:earmark_ast_dsl, "~> 0.3.6", only: [:dev, :test]},
Expand Down
86 changes: 86 additions & 0 deletions test/lib/cli/options_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
defmodule Test.Cli.OptionsTest do
use ExUnit.Case

alias Earmark.Options
import Earmark.Cli.Implementation, only: [parse_args: 1]

describe "boolean args" do
[
compact_output: false,
breaks: false,
eex: false,
escape: true,
footnotes: false,
gfm: true,
gfm_tables: false,
ignore_strings: false,
inner_html: false,
pedantic: false,
pure_links: true,
smartypants: true,
sub_sup: false,
template: false,
wikilinks: false
]
|> Enum.each(fn {arg, default} ->
empty_test_name = "boolean #{arg}, default: #{default}. No args"

test empty_test_name do
assert parse_args([]) |> Map.get(unquote(arg)) == unquote(default)
end

expl_test_name = "boolean #{arg} set "

test expl_test_name do
assert parse_args(["--#{mk_arg(unquote(arg))}", "a_file"]) |> Map.get(unquote(arg)) ==
true
end

nega_test_name = "boolean #{arg} unset "

test nega_test_name do
assert parse_args(["--no-#{mk_arg(unquote(arg))}", "a_file"]) |> Map.get(unquote(arg)) ==
false
end
end)
end

describe "value args" do
[
{:footnote_offset, 1, 41},
{:line, 1, 42},
{:timeout, nil, 2_000}
]
|> Enum.each(fn {arg, default, value} ->
empty_test_name = "value #{arg}, default: #{default}. No args"

test empty_test_name do
assert parse_args([]) |> Map.get(unquote(arg)) == unquote(default)
end

value_test_name = "value #{arg}, explicit value #{value}"
test value_test_name do
assert parse_args(["--#{mk_arg(unquote(arg))}=#{to_string(unquote(value))}", "a_file"]) |> Map.get(unquote(arg)) ==
unquote(value)
end
end)

defp mk_arg(arg) do
arg
|> to_string
|> String.replace("_", "-")
end

# test "default, smarty pants" do
# %Options{smartypants: true} = parse_args([])
# end
# test "can be set explicitly" do
# assert parse_args(~w[--smartypants some_file]).smartypants
# end
# test "can be unset explicitly" do
# refute parse_args(~w[--no-smartypants some_file]).smartypants
# end
end
end

# SPDX-License-Identifier: Apache-2.0

0 comments on commit 73878e7

Please sign in to comment.