module Analyser.Checks.UnusedPatternVariableTests exposing (all) import Analyser.Checks.CheckTestUtil as CTU import Analyser.Checks.UnusedPatternVariable as UnusedPatternVariable import Analyser.Files.Types exposing (..) import Analyser.Messages.Data as Data exposing (MessageData) import Dict import Test exposing (..) usedVariableAsRecordUpdate : ( String, String, List MessageData ) usedVariableAsRecordUpdate = ( "usedVariableAsRecordUpdate" , """module Bar exposing (..) addUsedVariable x = { x | name = "John" } """ , [] ) usedVariableInCaseExpression : ( String, String, List MessageData ) usedVariableInCaseExpression = ( "usedVariableInCaseExpression" , """module Bar exposing (..) foo x = case x of Bar -> 1 """ , [] ) usedVariableInAllDeclaration : ( String, String, List MessageData ) usedVariableInAllDeclaration = ( "usedVariableInAllDeclaration" , """module Bar exposing (..) x y = case y of ( b, _ ) -> let _ = Debug.log "Unknown" b in model ! []""" , [] ) usedValueConstructor : ( String, String, List MessageData ) usedValueConstructor = ( "usedValueConstructor" , """module Bar exposing (foo) type Some = Thing foo = Thing """ , [] ) exposedValueConstructor : ( String, String, List MessageData ) exposedValueConstructor = ( "exposedValueConstructor" , """module Bar exposing (foo,Some(..)) type Some = Thing foo = 1 """ , [] ) destructuringSameName : ( String, String, List MessageData ) destructuringSameName = ( "destructuringSameName" , """module Foo exposing (..) error : Model -> Maybe Error error { error } = error """ , [] ) unusedInEffectModule : ( String, String, List MessageData ) unusedInEffectModule = ( "unusedInEffectModule" , """effect module X where {subscription = MySub} exposing (foo) foo = 1 init = 2 """ , [] ) usedImportedVariableInPatterMatch : ( String, String, List MessageData ) usedImportedVariableInPatterMatch = ( "usedImportedVariableInPatterMatch" , """module Foo exposing (foo) import Color exposing (Color(..)) foo c = case c of Blue -> 1 """ , [] ) usedImportedVariableAsOpaque : ( String, String, List MessageData ) usedImportedVariableAsOpaque = ( "usedImportedVariableAsOpaque" , """module Foo exposing (foo) import Color exposing (Color(..)) foo (Blue c) = c """ , [] ) unusedInCasePattern : ( String, String, List MessageData ) unusedInCasePattern = ( "unusedInCasePattern" , """module Foo exposing (foo) foo x = case x of Just y -> 1 """ , [ Data.init "foo" |> Data.addVarName "varName" "y" |> Data.addRange "range" { start = { row = 6, column = 10 }, end = { row = 6, column = 11 } } ] ) unusedInCasePatternAsSingle : ( String, String, List MessageData ) unusedInCasePatternAsSingle = ( "unusedInCasePatternAsSingle" , """module Foo exposing (foo) foo x = case x of y -> 1 """ , [ Data.init "foo" |> Data.addVarName "varName" "y" |> Data.addRange "range" { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } ] ) usedInDestructuringLet : ( String, String, List MessageData ) usedInDestructuringLet = ( "usedInDestructuringLet" , """module Foo exposing (..) import Some exposing (Bar(..)) x = let (Bar 1) = some in 1 """ , [] ) {-| Issue #96 -} usedBinaryImportedFunctionUsedAsPrefix : ( String, String, List MessageData ) usedBinaryImportedFunctionUsedAsPrefix = ( "usedBinaryImportedFunctionUsedAsPrefix" , """module Foo exposing (..) import List.Extra exposing ((!!)) getItemAtIndex : Int -> Maybe String getItemAtIndex index = let someList = [ "a", "b", "c" ] in (!!) someList index """ , [] ) all : Test all = CTU.build "Analyser.Checks.UnusedPatternVariable" UnusedPatternVariable.checker [ usedVariableInCaseExpression , usedVariableAsRecordUpdate , usedVariableInAllDeclaration , usedValueConstructor , exposedValueConstructor , destructuringSameName , unusedInEffectModule , usedImportedVariableInPatterMatch , usedImportedVariableAsOpaque , unusedInCasePattern , unusedInCasePatternAsSingle , usedInDestructuringLet , usedBinaryImportedFunctionUsedAsPrefix ]