elm-review/tests/NoUnannotatedFunctionTest.elm
2018-11-05 15:40:41 +01:00

76 lines
2.1 KiB
Elm

module NoUnannotatedFunctionTest exposing (all)
import Lint.Rules.NoUnannotatedFunction exposing (rule)
import Lint.Types exposing (LintError, LintResult, LintRule)
import Test exposing (Test, describe, test)
import TestUtil exposing (expectErrors, ruleTester)
testRule : String -> LintResult
testRule =
ruleTester rule
error : String -> LintError
error =
LintError "NoUnannotatedFunction"
tests : List Test
tests =
[ test "should not report constants that are annotated" <|
\() ->
testRule """
f : Int
f = 2
"""
|> expectErrors []
, test "should not report functions that are annotated" <|
\() ->
testRule """
f : Int -> Int
f n = 2
"""
|> expectErrors []
, test "should report constants that are not annotated" <|
\() ->
testRule "f = 2"
|> expectErrors [ error "`f` does not have a type declaration" ]
, test "should report functions that are not annotated" <|
\() ->
testRule "f n = 2"
|> expectErrors [ error "`f` does not have a type declaration" ]
, test "should report functions that are not annotated when there are annotations" <|
\() ->
testRule """
f : Int -> Int
g n = 3
"""
|> expectErrors [ error "`g` does not have a type declaration" ]
, test "should report functions that are not annotated when there are other annotated functions" <|
\() ->
testRule """
f : Int -> Int
f n = 2
g n = 3
"""
|> expectErrors [ error "`g` does not have a type declaration" ]
, test "should not functions declared in a `let` body" <|
\() ->
testRule """
f : Int -> Int
f n =
let
a = 2
in
a
"""
|> expectErrors []
]
all : Test
all =
describe "NoUnannotatedFunction" tests