2017-06-18 15:00:48 +03:00
|
|
|
module NoUnannotatedFunctionTest exposing (all)
|
2017-01-16 02:07:04 +03:00
|
|
|
|
2017-01-29 22:03:31 +03:00
|
|
|
import Lint.Rules.NoUnannotatedFunction exposing (rule)
|
2018-11-05 17:40:41 +03:00
|
|
|
import Lint.Types exposing (LintError, LintResult, LintRule)
|
|
|
|
import Test exposing (Test, describe, test)
|
|
|
|
import TestUtil exposing (expectErrors, ruleTester)
|
2017-06-18 14:43:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
testRule : String -> LintResult
|
|
|
|
testRule =
|
|
|
|
ruleTester rule
|
2017-01-16 02:07:04 +03:00
|
|
|
|
|
|
|
|
2017-06-12 21:21:27 +03:00
|
|
|
error : String -> LintError
|
2017-01-16 02:07:04 +03:00
|
|
|
error =
|
2017-06-12 21:21:27 +03:00
|
|
|
LintError "NoUnannotatedFunction"
|
2017-01-16 02:07:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
tests : List Test
|
|
|
|
tests =
|
|
|
|
[ test "should not report constants that are annotated" <|
|
|
|
|
\() ->
|
2017-06-10 15:04:49 +03:00
|
|
|
testRule """
|
2017-06-12 21:15:05 +03:00
|
|
|
f : Int
|
2017-06-10 15:04:49 +03:00
|
|
|
f = 2
|
2017-01-16 02:07:04 +03:00
|
|
|
"""
|
2017-06-12 21:15:05 +03:00
|
|
|
|> expectErrors []
|
2017-01-16 02:07:04 +03:00
|
|
|
, test "should not report functions that are annotated" <|
|
|
|
|
\() ->
|
2017-06-10 15:04:49 +03:00
|
|
|
testRule """
|
2017-06-12 21:15:05 +03:00
|
|
|
f : Int -> Int
|
2017-06-10 15:04:49 +03:00
|
|
|
f n = 2
|
2017-01-16 02:07:04 +03:00
|
|
|
"""
|
2017-06-12 21:15:05 +03:00
|
|
|
|> expectErrors []
|
2017-01-16 02:07:04 +03:00
|
|
|
, test "should report constants that are not annotated" <|
|
|
|
|
\() ->
|
2017-06-10 15:04:49 +03:00
|
|
|
testRule "f = 2"
|
2017-06-12 21:15:05 +03:00
|
|
|
|> expectErrors [ error "`f` does not have a type declaration" ]
|
2017-01-16 02:07:04 +03:00
|
|
|
, test "should report functions that are not annotated" <|
|
|
|
|
\() ->
|
2017-06-10 15:04:49 +03:00
|
|
|
testRule "f n = 2"
|
2017-06-12 21:15:05 +03:00
|
|
|
|> expectErrors [ error "`f` does not have a type declaration" ]
|
2017-01-16 02:07:04 +03:00
|
|
|
, test "should report functions that are not annotated when there are annotations" <|
|
|
|
|
\() ->
|
2017-06-10 15:04:49 +03:00
|
|
|
testRule """
|
|
|
|
f : Int -> Int
|
|
|
|
g n = 3
|
2017-01-16 02:07:04 +03:00
|
|
|
"""
|
2017-06-12 21:15:05 +03:00
|
|
|
|> expectErrors [ error "`g` does not have a type declaration" ]
|
2017-01-16 02:07:04 +03:00
|
|
|
, test "should report functions that are not annotated when there are other annotated functions" <|
|
|
|
|
\() ->
|
2017-06-10 15:04:49 +03:00
|
|
|
testRule """
|
|
|
|
f : Int -> Int
|
|
|
|
f n = 2
|
2017-01-16 02:07:04 +03:00
|
|
|
|
2017-06-10 15:04:49 +03:00
|
|
|
g n = 3
|
2017-01-16 02:07:04 +03:00
|
|
|
"""
|
2017-06-12 21:15:05 +03:00
|
|
|
|> expectErrors [ error "`g` does not have a type declaration" ]
|
2017-01-16 02:07:04 +03:00
|
|
|
, test "should not functions declared in a `let` body" <|
|
|
|
|
\() ->
|
2017-06-10 15:04:49 +03:00
|
|
|
testRule """
|
|
|
|
f : Int -> Int
|
|
|
|
f n =
|
|
|
|
let
|
|
|
|
a = 2
|
|
|
|
in
|
|
|
|
a
|
2017-01-16 02:07:04 +03:00
|
|
|
"""
|
2017-06-12 21:15:05 +03:00
|
|
|
|> expectErrors []
|
2017-01-16 02:07:04 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
all : Test
|
|
|
|
all =
|
2017-01-16 02:16:28 +03:00
|
|
|
describe "NoUnannotatedFunction" tests
|