mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-24 15:12:01 +03:00
Change oneOf format to use (pattern1|pattern2) notation.
This commit is contained in:
parent
3fb2893dee
commit
78f704d578
27
src/Glob.elm
27
src/Glob.elm
@ -92,6 +92,27 @@ not string =
|
||||
)
|
||||
|
||||
|
||||
notOneOf : ( String, List String ) -> Glob String
|
||||
notOneOf ( firstPattern, otherPatterns ) =
|
||||
let
|
||||
allPatterns =
|
||||
firstPattern :: otherPatterns
|
||||
in
|
||||
Glob
|
||||
("!("
|
||||
++ (allPatterns |> String.join "|")
|
||||
++ ")"
|
||||
)
|
||||
(\captures ->
|
||||
case captures of
|
||||
first :: rest ->
|
||||
( first, rest )
|
||||
|
||||
[] ->
|
||||
( "ERROR", [] )
|
||||
)
|
||||
|
||||
|
||||
run : List String -> Glob a -> { match : a, pattern : String }
|
||||
run captures (Glob pattern applyCapture) =
|
||||
{ match =
|
||||
@ -142,9 +163,9 @@ oneOf ( defaultMatch, otherMatchers ) =
|
||||
defaultMatch :: otherMatchers
|
||||
in
|
||||
Glob
|
||||
("{"
|
||||
++ (allMatchers |> List.map Tuple.first |> String.join ",")
|
||||
++ "}"
|
||||
("("
|
||||
++ (allMatchers |> List.map Tuple.first |> String.join "|")
|
||||
++ ")"
|
||||
)
|
||||
(\captures ->
|
||||
case captures of
|
||||
|
@ -38,10 +38,11 @@ all =
|
||||
]
|
||||
)
|
||||
)
|
||||
-- https://runkit.com/embed/05epbnc0c7g1
|
||||
|> expect
|
||||
{ captures = [ "data-file", "json" ]
|
||||
, expectedMatch = ( "data-file", Json )
|
||||
, expectedPattern = "*.{yml,json}"
|
||||
, expectedPattern = "*.(yml|json)"
|
||||
}
|
||||
, test "optional group - no match" <|
|
||||
\() ->
|
||||
@ -108,7 +109,10 @@ all =
|
||||
, test "not" <|
|
||||
\() ->
|
||||
Glob.succeed Tuple.pair
|
||||
|> Glob.keep (Glob.not "xyz")
|
||||
|> Glob.keep
|
||||
(Glob.notOneOf
|
||||
( "xyz", [] )
|
||||
)
|
||||
|> Glob.drop (Glob.literal "/")
|
||||
|> Glob.keep Glob.wildcard
|
||||
|> Glob.drop (Glob.literal ".txt")
|
||||
@ -119,6 +123,21 @@ all =
|
||||
, expectedMatch = ( "abc", "d" )
|
||||
, expectedPattern = "!(xyz)/*.txt"
|
||||
}
|
||||
, test "not with multiple patterns" <|
|
||||
\() ->
|
||||
Glob.succeed Tuple.pair
|
||||
|> Glob.keep
|
||||
(Glob.notOneOf ( "abz", [ "xyz" ] ))
|
||||
|> Glob.drop (Glob.literal "/")
|
||||
|> Glob.keep Glob.wildcard
|
||||
|> Glob.drop (Glob.literal ".txt")
|
||||
|> expect
|
||||
-- abc/d.txt
|
||||
-- https://runkit.com/embed/05epbnc0c7g1
|
||||
{ captures = [ "abc", "d" ]
|
||||
, expectedMatch = ( "abc", "d" )
|
||||
, expectedPattern = "!(abz|xyz)/*.txt"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user