Remove obsolete captures list (now derived from running regex).

This commit is contained in:
Dillon Kearns 2021-04-25 20:38:48 -07:00
parent c7984cccfd
commit b245d7dc98
2 changed files with 15 additions and 29 deletions

View File

@ -123,8 +123,8 @@ regexEscaped stringLiteral =
{-| -} {-| -}
run : String -> RawGlob -> Glob a -> { match : a, pattern : String } run : String -> Glob a -> { match : a, pattern : String }
run rawInput { captures, fullPath } (Glob pattern regex applyCapture) = run rawInput (Glob pattern regex applyCapture) =
let let
fullRegex = fullRegex =
"^" ++ regex ++ "$" "^" ++ regex ++ "$"
@ -312,7 +312,7 @@ toDataSource glob =
(OptimizedDecoder.field "fullPath" OptimizedDecoder.string) (OptimizedDecoder.field "fullPath" OptimizedDecoder.string)
|> OptimizedDecoder.list |> OptimizedDecoder.list
|> OptimizedDecoder.map |> OptimizedDecoder.map
(\rawGlob -> rawGlob |> List.map (\inner -> run inner.fullPath inner glob |> .match)) (\rawGlob -> rawGlob |> List.map (\inner -> run inner.fullPath glob |> .match))
) )

View File

