elm-review/tests/NoMissingTypeAnnotationTest.elm

64 lines
2.2 KiB
Elm
Raw Normal View History

2020-04-08 01:14:03 +03:00
module NoMissingTypeAnnotationTest exposing (all)
import NoMissingTypeAnnotation exposing (rule)
import Review.Test
2020-04-08 19:36:56 +03:00
import Test exposing (Test, describe, test)
2020-04-08 01:14:03 +03:00
details : List String
details =
[ "Type annotations help you understand what happens in the code, and it will help the compiler give better error messages."
]
all : Test
all =
describe "NoMissingTypeAnnotation"
2020-04-21 00:11:02 +03:00
[ test "should not report anything when all top-level declarations have a type annotation" <|
2020-04-08 01:14:03 +03:00
\_ ->
"""module A exposing (..)
hasTypeAnnotation : Int
hasTypeAnnotation = 1
alsoHasTypeAnnotation : String -> List Things
alsoHasTypeAnnotation = doSomething
"""
|> Review.Test.run rule
|> Review.Test.expectNoErrors
, test "should report when a declaration named `all...` that is of type `List <CustomTypeName>` does not have all the type constructors in its value (1)" <|
\_ ->
"""module A exposing (..)
hasNoTypeAnnotation = 1
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Missing type annotation for `hasNoTypeAnnotation`"
, details = details
, under = "hasNoTypeAnnotation"
}
]
, test "should not report anything for custom type declarations" <|
\_ ->
"""module A exposing (..)
type A = B | C
"""
|> Review.Test.run rule
|> Review.Test.expectNoErrors
, test "should not report anything for type alias declarations" <|
\_ ->
"""module A exposing (..)
type alias A = { a : String }
"""
|> Review.Test.run rule
|> Review.Test.expectNoErrors
, test "should not report anything for port declarations" <|
\_ ->
"""module A exposing (..)
port toJavaScript : Int -> Cmd msg
port fromJavaScript : (Int -> msg) -> Sub msg
"""
|> Review.Test.run rule
|> Review.Test.expectNoErrors
]