elm-review/tests/NoDebugTest.elm

134 lines
4.6 KiB
Elm
Raw Normal View History

port module NoDebugTest exposing (all)
import Expect
import Test exposing (describe, test, Test)
import NoDebug exposing (rule)
import Types exposing (Error)
error : String -> Error
error =
Error "NoDebug"
tests : List Test
tests =
[ test "should not report normal function calls" <|
\() ->
2017-01-16 23:40:01 +03:00
rule """
a = foo n
b = bar.foo n
c = debug
e = debug.log n
d = debug.log n
"""
|> Expect.equal []
, test "should report Debug.log use" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = Debug.log"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug.log calls" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = Debug.log z"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report multiple Debug.log calls" <|
\() ->
2017-01-16 23:40:01 +03:00
rule """
a = Debug.log z
b = Debug.log z
"""
|> Expect.equal
[ error "Forbidden use of Debug"
, error "Forbidden use of Debug"
]
, test "should report Debug.crash calls" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = Debug.crash 1"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report any Debug method" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = Debug.foo 1"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in a binary expression" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = (Debug.log z) + 2"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in a << binary expression" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = fn << Debug.log"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in a pipe expression" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = fn |> Debug.log z"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in an list expression" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = [Debug.log z y]"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in an record expression" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = { foo = Debug.log z y }"
|> Expect.equal [ error "Forbidden use of Debug" ]
-- elm-ast doesn't handle record update expressions
-- , test "should report Debug in an record update expression" <|
-- \() ->
2017-01-16 23:40:01 +03:00
-- rule "a = { model | foo = Debug.log z y }"
-- |> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in an lambda expression" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = (\\foo -> Debug.log z foo)"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in an if expression condition" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = if Debug.log a b then True else False"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in an if expression then" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = if True then Debug.log a b else False"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in an if expression else" <|
\() ->
2017-01-16 23:40:01 +03:00
rule "a = if True then True else Debug.log a b"
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in a case value" <|
\() ->
2017-01-16 23:40:01 +03:00
rule """
a = case Debug.log a b of
_ -> []
"""
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in a case pattern" <|
\() ->
2017-01-16 23:40:01 +03:00
rule """
a = case a of
Debug.log a b -> []
"""
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in a case body" <|
\() ->
2017-01-16 23:40:01 +03:00
rule """
a = case a of
_ -> Debug.log a b
"""
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in let declaration section" <|
\() ->
2017-01-16 23:40:01 +03:00
rule """
a = let b = Debug.log a b
in b
"""
|> Expect.equal [ error "Forbidden use of Debug" ]
, test "should report Debug in let body" <|
\() ->
2017-01-16 23:40:01 +03:00
rule """
a = let b = c
in Debug.log a b
"""
|> Expect.equal [ error "Forbidden use of Debug" ]
]
all : Test
all =
describe "NoDebug" tests