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 0edc76d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 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
2 changes: 1 addition & 1 deletion test/stampede_stateless_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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", "!") == {false, "ping"}
end

test "SiteConfig.make_regex() test" do
Expand Down

0 comments on commit 0edc76d

Please sign in to comment.