dkuku
Am I the only one who can't spot the difference in map keys
This is a proposal to make the map key mismatch errors a bit better:
Every time I have a typo It’s very challenging for me even when I understand the error:
I see this in many places - it’s the same in test results. There may be a bit easier because the colors but because the order of keys sometimes changes and the maps are often huge I need to scroll the screen multiple times.
I even changed the test formatter to show only the lines that have ansi sequences but I work on different projects and the formatter needs to be always installed. Similar with errors thrown by dialyzer or hammox.
Most Liked
cevado
but you don’t need to refactor everything at once, next time a test breaks, refactor that specific test. spread the word at the company, so they stop doing the old way and more people help to do the refactor… one day it all gonna be done. ![]()
cevado
both clauses expect a :amount key that is not present in the map that is passed as argument.
edit: not sure if your question is about the error or a better way to format this.
in the way you’re using it, it would be better to have a struct or at least use the dot notation to extract the values instead of pattern matching them on function clause:
def build(something) do
created_at = something.created_at
...
end
sodapopcan
LostKobrakai
Yeah, should be doable with sourceror, given the following plain elixir poc:
"""
defmodule MyApp.Test do
test "abc" do
y = 15
assert %{a: ^y, b: 8} = call()
end
end
"""
|> Code.string_to_quoted!(
literal_encoder: &{:ok, {:__block__, &2, [&1]}},
token_metadata: true,
unescape: false
)
|> Macro.postwalk(fn
{:assert, assert_meta, [{:=, assign_meta, [{:%{}, _, pairs}, call]}]} ->
checks =
Enum.map(pairs, fn {{:__block__, _meta, [key]}, value} ->
quote do
assert unquote(value) = response.unquote(key)
end
end)
{:__block__, [],
[
{:assert, assert_meta, [{:=, assign_meta, [Macro.var(:response, nil), call]}]} | checks
]}
other ->
other
end)
|> Code.quoted_to_algebra(
literal_encoder: &{:ok, {:__block__, &2, [&1]}},
token_metadata: true,
unescape: false
)
|> Inspect.Algebra.format(:infinity)
|> IO.iodata_to_binary()
|> IO.puts()
# defmodule MyApp.Test do
# test "abc" do
# y = 15
# (assert response = call()
# assert ^y = response.a
# assert 8 = response.b)
# end
# end
Not sure how to best get rid of the parenthesis for the block there though.









