diff --git a/src/DataSource/Glob.elm b/src/DataSource/Glob.elm index bcedc289..a7e9fa0a 100644 --- a/src/DataSource/Glob.elm +++ b/src/DataSource/Glob.elm @@ -206,7 +206,22 @@ match (Glob matcherPattern regex1 apply1) (Glob pattern regex2 apply2) = Glob (pattern ++ matcherPattern) (combineRegexes regex1 regex2) - apply2 + (\fullPath captures -> + let + ( _, captured1 ) = + -- apply to make sure we drop from the captures list for all capturing patterns + -- but don't change the return value + captures + |> apply1 fullPath + + ( applied2, captured2 ) = + captured1 + |> apply2 fullPath + in + ( applied2 + , captured2 + ) + ) {-| -} @@ -254,9 +269,9 @@ oneOf ( defaultMatch, otherMatchers ) = defaultMatch :: otherMatchers in Glob - ("(" - ++ (allMatchers |> List.map Tuple.first |> String.join "|") - ++ ")" + ("{" + ++ (allMatchers |> List.map Tuple.first |> String.join ",") + ++ "}" ) ("(" ++ String.join "|" diff --git a/tests/GlobTests.elm b/tests/GlobTests.elm index 5c2fb12d..fbea0ae2 100644 --- a/tests/GlobTests.elm +++ b/tests/GlobTests.elm @@ -39,8 +39,41 @@ all = -- https://runkit.com/embed/05epbnc0c7g1 |> expect "data-file.json" { expectedMatch = ( "data-file", Json ) - , expectedPattern = "*.(yml|json)" + , expectedPattern = "*.{yml,json}" } + , test "mix of match and capture with wildcards" <| + \() -> + Glob.succeed identity + |> Glob.match Glob.wildcard + |> Glob.match (Glob.literal "/") + |> Glob.capture Glob.wildcard + |> expectAll + [ ( "match/capture", "capture" ) + ] + , test "mix of match and capture with wildcards 2" <| + \() -> + Glob.succeed identity + |> Glob.capture Glob.wildcard + |> Glob.match (Glob.literal "/") + |> Glob.match Glob.wildcard + |> expectAll + [ ( "capture/match", "capture" ) + ] + , test "oneOf with empty" <| + \() -> + Glob.succeed Tuple.pair + |> Glob.capture Glob.wildcard + |> Glob.capture + (Glob.oneOf + ( ( "/index", WithIndex ) + , [ ( "", NoIndex ) + ] + ) + ) + |> expectAll + [ ( "hello/index", ( "hello", WithIndex ) ) + , ( "hello", ( "hello", NoIndex ) ) + ] , test "at least one" <| \() -> Glob.succeed identity @@ -129,6 +162,11 @@ all = ] +type HasIndex + = WithIndex + | NoIndex + + zeroOrMoreGlob : Glob.Glob (Maybe String) zeroOrMoreGlob = Glob.succeed identity