From 614f9d8a490892b04cef508362c5fe13b40d167f Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sun, 7 Mar 2021 17:14:25 +0100 Subject: [PATCH] Outline happy path --- src/Review/Test.elm | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/Review/Test.elm b/src/Review/Test.elm index 157a3d4b..48f93f23 100644 --- a/src/Review/Test.elm +++ b/src/Review/Test.elm @@ -1189,6 +1189,53 @@ checkAllErrorsMatch runResult unorderedExpectedErrors = |> (\expectations -> Expect.all expectations ()) +happyPath : { expected : List GlobalError, actual : List GlobalError, needSecondPass : List GlobalError } -> List Expectation +happyPath params = + case params.expected of + head :: rest -> + case findAndRemove head params.actual of + Just newActual -> + happyPath { expected = rest, actual = newActual, needSecondPass = params.needSecondPass } + + Nothing -> + happyPath { expected = rest, actual = params.actual, needSecondPass = head :: params.needSecondPass } + + [] -> + if List.isEmpty params.actual then + if List.isEmpty params.needSecondPass then + [ Expect.pass ] + + else + -- TODO Report extraneous errors + [] + + else + notHappyPath params.actual params.needSecondPass + + +findAndRemove : a -> List a -> Maybe (List a) +findAndRemove element list = + findAndRemoveHelp element [] list + + +findAndRemoveHelp : a -> List a -> List a -> Maybe (List a) +findAndRemoveHelp element previous list = + case list of + [] -> + Nothing + + head :: rest -> + if element == head then + Just (List.reverse previous ++ rest) + + else + findAndRemoveHelp element (head :: previous) rest + + +notHappyPath = + Debug.todo "" + + checkAllGlobalErrorsMatch : { expected : List GlobalError, actual : List GlobalError } -> List (() -> Expectation) checkAllGlobalErrorsMatch params = case ( params.expected, params.actual ) of