mirror of
https://github.com/jfmengels/elm-review.git
synced 2025-01-08 10:47:25 +03:00
Add test to make sure files only have access to the files they requested
This commit is contained in:
parent
9b96c975eb
commit
e739f882e4
@ -55,6 +55,37 @@ a = 1
|
||||
, details = [ "foo/some-file.css" ]
|
||||
}
|
||||
]
|
||||
, test "visitors should only have access to files they requested" <|
|
||||
\() ->
|
||||
let
|
||||
project : Project
|
||||
project =
|
||||
createProject
|
||||
[ { path = "a.txt", content = "A" }
|
||||
, { path = "b.txt", content = "B" }
|
||||
, { path = "c.txt", content = "C" }
|
||||
]
|
||||
|
||||
rule : Rule
|
||||
rule =
|
||||
createRule
|
||||
(Rule.withArbitraryFilesModuleVisitor [ "a.txt", "c.txt" ] (reportsFileNames "A")
|
||||
>> Rule.withArbitraryFilesModuleVisitor [ "b.txt" ] (reportsFileNames "B")
|
||||
)
|
||||
in
|
||||
"""module A exposing (a)
|
||||
a = 1
|
||||
"""
|
||||
|> Review.Test.runWithProjectData project rule
|
||||
|> Review.Test.expectGlobalErrors
|
||||
[ { message = "Found these files"
|
||||
, details =
|
||||
[ "Visitor B saw file b.txt"
|
||||
, "Visitor A saw file a.txt"
|
||||
, "Visitor A saw file c.txt"
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
@ -76,6 +107,11 @@ arbitraryFilesModuleVisitor files context =
|
||||
List.map .path files ++ context
|
||||
|
||||
|
||||
reportsFileNames : String -> List { path : String, content : String } -> Context -> Context
|
||||
reportsFileNames prefix files context =
|
||||
List.map (\file -> "Visitor " ++ prefix ++ " saw file " ++ file.path) files ++ context
|
||||
|
||||
|
||||
finalEvaluation : Context -> List (Error scope)
|
||||
finalEvaluation context =
|
||||
[ Rule.globalError
|
||||
|
Loading…
Reference in New Issue
Block a user