@ -12,8 +12,7 @@ all =
\() -> \() ->
Glob.literal "hello" Glob.literal "hello"
|> expect "hello" |> expect "hello"
{ captures = [] { expectedMatch = "hello"
, expectedMatch = "hello"
, expectedPattern = "hello" , expectedPattern = "hello"
} }
, test "capture" <| , test "capture" <|
@ -22,8 +21,7 @@ all =
|> Glob.capture Glob.wildcard |> Glob.capture Glob.wildcard
|> Glob.ignore (Glob.literal ".txt") |> Glob.ignore (Glob.literal ".txt")
|> expect "my-file.txt" |> expect "my-file.txt"
{ captures = [ "my-file" ] { expectedMatch = "my-file"
, expectedMatch = "my-file"
, expectedPattern = "*.txt" , expectedPattern = "*.txt"
} }
, test "oneOf" <| , test "oneOf" <|
@ -40,8 +38,7 @@ all =
) )
-- https://runkit.com/embed/05epbnc0c7g1 -- https://runkit.com/embed/05epbnc0c7g1
|> expect "data-file.json" |> expect "data-file.json"
{ captures = [ "data-file", "json" ] { expectedMatch = ( "data-file", Json )
, expectedMatch = ( "data-file", Json )
, expectedPattern = "*.(yml|json)" , expectedPattern = "*.(yml|json)"
} }
, test "at least one" <| , test "at least one" <|
@ -58,8 +55,7 @@ all =
) )
-- https://runkit.com/embed/05epbnc0c7g1 -- https://runkit.com/embed/05epbnc0c7g1
|> expect "data-file.jsonymljsonjson" |> expect "data-file.jsonymljsonjson"
{ captures = [ "data-file", "jsonymljsonjson" ] { expectedMatch = ( Json, [ Yml, Json, Json ] )
, expectedMatch = ( Json, [ Yml, Json, Json ] )
, expectedPattern = "*.+(yml|json)" , expectedPattern = "*.+(yml|json)"
} }
, test "optional group - no match" <| , test "optional group - no match" <|
@ -68,8 +64,7 @@ all =
|> expect "test/a/x.js" |> expect "test/a/x.js"
-- test/a/x.js -- test/a/x.js
-- https://github.com/micromatch/micromatch/blob/fe4858b0c63b174fd3ae22674db39119b8fa4392/test/api.capture.js#L42 -- https://github.com/micromatch/micromatch/blob/fe4858b0c63b174fd3ae22674db39119b8fa4392/test/api.capture.js#L42
{ captures = [ "" ] { expectedMatch = Nothing
, expectedMatch = Nothing
, expectedPattern = "test/a*(a|b)/x.js" , expectedPattern = "test/a*(a|b)/x.js"
} }
, test "optional group - single match" <| , test "optional group - single match" <|
@ -78,8 +73,7 @@ all =
|> expect "test/ab/x.js" |> expect "test/ab/x.js"
-- test/ab/x.js -- test/ab/x.js
-- https://github.com/micromatch/micromatch/blob/fe4858b0c63b174fd3ae22674db39119b8fa4392/test/api.capture.js#L44 -- https://github.com/micromatch/micromatch/blob/fe4858b0c63b174fd3ae22674db39119b8fa4392/test/api.capture.js#L44
{ captures = [ "b" ] { expectedMatch = Just "b"
, expectedMatch = Just "b"
, expectedPattern = "test/a*(a|b)/x.js" , expectedPattern = "test/a*(a|b)/x.js"
} }
, test "optional group - multiple matches" <| , test "optional group - multiple matches" <|
@ -88,16 +82,14 @@ all =
|> expect "test/aba/x.js" |> expect "test/aba/x.js"
-- test/aba/x.js -- test/aba/x.js
-- https://github.com/micromatch/micromatch/blob/fe4858b0c63b174fd3ae22674db39119b8fa4392/test/api.capture.js#L45 -- https://github.com/micromatch/micromatch/blob/fe4858b0c63b174fd3ae22674db39119b8fa4392/test/api.capture.js#L45
{ captures = [ "ba" ] { expectedMatch = Just "ba"
, expectedMatch = Just "ba"
, expectedPattern = "test/a*(a|b)/x.js" , expectedPattern = "test/a*(a|b)/x.js"
} }
, test "new star" <| , test "new star" <|
\() -> \() ->
Glob.wildcard Glob.wildcard
|> expect "star-pattern" |> expect "star-pattern"
{ captures = [ "star-pattern" ] { expectedMatch = "star-pattern"
, expectedMatch = "star-pattern"
, expectedPattern = "*" , expectedPattern = "*"
} }
, test "new star with literal" <| , test "new star with literal" <|
@ -108,8 +100,7 @@ all =
|> Glob.capture (Glob.wildcard |> Glob.map String.toUpper) |> Glob.capture (Glob.wildcard |> Glob.map String.toUpper)
|> Glob.ignore (Glob.literal ".txt") |> Glob.ignore (Glob.literal ".txt")
|> expect "before-slash/after-slash.txt" |> expect "before-slash/after-slash.txt"
{ captures = [ "before-slash", "after-slash" ] { expectedMatch = ( "before-slash", "AFTER-SLASH" )
, expectedMatch = ( "before-slash", "AFTER-SLASH" )
, expectedPattern = "*/*.txt" , expectedPattern = "*/*.txt"
} }
, test "recursive match" <| , test "recursive match" <|
@ -120,8 +111,7 @@ all =
|> Glob.capture Glob.wildcard |> Glob.capture Glob.wildcard
|> Glob.ignore (Glob.literal ".txt") |> Glob.ignore (Glob.literal ".txt")
|> expect "a/b/c/d.txt" |> expect "a/b/c/d.txt"
{ captures = [ "a/b/c", "d" ] { expectedMatch = ( "a/b/c", "d" )
, expectedMatch = ( "a/b/c", "d" )
, expectedPattern = "**/*.txt" , expectedPattern = "**/*.txt"
} }
] ]
@ -143,18 +133,14 @@ type DataExtension
expect : expect :
String String
-> ->
{ captures : List String { expectedMatch : match
, expectedMatch : match
, expectedPattern : String , expectedPattern : String
} }
-> Glob.Glob match -> Glob.Glob match
-> Expect.Expectation -> Expect.Expectation
expect filePath { captures, expectedMatch, expectedPattern } glob = expect filePath { expectedMatch, expectedPattern } glob =
glob glob
|> Glob.run filePath |> Glob.run filePath
{ fullPath = "full-path"
, captures = captures
}
|> Expect.equal |> Expect.equal
{ pattern = expectedPattern { pattern = expectedPattern
, match = expectedMatch , match = expectedMatch