2019-06-16 16:31:40 +03:00
|
|
|
module NoExtraBooleanComparisonTest exposing (all)
|
|
|
|
|
2019-09-29 00:47:02 +03:00
|
|
|
import Review.Rule.NoExtraBooleanComparison exposing (rule)
|
|
|
|
import Review.Test exposing (ReviewResult)
|
2019-06-26 14:47:00 +03:00
|
|
|
import Test exposing (Test, describe, test)
|
2019-06-16 16:31:40 +03:00
|
|
|
|
|
|
|
|
2019-09-29 00:47:02 +03:00
|
|
|
testRule : String -> ReviewResult
|
2019-06-16 16:31:40 +03:00
|
|
|
testRule string =
|
|
|
|
"module A exposing (..)\n\n"
|
|
|
|
++ string
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.run rule
|
2019-06-16 16:31:40 +03:00
|
|
|
|
|
|
|
|
|
|
|
tests : List Test
|
|
|
|
tests =
|
|
|
|
[ test "should not report condition without an operator" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if n then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectNoErrors
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should not report condition with integer operators" <|
|
|
|
|
\() ->
|
|
|
|
testRule """
|
|
|
|
a = if n < 1 then 1 else 2
|
|
|
|
b = if n <= 1 then 1 else 2
|
|
|
|
c = if n > 1 then 1 else 2
|
|
|
|
d = if n >= 1 then 1 else 2
|
|
|
|
"""
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectNoErrors
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should not report condition using `not`" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if not n then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectNoErrors
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should report condition with `expr == True`" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if b == True then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectErrors
|
|
|
|
[ Review.Test.error
|
2019-06-30 12:53:49 +03:00
|
|
|
{ message = "Unnecessary comparison with `True`"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = [ "You can simplify this expression by removing the `==` operator and the value `True`." ]
|
2019-06-30 12:56:28 +03:00
|
|
|
, under = "b == True"
|
2019-06-30 12:53:49 +03:00
|
|
|
}
|
|
|
|
]
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should report condition with `True == expr`" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if True == b then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectErrors
|
|
|
|
[ Review.Test.error
|
2019-06-30 12:53:49 +03:00
|
|
|
{ message = "Unnecessary comparison with `True`"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = [ "You can simplify this expression by removing the `==` operator and the value `True`." ]
|
2019-06-30 12:56:28 +03:00
|
|
|
, under = "True == b"
|
2019-06-30 12:53:49 +03:00
|
|
|
}
|
|
|
|
]
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should report condition with `expr == False`" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if b == False then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectErrors
|
|
|
|
[ Review.Test.error
|
2019-06-30 12:53:49 +03:00
|
|
|
{ message = "Unnecessary comparison with `False`"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = [ "You can simplify this expression by removing the `==` operator and the value `False`." ]
|
2019-06-30 12:56:28 +03:00
|
|
|
, under = "b == False"
|
2019-06-30 12:53:49 +03:00
|
|
|
}
|
|
|
|
]
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should report condition with `False == expr`" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if False == b then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectErrors
|
|
|
|
[ Review.Test.error
|
2019-06-30 12:53:49 +03:00
|
|
|
{ message = "Unnecessary comparison with `False`"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = [ "You can simplify this expression by removing the `==` operator and the value `False`." ]
|
2019-06-30 12:56:28 +03:00
|
|
|
, under = "False == b"
|
2019-06-30 12:53:49 +03:00
|
|
|
}
|
|
|
|
]
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should report condition with `expr /= True`" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if b /= True then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectErrors
|
|
|
|
[ Review.Test.error
|
2019-06-30 12:53:49 +03:00
|
|
|
{ message = "Unnecessary comparison with `True`"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = [ "You can simplify this expression by removing the `/=` operator and the value `True`." ]
|
2019-06-30 12:56:28 +03:00
|
|
|
, under = "b /= True"
|
2019-06-30 12:53:49 +03:00
|
|
|
}
|
|
|
|
]
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should report condition with `True /= expr`" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if True /= b then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectErrors
|
|
|
|
[ Review.Test.error
|
2019-06-30 12:53:49 +03:00
|
|
|
{ message = "Unnecessary comparison with `True`"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = [ "You can simplify this expression by removing the `/=` operator and the value `True`." ]
|
2019-06-30 12:56:28 +03:00
|
|
|
, under = "True /= b"
|
2019-06-30 12:53:49 +03:00
|
|
|
}
|
|
|
|
]
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should report condition with `expr /= False`" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if b /= False then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectErrors
|
|
|
|
[ Review.Test.error
|
2019-06-30 12:53:49 +03:00
|
|
|
{ message = "Unnecessary comparison with `False`"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = [ "You can simplify this expression by removing the `/=` operator and the value `False`." ]
|
2019-06-30 12:56:28 +03:00
|
|
|
, under = "b /= False"
|
2019-06-30 12:53:49 +03:00
|
|
|
}
|
|
|
|
]
|
2019-06-16 16:31:40 +03:00
|
|
|
, test "should report condition with `False /= expr`" <|
|
|
|
|
\() ->
|
|
|
|
testRule "a = if False /= b then 1 else 2"
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.expectErrors
|
|
|
|
[ Review.Test.error
|
2019-06-30 12:53:49 +03:00
|
|
|
{ message = "Unnecessary comparison with `False`"
|
2019-07-28 01:16:57 +03:00
|
|
|
, details = [ "You can simplify this expression by removing the `/=` operator and the value `False`." ]
|
2019-06-30 12:56:28 +03:00
|
|
|
, under = "False /= b"
|
2019-06-30 12:53:49 +03:00
|
|
|
}
|
|
|
|
]
|
2019-06-16 16:31:40 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
all : Test
|
|
|
|
all =
|
|
|
|
describe "NoExtraBooleanComparison" tests
|