Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lue-bird committed Jul 21, 2023
1 parent 2ee1d6e commit 1998e5e
Showing 1 changed file with 88 additions and 16 deletions.
104 changes: 88 additions & 16 deletions tests/EqualsCaseableTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,79 @@ a =
"a and or b is filled"
"""
]
, test "should report if /= [] || /= []" <|
\() ->
"""module A exposing (..)
a =
if aList /= [] || bList /= [] then
"a and or b is filled"
else
"empty"
"""
|> Review.Test.run (forbid EqualsCaseable.Everywhere)
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "equivalent `case of` exists"
, details =
[ "You are checking for equality against a value that could be a pattern in an equivalent `case of`!"
, "You can replace this check with a `case of` where you use the value you're matching for as a pattern."
, "This can aid structuring your code in a way where the compiler knows as much about the current branch as you. Read more in the readme: https://dark.elm.dmy.fr/packages/lue-bird/elm-review-equals-caseable/latest/"
]
, under = "aList /= [] || bList /= []"
}
|> Review.Test.whenFixed
"""module A exposing (..)
a =
case ( aList, bList ) of
( [], [] ) ->
"empty"
_ ->
"a and or b is filled"
"""
]
, test "should report if /= [] && /= []" <|
\() ->
"""module A exposing (..)
a =
if aList /= [] && bList /= [] then
"filled"
else
"a and b is empty"
"""
|> Review.Test.run (forbid EqualsCaseable.Everywhere)
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "equivalent `case of` exists"
, details =
[ "You are checking for equality against a value that could be a pattern in an equivalent `case of`!"
, "You can replace this check with a `case of` where you use the value you're matching for as a pattern."
, "This can aid structuring your code in a way where the compiler knows as much about the current branch as you. Read more in the readme: https://dark.elm.dmy.fr/packages/lue-bird/elm-review-equals-caseable/latest/"
, """Note: Since your condition isn't as simple as `(a == A) && (b == B) && ...` or `(a /= A) || (b /= B) || ...`, fixing isn't automatic. An example:
if a == 'a' || b == 'b' then
aAOrBB
else
notAAOrNotBB
as a case of:
case ( a, b ) of
( A, _ ) ->
aaOrBB
( _, B ) ->
aaOrBB
( _, _ ) ->
notAAOrNotBB
"""
]
, under = "aList /= []"
}
]
, test "should report if == [] || == []" <|
\() ->
"""module A exposing (..)
Expand All @@ -181,7 +254,7 @@ a =
[ "You are checking for equality against a value that could be a pattern in an equivalent `case of`!"
, "You can replace this check with a `case of` where you use the value you're matching for as a pattern."
, "This can aid structuring your code in a way where the compiler knows as much about the current branch as you. Read more in the readme: https://dark.elm.dmy.fr/packages/lue-bird/elm-review-equals-caseable/latest/"
, """Note: Since your condition isn't as simple as `(a == A) && (b == B) && ...`, fixing isn't automatic. You will need more than 2 cases. An example:
, """Note: Since your condition isn't as simple as `(a == A) && (b == B) && ...` or `(a /= A) || (b /= B) || ...`, fixing isn't automatic. An example:
if a == 'a' || b == 'b' then
aAOrBB
Expand Down Expand Up @@ -222,28 +295,27 @@ a =
[ "You are checking for equality against a value that could be a pattern in an equivalent `case of`!"
, "You can replace this check with a `case of` where you use the value you're matching for as a pattern."
, "This can aid structuring your code in a way where the compiler knows as much about the current branch as you. Read more in the readme: https://dark.elm.dmy.fr/packages/lue-bird/elm-review-equals-caseable/latest/"
, """Note: Since your condition uses both /= and ==, fixing isn't automatic. You will need more than 2 cases. An example:
, """Note: Since your condition isn't as simple as `(a == A) && (b == B) && ...` or `(a /= A) || (b /= B) || ...`, fixing isn't automatic. An example:
if a == 'a' && b /= 'b' then
aANotBB
if a == 'a' || b == 'b' then
aAOrBB
else
maybeBBOrNotAA
notAAOrNotBB
as a case of:
case a of
'a' ->
case b of
'b' ->
maybeBBOrNotAA
_ ->
aANotBB
_ ->
maybeBBOrNotAA
case ( a, b ) of
( A, _ ) ->
aaOrBB
( _, B ) ->
aaOrBB
( _, _ ) ->
notAAOrNotBB
"""
]
, under = "aList == [] && bList /= []"
, under = "aList == []"
}
]
, test "should report if == [] and keep indentation" <|
Expand Down

0 comments on commit 1998e5e

Please sign in to comment.