From d68964f83fcc7311721686d5ba4af75645264999 Mon Sep 17 00:00:00 2001 From: Producer Matt <58014742+ProducerMatt@users.noreply.github.com> Date: Fri, 31 May 2024 19:09:35 -0500 Subject: [PATCH] format --- .formatter.exs | 7 ++- bench/str_split_regex.ex | 17 ++--- mix.exs | 1 - test/stampede_stateless_test.exs | 104 ++++++++++++++++--------------- 4 files changed, 71 insertions(+), 58 deletions(-) diff --git a/.formatter.exs b/.formatter.exs index d2cda26..6f9001c 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,4 +1,9 @@ # Used by "mix format" [ - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] + inputs: ["{mix,.formatter}.exs", "{config,lib,test,bench}/**/*.{ex,exs}"], + # don't add parens around assert_value arguments + import_deps: [:assert_value], + # use this line length when updating expected value + # whatever you prefer, default is 98 + line_length: 98 ] diff --git a/bench/str_split_regex.ex b/bench/str_split_regex.ex index 51bdcba..2e3f4b1 100644 --- a/bench/str_split_regex.ex +++ b/bench/str_split_regex.ex @@ -11,6 +11,7 @@ defmodule T do def plain_indent_io(str, prefix) when is_binary(prefix) do bp = :binary.compile_pattern("\n") + IO.iodata_to_binary(str) |> String.split(bp, trim: true) |> Enum.flat_map(&[prefix, &1, "\n"]) @@ -21,6 +22,7 @@ defmodule T do def plain_indent_bp_inline(str, prefix) when is_binary(prefix) do bp = :binary.compile_pattern("\n") + IO.iodata_to_binary(str) |> String.split(bp, trim: true) |> Enum.flat_map(&[prefix, &1, "\n"]) @@ -46,10 +48,13 @@ defmodule T do end r = S.text_chunk_regex(8) + inputs = %{ "no newlines, 4 chars" => String.duplicate("x", 4) |> S.text_chunk(8, false, r), - "16 newlines, 512 chars" => String.duplicate(String.duplicate("x", 31) <> "\n", 16) |> S.text_chunk(8, false, r), - "8 newlines, 1024 chars" => String.duplicate(String.duplicate("x", 127) <> "\n", 8) |> S.text_chunk(8, false, r), + "16 newlines, 512 chars" => + String.duplicate(String.duplicate("x", 31) <> "\n", 16) |> S.text_chunk(8, false, r), + "8 newlines, 1024 chars" => + String.duplicate(String.duplicate("x", 127) <> "\n", 8) |> S.text_chunk(8, false, r) } {:ok, r2} = :re.compile("\\n", [:multiline]) @@ -59,11 +64,9 @@ suites = %{ # "Split with String" => # # identical to :binary.split() # &T.plain_indent_io(&1, 2), - "Split with String compiled in function" => - &T.plain_indent_bp_inline(&1, 2), - "Split with String precompiled" => - &T.plain_indent_bp(&1, 2, bp), - #"Split with :re" => + "Split with String compiled in function" => &T.plain_indent_bp_inline(&1, 2), + "Split with String precompiled" => &T.plain_indent_bp(&1, 2, bp) + # "Split with :re" => # &T.plain_indent_re(&1, 2, r2) } diff --git a/mix.exs b/mix.exs index 79ecbd0..5bba430 100644 --- a/mix.exs +++ b/mix.exs @@ -78,7 +78,6 @@ defmodule Stampede.MixProject do # must be started before use, see test/test_helper.exs {:assert_value, "~> 0.10.4", only: [:test, :dev]}, - # RUNTIME TYPE CHECKING # https://hexdocs.pm/type_check/readme.html {:type_check, "~> 0.13.5"}, diff --git a/test/stampede_stateless_test.exs b/test/stampede_stateless_test.exs index b59496f..bf392a7 100644 --- a/test/stampede_stateless_test.exs +++ b/test/stampede_stateless_test.exs @@ -30,19 +30,19 @@ defmodule StampedeStatelessTest do describe "stateless functions" do test "split_prefix text" do - assert_value S.split_prefix("!ping", "!") == {"!", "ping"} - assert_value {false, "ping"} == S.split_prefix("ping", "!") + assert_value(S.split_prefix("!ping", "!") == {"!", "ping"}) + assert_value({false, "ping"} == S.split_prefix("ping", "!")) end test "SiteConfig.make_regex() test" do r_binary = "~r/[Ss]\(,\)? " [prefix: rex] = SiteConfig.make_regex([prefix: r_binary], nil) assert Regex.source(rex) == String.slice(r_binary, 3, String.length(r_binary) - 3) - assert_value S.split_prefix("S, ping", rex) == {"S, ", "ping"} - assert_value S.split_prefix("S ping", rex) == {"S ", "ping"} - assert_value S.split_prefix("s, ping", rex) == {"s, ", "ping"} - assert_value S.split_prefix("s,, ping", rex) == {false, "s,, ping"} - assert_value S.split_prefix("ping", rex) == {false, "ping"} + assert_value(S.split_prefix("S, ping", rex) == {"S, ", "ping"}) + assert_value(S.split_prefix("S ping", rex) == {"S ", "ping"}) + assert_value(S.split_prefix("s, ping", rex) == {"s, ", "ping"}) + assert_value(S.split_prefix("s,, ping", rex) == {false, "s,, ping"}) + assert_value(S.split_prefix("ping", rex) == {false, "ping"}) end test "Plugin.is_bot_invoked?" do @@ -338,36 +338,38 @@ defmodule StampedeStatelessTest do TxtBlock.Debugging.all_formats_example() |> TxtBlock.to_binary(Service.Dummy) - assert_value processed == """ - Testing formats. + assert_value( + processed == """ + Testing formats. - *Italicized* + *Italicized* - Quoted - > Quoted line 1 - > Quoted line 2 + Quoted + > Quoted line 1 + > Quoted line 2 - ``` - source(1) - source(2) - ``` + ``` + source(1) + source(2) + ``` - Inline source quote `foobar` + Inline source quote `foobar` - ><> school - ><> of - ><> fishies + ><> school + ><> of + ><> fishies - Dotted list - - Item 1 - - Item 2 - - Item 3 + Dotted list + - Item 1 + - Item 2 + - Item 3 - Numbered list - 1. Item 1 - 2. *Nested Italics Item 2* - 3. Item 3 - """ + Numbered list + 1. Item 1 + 2. *Nested Italics Item 2* + 3. Item 3 + """ + ) end end @@ -376,8 +378,10 @@ defmodule StampedeStatelessTest do tlist = [{Plugins.Test, {:job_ok, nil}}] - assert_value Plugin.resolve_responses(tlist) |> inspect(pretty: true) == - "%{r: nil, tb: vec([declined_to_answer: Plugins.Test])}" + assert_value( + Plugin.resolve_responses(tlist) |> inspect(pretty: true) == + "%{r: nil, tb: vec([declined_to_answer: Plugins.Test])}" + ) end test "default response" do @@ -398,23 +402,25 @@ defmodule StampedeStatelessTest do result = Plugin.resolve_responses(tlist) - assert_value Plugin.resolve_responses(tlist) |> inspect(pretty: true) == """ - %{ - r: %Stampede.ResponseToPost{ - confidence: 1, - text: {:italics, \"confused beeping\"}, - origin_plug: Plugins.Sentience, - origin_msg_id: 49, - why: [\"I didn't have any better ideas.\"], - callback: nil, - channel_lock: false - }, - tb: vec([ - response_was_chosen: {:replied_with_text, Plugins.Sentience, 1, - {:italics, \"confused beeping\"}, [\"I didn't have any better ideas.\"]} - ]) - } - """ + assert_value( + Plugin.resolve_responses(tlist) |> inspect(pretty: true) == """ + %{ + r: %Stampede.ResponseToPost{ + confidence: 1, + text: {:italics, \"confused beeping\"}, + origin_plug: Plugins.Sentience, + origin_msg_id: 49, + why: [\"I didn't have any better ideas.\"], + callback: nil, + channel_lock: false + }, + tb: vec([ + response_was_chosen: {:replied_with_text, Plugins.Sentience, 1, + {:italics, \"confused beeping\"}, [\"I didn't have any better ideas.\"]} + ]) + } + """ + ) end end end