elm-review/tests/NoUnannotatedFunctionTest.elm

76 lines
2.1 KiB
Elm
Raw Normal View History

2017-06-18 15:00:48 +03:00
module NoUnannotatedFunctionTest exposing (all)
2017-01-16 02:07:04 +03:00
import Test exposing (describe, test, Test)
2017-01-29 22:03:31 +03:00
import Lint.Rules.NoUnannotatedFunction exposing (rule)
2017-06-18 14:43:37 +03:00
import Lint.Types exposing (LintRule, LintError, LintResult)
import TestUtil exposing (ruleTester, expectErrors)
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 """
f : Int
2017-06-10 15:04:49 +03:00
f = 2
2017-01-16 02:07:04 +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 """
f : Int -> Int
2017-06-10 15:04:49 +03:00
f n = 2
2017-01-16 02:07:04 +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"
|> 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"
|> 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
"""
|> 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
"""
|> 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
"""
|> expectErrors []
2017-01-16 02:07:04 +03:00
]
all : Test
all =
describe "NoUnannotatedFunction" tests