Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ProducerMatt committed Jun 1, 2024
1 parent ca02ba7 commit d68964f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 58 deletions.
7 changes: 6 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -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
]
17 changes: 10 additions & 7 deletions bench/str_split_regex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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"])
Expand All @@ -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])
Expand All @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
104 changes: 55 additions & 49 deletions test/stampede_stateless_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -398,23 +402,25 @@ defmodule StampedeStatelessTest do

result = Plugin.resolve_responses(tlist)

Check warning on line 403 in test/stampede_stateless_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

variable "result" is unused (if the variable is not meant to be used, prefix it with an underscore)

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.\"]}
])
}<NOEOL>
"""
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.\"]}
])
}<NOEOL>
"""
)
end
end
end

0 comments on commit d68964f

Please sign in to comment.