From 73878e74bed76e4d89b19bd04f8e78839d536907 Mon Sep 17 00:00:00 2001 From: Robert Dober Date: Tue, 12 Sep 2023 20:31:49 +0200 Subject: [PATCH] Prepare rel 1.4.40 --- lib/earmark/cli/implementation.ex | 15 ++++-- lib/earmark/options.ex | 1 - mix.exs | 4 +- test/lib/cli/options_test.exs | 86 +++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 test/lib/cli/options_test.exs diff --git a/lib/earmark/cli/implementation.ex b/lib/earmark/cli/implementation.ex index 6d0ca7e5..36fe79d7 100644 --- a/lib/earmark/cli/implementation.ex +++ b/lib/earmark/cli/implementation.ex @@ -39,7 +39,7 @@ defmodule Earmark.Cli.Implementation do def run(argv) do argv - |> _parse_args() + |> parse_args() |> _process() end @@ -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 = [ diff --git a/lib/earmark/options.ex b/lib/earmark/options.ex index 28d9b6eb..99ff5b21 100644 --- a/lib/earmark/options.ex +++ b/lib/earmark/options.ex @@ -18,7 +18,6 @@ defmodule Earmark.Options do """ defstruct annotations: nil, - all: false, breaks: false, code_class_prefix: nil, compact_output: false, diff --git a/mix.exs b/mix.exs index e5de0488..73ceb1be 100644 --- a/mix.exs +++ b/mix.exs @@ -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]}, diff --git a/test/lib/cli/options_test.exs b/test/lib/cli/options_test.exs new file mode 100644 index 00000000..da9096a7 --- /dev/null +++ b/test/lib/cli/options_test.exs @@ -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