Skip to content

json_test.exs warns on matching 0.0 instead of +0.0 #31

Description

@DominicFinn

Problem

mix test in wick/ emits one compiler warning:

warning: pattern matching on 0.0 is equivalent to matching only on +0.0 from Erlang/OTP 27+.
Instead you must match on +0.0 or -0.0
└─ test/wick/json_test.exs: Wick.JsonTest."test decode/1 — primitives decodes floats
   including negative and exponent forms"/1

mix check runs mix compile --warnings-as-errors, but that compiles lib/, so the test
file's warning does not fail the build — it just sits there on every run. The repo is
otherwise warning-clean and credo --strict finds nothing across both libraries, so this is
the one blemish.

Fix

Change the pattern in test/wick/json_test.exs to +0.0 (or -0.0, whichever the case
intends — worth checking, since decoding "-0.0" should arguably yield -0.0 and that
distinction is exactly what the warning is about).

While there: it is worth asserting the sign explicitly, since +0.0 == -0.0 is true in
Elixir and assert decoded == 0.0 would pass either way. assert decoded === -0.0 is the
test that actually means something.

Good first issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersp3Nice to havepolishCode quality / idiom, not a missing feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions