elm-review/tests/NoUnusedTypeConstructorsTest.elm

83 lines
2.7 KiB
Elm
Raw Normal View History

2019-07-05 00:57:55 +03:00
module NoUnusedTypeConstructorsTest exposing (all)
import Review.Rule.NoUnusedTypeConstructors exposing (rule)
import Review.Test exposing (ReviewResult)
2019-07-05 00:57:55 +03:00
import Test exposing (Test, describe, test)
testRule : String -> ReviewResult
2019-07-05 00:57:55 +03:00
testRule =
Review.Test.run rule
2019-07-05 00:57:55 +03:00
2019-07-28 01:16:57 +03:00
details : List String
details =
[ "Since it is not being used, I recommend removing it. It should make the code clearer to read for other people."
]
2019-07-05 00:57:55 +03:00
tests : List Test
tests =
[ test "should not report non-exposed variables" <|
\() ->
testRule """module A exposing (b)
a = 1"""
|> Review.Test.expectNoErrors
2019-07-05 00:57:55 +03:00
, test "should not report used type constructors" <|
\() ->
testRule """module A exposing (b)
type Foo = Bar | Baz
a = Bar
b = Baz"""
|> Review.Test.expectNoErrors
2019-07-05 00:57:55 +03:00
, test "should not report unused type constructors when module is exposing all" <|
\() ->
testRule """module A exposing (..)
type Foo = Bar | Baz
"""
|> Review.Test.expectNoErrors
2019-07-05 00:57:55 +03:00
, test "should not report unused type constructors when module is exposing the constructors of that type" <|
\() ->
testRule """module A exposing (Foo(..))
type Foo = Bar | Baz
"""
|> Review.Test.expectNoErrors
2019-07-05 00:57:55 +03:00
, test "should report unused type constructors" <|
\() ->
testRule """module A exposing (b)
type Foo = Bar | Baz"""
|> Review.Test.expectErrors
[ Review.Test.error
2019-07-05 00:57:55 +03:00
{ message = "Type constructor `Bar` is not used."
2019-07-28 01:16:57 +03:00
, details = details
2019-07-05 00:57:55 +03:00
, under = "Bar"
}
, Review.Test.error
2019-07-05 00:57:55 +03:00
{ message = "Type constructor `Baz` is not used."
2019-07-28 01:16:57 +03:00
, details = details
2019-07-05 00:57:55 +03:00
, under = "Baz"
}
]
, test "should report unused type constructors, even if the type is exposed" <|
\() ->
testRule """module A exposing (Foo)
type Foo = Bar | Baz"""
|> Review.Test.expectErrors
[ Review.Test.error
2019-07-05 00:57:55 +03:00
{ message = "Type constructor `Bar` is not used."
2019-07-28 01:16:57 +03:00
, details = details
2019-07-05 00:57:55 +03:00
, under = "Bar"
}
, Review.Test.error
2019-07-05 00:57:55 +03:00
{ message = "Type constructor `Baz` is not used."
2019-07-28 01:16:57 +03:00
, details = details
2019-07-05 00:57:55 +03:00
, under = "Baz"
}
]
]
all : Test
all =
describe "NoUnusedTypeConstructors" tests