elm-review/tests/NoExposingEverythingTest.elm

136 lines
5.9 KiB
Elm
Raw Permalink Normal View History

2020-04-08 01:14:03 +03:00
module NoExposingEverythingTest exposing (all)
import NoExposingEverything exposing (rule)
import Review.Test
2020-04-08 19:36:56 +03:00
import Test exposing (Test, describe, test)
2020-04-08 01:14:03 +03:00
all : Test
all =
describe "NoExposingEverything"
2020-06-03 19:23:19 +03:00
[ test "should not report anything when a module exposes a limited set of things" <|
2020-08-09 19:55:15 +03:00
\() ->
2020-06-03 19:23:19 +03:00
"""
module A exposing (B(..), C, d)
type B = B
d = 1
"""
2020-04-08 01:14:03 +03:00
|> Review.Test.run rule
|> Review.Test.expectNoErrors
2020-12-25 19:23:07 +03:00
, test "should offer a fix listing all variables" <|
2020-08-09 19:55:15 +03:00
\() ->
2020-06-03 19:23:19 +03:00
"""
module A exposing (..)
2020-12-25 19:23:07 +03:00
foo = 1
bar = 2
2020-06-03 19:23:19 +03:00
"""
2020-04-08 01:14:03 +03:00
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Module exposes everything implicitly \"(..)\""
, details =
2021-04-06 18:32:30 +03:00
[ "Modules should have hidden implementation details with an explicit API so that the module is used in a proper and controlled way. The users of this module should not have to know about what is inside a module it is using, and they shouldn't need to access its internal details. Therefore, the API should be explicitly defined and ideally as small as possible."
2020-04-08 01:14:03 +03:00
]
, under = "(..)"
}
2020-12-25 19:23:07 +03:00
|> Review.Test.whenFixed
"""
module A exposing (foo, bar)
foo = 1
bar = 2
"""
]
, test "should offer a fix listing all types" <|
\() ->
"""
module A exposing (..)
type Foo = Foo
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Module exposes everything implicitly \"(..)\""
, details =
2021-04-06 18:32:30 +03:00
[ "Modules should have hidden implementation details with an explicit API so that the module is used in a proper and controlled way. The users of this module should not have to know about what is inside a module it is using, and they shouldn't need to access its internal details. Therefore, the API should be explicitly defined and ideally as small as possible."
2020-12-25 19:23:07 +03:00
]
, under = "(..)"
}
|> Review.Test.whenFixed
"""
module A exposing (Foo(..))
type Foo = Foo
"""
]
, test "should offer a fix listing all type aliases" <|
\() ->
"""
module A exposing (..)
type alias Foo = String
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Module exposes everything implicitly \"(..)\""
, details =
2021-04-06 18:32:30 +03:00
[ "Modules should have hidden implementation details with an explicit API so that the module is used in a proper and controlled way. The users of this module should not have to know about what is inside a module it is using, and they shouldn't need to access its internal details. Therefore, the API should be explicitly defined and ideally as small as possible."
2020-12-25 19:23:07 +03:00
]
, under = "(..)"
}
|> Review.Test.whenFixed
"""
module A exposing (Foo)
type alias Foo = String
"""
]
, test "should offer a fix listing all ports" <|
\() ->
"""
port module A exposing (..)
port foo : String
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Module exposes everything implicitly \"(..)\""
, details =
2021-04-06 18:32:30 +03:00
[ "Modules should have hidden implementation details with an explicit API so that the module is used in a proper and controlled way. The users of this module should not have to know about what is inside a module it is using, and they shouldn't need to access its internal details. Therefore, the API should be explicitly defined and ideally as small as possible."
2020-12-25 19:23:07 +03:00
]
, under = "(..)"
}
|> Review.Test.whenFixed
"""
port module A exposing (foo)
port foo : String
"""
]
, test "should offer a fix listing all infixes" <|
\() ->
"""
module List exposing (..)
import Elm.Kernel.List
infix right 5 (::) = cons
cons : a -> List a -> List a
cons =
Elm.Kernel.List.cons
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Module exposes everything implicitly \"(..)\""
, details =
2021-04-06 18:32:30 +03:00
[ "Modules should have hidden implementation details with an explicit API so that the module is used in a proper and controlled way. The users of this module should not have to know about what is inside a module it is using, and they shouldn't need to access its internal details. Therefore, the API should be explicitly defined and ideally as small as possible."
2020-12-25 19:23:07 +03:00
]
, under = "(..)"
}
|> Review.Test.whenFixed
"""
module List exposing ((::), cons)
import Elm.Kernel.List
infix right 5 (::) = cons
cons : a -> List a -> List a
cons =
Elm.Kernel.List.cons
"""
2020-04-08 01:14:03 +03:00
]
]