mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 23:05:35 +03:00
109 lines
4.0 KiB
Elm
109 lines
4.0 KiB
Elm
module NoImportingEverythingTest exposing (all)
|
|
|
|
import Lint.Rule.NoImportingEverything exposing (Configuration, rule)
|
|
import Lint.Test exposing (LintResult)
|
|
import Test exposing (Test, describe, test)
|
|
|
|
|
|
testRule : Configuration -> String -> LintResult
|
|
testRule options =
|
|
Lint.Test.run (rule options)
|
|
|
|
|
|
tests : List Test
|
|
tests =
|
|
[ test "should not report imports that do not expose anything" <|
|
|
\() ->
|
|
"""module A exposing (..)
|
|
import Html
|
|
import Http"""
|
|
|> testRule { exceptions = [] }
|
|
|> Lint.Test.expectNoErrors
|
|
, test "should not report imports that expose functions by name" <|
|
|
\() ->
|
|
"""module A exposing (..)
|
|
import Html exposing (a)
|
|
import Http exposing (a, b)"""
|
|
|> testRule { exceptions = [] }
|
|
|> Lint.Test.expectNoErrors
|
|
, test "should report imports that expose everything" <|
|
|
\() ->
|
|
"""module A exposing (..)
|
|
import Html exposing (..)"""
|
|
|> testRule { exceptions = [] }
|
|
|> Lint.Test.expectErrors
|
|
[ Lint.Test.error
|
|
{ message = "Do not expose everything from Html"
|
|
, under = ".."
|
|
}
|
|
|> Lint.Test.atExactly { start = { row = 2, column = 23 }, end = { row = 2, column = 25 } }
|
|
]
|
|
, test "should report imports from sub-modules" <|
|
|
\() ->
|
|
"""module A exposing (a)
|
|
import Html.App exposing (..)"""
|
|
|> testRule { exceptions = [] }
|
|
|> Lint.Test.expectErrors
|
|
[ Lint.Test.error
|
|
{ message = "Do not expose everything from Html.App"
|
|
, under = ".."
|
|
}
|
|
]
|
|
, test "should report imports from sub-modules (multiple dots)" <|
|
|
\() ->
|
|
"""module A exposing (a)
|
|
import Html.Foo.Bar exposing (..)"""
|
|
|> testRule { exceptions = [] }
|
|
|> Lint.Test.expectErrors
|
|
[ Lint.Test.error
|
|
{ message = "Do not expose everything from Html.Foo.Bar"
|
|
, under = ".."
|
|
}
|
|
]
|
|
, test "should not report imports that expose everything that are in the exception list" <|
|
|
\() ->
|
|
"""module A exposing (a)
|
|
import Html exposing (..)"""
|
|
|> testRule { exceptions = [ "Html" ] }
|
|
|> Lint.Test.expectNoErrors
|
|
, test "should not report imports from sub-modules that are in the exception list" <|
|
|
\() ->
|
|
"""module A exposing (a)
|
|
import Html.App exposing (..)"""
|
|
|> testRule { exceptions = [ "Html.App" ] }
|
|
|> Lint.Test.expectNoErrors
|
|
, test "should not report imports from sub-modules (multiple dots)" <|
|
|
\() ->
|
|
"""module A exposing (a)
|
|
import Html.Foo.Bar exposing (..)"""
|
|
|> testRule { exceptions = [ "Html.Foo.Bar" ] }
|
|
|> Lint.Test.expectNoErrors
|
|
, test "should report imports whose parent is ignored" <|
|
|
\() ->
|
|
"""module A exposing (a)
|
|
import Html.Foo.Bar exposing (..)"""
|
|
|> testRule { exceptions = [ "Html" ] }
|
|
|> Lint.Test.expectErrors
|
|
[ Lint.Test.error
|
|
{ message = "Do not expose everything from Html.Foo.Bar"
|
|
, under = ".."
|
|
}
|
|
]
|
|
, test "should report imports whose sub-module is ignored" <|
|
|
\() ->
|
|
"""module A exposing (a)
|
|
import Html exposing (..)"""
|
|
|> testRule { exceptions = [ "Html.App" ] }
|
|
|> Lint.Test.expectErrors
|
|
[ Lint.Test.error
|
|
{ message = "Do not expose everything from Html"
|
|
, under = ".."
|
|
}
|
|
]
|
|
]
|
|
|
|
|
|
all : Test
|
|
all =
|
|
describe "NoImportingEverything" tests
|