mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-26 11:13:39 +03:00
30 lines
693 B
Elm
30 lines
693 B
Elm
module TestUtil exposing (expectErrors, ruleTester)
|
|
|
|
import Expect
|
|
import Lint exposing (parseSource)
|
|
import Lint.Types exposing (LintError, LintResult, LintRule)
|
|
import Regex
|
|
|
|
|
|
spacesRegex : Regex.Regex
|
|
spacesRegex =
|
|
Regex.regex "\n "
|
|
|
|
|
|
ruleTester : LintRule -> String -> LintResult
|
|
ruleTester rule str =
|
|
str
|
|
|> Regex.replace Regex.All spacesRegex (\_ -> "\n")
|
|
|> parseSource
|
|
|> Result.map rule
|
|
|
|
|
|
expectErrors : List LintError -> LintResult -> Expect.Expectation
|
|
expectErrors expectedErrors result =
|
|
case result of
|
|
Err _ ->
|
|
Expect.fail "Parsing failure"
|
|
|
|
Ok errors ->
|
|
Expect.equal expectedErrors errors
|