From 8791747ad71da27aef16a56a4a2b74cc2161d9b5 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 25 Apr 2021 09:08:27 -0700 Subject: [PATCH] Add starting point for new glob experiment. --- tests/GlobTestsNew.elm | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/GlobTestsNew.elm diff --git a/tests/GlobTestsNew.elm b/tests/GlobTestsNew.elm new file mode 100644 index 00000000..a21f611f --- /dev/null +++ b/tests/GlobTestsNew.elm @@ -0,0 +1,62 @@ +module GlobTestsNew exposing (all) + +import Expect +import Test exposing (Test, describe, test) + + +{-| -} +type Glob a + = Glob { pattern : String, regexPattern : String, capture : String -> ( a, String ) } + + +{-| -} +literal : String -> Glob String +literal string = + Glob { pattern = string, regexPattern = string, capture = \filePath -> ( string, filePath ) } + + +all : Test +all = + describe "glob" + [ test "literal" <| + \() -> + literal "hello" + |> expect "hello" + { expectedMatch = "hello" + , expectedPattern = "hello" + } + ] + + +type DataExtension + = Yml + | Json + + +run : String -> Glob match -> match +run filePath (Glob { pattern, regexPattern, capture }) = + capture filePath + |> Tuple.first + + +expect : + String + -> + { expectedMatch : match + , expectedPattern : String + } + -> Glob match + -> Expect.Expectation +expect filePath { expectedMatch, expectedPattern } glob = + { pattern = getPattern glob + , match = glob |> run filePath + } + |> Expect.equal + { pattern = expectedPattern + , match = expectedMatch + } + + +getPattern : Glob match -> String +getPattern (Glob { pattern }) = + pattern