Make sure that capture list is updated when running Glob.match (not just Glob.capture).

This commit is contained in:
Dillon Kearns 2021-05-26 14:57:16 -07:00
parent 340d311b6a
commit d520f734b3
2 changed files with 58 additions and 5 deletions

View File

@ -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 "|"

View File

@ -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