mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-26 11:13:39 +03:00
59 lines
2.1 KiB
Elm
59 lines
2.1 KiB
Elm
module SimplifyPropertyAccessTest exposing (all)
|
|
|
|
import Lint.Rules.SimplifyPropertyAccess 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 "SimplifyPropertyAccess"
|
|
|
|
|
|
tests : List Test
|
|
tests =
|
|
[ test "should report a named function that returns the property of a record" <|
|
|
\() ->
|
|
testRule "a x = x.foo"
|
|
|> expectErrors [ error "Access to property `foo` could be simplified by using `.foo`" ]
|
|
, test "should report an anonymous function that returns the property of a record" <|
|
|
\() ->
|
|
testRule "a = List.map (\\x -> x.foo)"
|
|
|> expectErrors [ error "Access to property `foo` could be simplified by using `.foo`" ]
|
|
, test "should not report a named function that returns a nested property" <|
|
|
\() ->
|
|
testRule "a x = x.foo.bar"
|
|
|> expectErrors []
|
|
, test "should not report an anonymous function that returns a nested property" <|
|
|
\() ->
|
|
testRule "a = List.map (\\x -> x.foo.bar)"
|
|
|> expectErrors []
|
|
, test "should not report a named function that returns the property of another value" <|
|
|
\() ->
|
|
testRule "a x = b.foo"
|
|
|> expectErrors []
|
|
, test "should not report an anonymous function that returns the property of another value" <|
|
|
\() ->
|
|
testRule "a = List.map (\\x -> b.foo)"
|
|
|> expectErrors []
|
|
, test "should not report a named function that has multiple parameters" <|
|
|
\() ->
|
|
testRule "a x y = x.foo"
|
|
|> expectErrors []
|
|
, test "should not report an anonymous function that has multiple parameters" <|
|
|
\() ->
|
|
testRule "a = List.map (\\x y -> x.foo)"
|
|
|> expectErrors []
|
|
]
|
|
|
|
|
|
all : Test
|
|
all =
|
|
describe "SimplifyPropertyAccess" tests
|