mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-27 05:44:17 +03:00
Rename temporary function names from removed API functions.
This commit is contained in:
parent
aef010ced7
commit
f7c647fb80
66
src/Glob.elm
66
src/Glob.elm
@ -4,16 +4,12 @@ import List.Extra
|
|||||||
|
|
||||||
|
|
||||||
type Glob a
|
type Glob a
|
||||||
= Glob String (List String -> a)
|
= Glob String (List String -> ( a, List String ))
|
||||||
|
|
||||||
|
|
||||||
type NewGlob a
|
map : (a -> b) -> Glob a -> Glob b
|
||||||
= NewGlob String (List String -> ( a, List String ))
|
map mapFn (Glob pattern applyCapture) =
|
||||||
|
Glob pattern
|
||||||
|
|
||||||
map : (a -> b) -> NewGlob a -> NewGlob b
|
|
||||||
map mapFn (NewGlob pattern applyCapture) =
|
|
||||||
NewGlob pattern
|
|
||||||
(\captures ->
|
(\captures ->
|
||||||
captures
|
captures
|
||||||
|> applyCapture
|
|> applyCapture
|
||||||
@ -21,14 +17,14 @@ map mapFn (NewGlob pattern applyCapture) =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
succeed : constructor -> NewGlob constructor
|
succeed : constructor -> Glob constructor
|
||||||
succeed constructor =
|
succeed constructor =
|
||||||
NewGlob "" (\captures -> ( constructor, captures ))
|
Glob "" (\captures -> ( constructor, captures ))
|
||||||
|
|
||||||
|
|
||||||
star : NewGlob String
|
star : Glob String
|
||||||
star =
|
star =
|
||||||
NewGlob "*"
|
Glob "*"
|
||||||
(\captures ->
|
(\captures ->
|
||||||
case captures of
|
case captures of
|
||||||
first :: rest ->
|
first :: rest ->
|
||||||
@ -39,9 +35,9 @@ star =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
zeroOrMore : List String -> NewGlob (Maybe String)
|
zeroOrMore : List String -> Glob (Maybe String)
|
||||||
zeroOrMore matchers =
|
zeroOrMore matchers =
|
||||||
NewGlob
|
Glob
|
||||||
("*("
|
("*("
|
||||||
++ (matchers |> String.join "|")
|
++ (matchers |> String.join "|")
|
||||||
++ ")"
|
++ ")"
|
||||||
@ -62,13 +58,13 @@ zeroOrMore matchers =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
literal2 : String -> NewGlob String
|
literal : String -> Glob String
|
||||||
literal2 string =
|
literal string =
|
||||||
NewGlob string (\captures -> ( string, captures ))
|
Glob string (\captures -> ( string, captures ))
|
||||||
|
|
||||||
|
|
||||||
runNew : List String -> NewGlob a -> { match : a, pattern : String }
|
run : List String -> Glob a -> { match : a, pattern : String }
|
||||||
runNew captures (NewGlob pattern applyCapture) =
|
run captures (Glob pattern applyCapture) =
|
||||||
{ match =
|
{ match =
|
||||||
captures
|
captures
|
||||||
|> List.reverse
|
|> List.reverse
|
||||||
@ -78,31 +74,21 @@ runNew captures (NewGlob pattern applyCapture) =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
run : List String -> Glob a -> { match : a, pattern : String }
|
toPattern : Glob a -> String
|
||||||
run captures (Glob pattern applyCapture) =
|
toPattern (Glob pattern applyCapture) =
|
||||||
{ match =
|
|
||||||
captures
|
|
||||||
|> List.reverse
|
|
||||||
|> applyCapture
|
|
||||||
, pattern = pattern
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
toPattern : NewGlob a -> String
|
|
||||||
toPattern (NewGlob pattern applyCapture) =
|
|
||||||
pattern
|
pattern
|
||||||
|
|
||||||
|
|
||||||
drop2 : NewGlob a -> NewGlob value -> NewGlob value
|
drop : Glob a -> Glob value -> Glob value
|
||||||
drop2 (NewGlob matcherPattern apply1) (NewGlob pattern apply2) =
|
drop (Glob matcherPattern apply1) (Glob pattern apply2) =
|
||||||
NewGlob
|
Glob
|
||||||
(pattern ++ matcherPattern)
|
(pattern ++ matcherPattern)
|
||||||
apply2
|
apply2
|
||||||
|
|
||||||
|
|
||||||
keep2 : NewGlob a -> NewGlob (a -> value) -> NewGlob value
|
keep : Glob a -> Glob (a -> value) -> Glob value
|
||||||
keep2 (NewGlob matcherPattern apply1) (NewGlob pattern apply2) =
|
keep (Glob matcherPattern apply1) (Glob pattern apply2) =
|
||||||
NewGlob
|
Glob
|
||||||
(pattern ++ matcherPattern)
|
(pattern ++ matcherPattern)
|
||||||
(\captures ->
|
(\captures ->
|
||||||
let
|
let
|
||||||
@ -120,13 +106,13 @@ keep2 (NewGlob matcherPattern apply1) (NewGlob pattern apply2) =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
oneOf2 : ( ( String, a ), List ( String, a ) ) -> NewGlob a
|
oneOf : ( ( String, a ), List ( String, a ) ) -> Glob a
|
||||||
oneOf2 ( defaultMatch, otherMatchers ) =
|
oneOf ( defaultMatch, otherMatchers ) =
|
||||||
let
|
let
|
||||||
allMatchers =
|
allMatchers =
|
||||||
defaultMatch :: otherMatchers
|
defaultMatch :: otherMatchers
|
||||||
in
|
in
|
||||||
NewGlob
|
Glob
|
||||||
("{"
|
("{"
|
||||||
++ (allMatchers |> List.map Tuple.first |> String.join ",")
|
++ (allMatchers |> List.map Tuple.first |> String.join ",")
|
||||||
++ "}"
|
++ "}"
|
||||||
|
@ -10,7 +10,7 @@ all =
|
|||||||
describe "glob"
|
describe "glob"
|
||||||
[ test "literal" <|
|
[ test "literal" <|
|
||||||
\() ->
|
\() ->
|
||||||
Glob.literal2 "hello"
|
Glob.literal "hello"
|
||||||
|> expect
|
|> expect
|
||||||
{ captures = []
|
{ captures = []
|
||||||
, expectedMatch = "hello"
|
, expectedMatch = "hello"
|
||||||
@ -19,8 +19,8 @@ all =
|
|||||||
, test "capture" <|
|
, test "capture" <|
|
||||||
\() ->
|
\() ->
|
||||||
Glob.succeed identity
|
Glob.succeed identity
|
||||||
|> Glob.keep2 Glob.star
|
|> Glob.keep Glob.star
|
||||||
|> Glob.drop2 (Glob.literal2 ".txt")
|
|> Glob.drop (Glob.literal ".txt")
|
||||||
|> expect
|
|> expect
|
||||||
{ captures = [ "my-file" ]
|
{ captures = [ "my-file" ]
|
||||||
, expectedMatch = "my-file"
|
, expectedMatch = "my-file"
|
||||||
@ -29,10 +29,10 @@ all =
|
|||||||
, test "oneOf" <|
|
, test "oneOf" <|
|
||||||
\() ->
|
\() ->
|
||||||
Glob.succeed Tuple.pair
|
Glob.succeed Tuple.pair
|
||||||
|> Glob.keep2 Glob.star
|
|> Glob.keep Glob.star
|
||||||
|> Glob.drop2 (Glob.literal2 ".")
|
|> Glob.drop (Glob.literal ".")
|
||||||
|> Glob.keep2
|
|> Glob.keep
|
||||||
(Glob.oneOf2
|
(Glob.oneOf
|
||||||
( ( "yml", Yml )
|
( ( "yml", Yml )
|
||||||
, [ ( "json", Json )
|
, [ ( "json", Json )
|
||||||
]
|
]
|
||||||
@ -84,10 +84,10 @@ all =
|
|||||||
, test "new star with literal" <|
|
, test "new star with literal" <|
|
||||||
\() ->
|
\() ->
|
||||||
Glob.succeed Tuple.pair
|
Glob.succeed Tuple.pair
|
||||||
|> Glob.keep2 Glob.star
|
|> Glob.keep Glob.star
|
||||||
|> Glob.drop2 (Glob.literal2 "/")
|
|> Glob.drop (Glob.literal "/")
|
||||||
|> Glob.keep2 (Glob.star |> Glob.map String.toUpper)
|
|> Glob.keep (Glob.star |> Glob.map String.toUpper)
|
||||||
|> Glob.drop2 (Glob.literal2 ".txt")
|
|> Glob.drop (Glob.literal ".txt")
|
||||||
|> expect
|
|> expect
|
||||||
{ captures = [ "before-slash", "after-slash" ]
|
{ captures = [ "before-slash", "after-slash" ]
|
||||||
, expectedMatch = ( "before-slash", "AFTER-SLASH" )
|
, expectedMatch = ( "before-slash", "AFTER-SLASH" )
|
||||||
@ -96,12 +96,12 @@ all =
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
zeroOrMoreGlob : Glob.NewGlob (Maybe String)
|
zeroOrMoreGlob : Glob.Glob (Maybe String)
|
||||||
zeroOrMoreGlob =
|
zeroOrMoreGlob =
|
||||||
Glob.succeed identity
|
Glob.succeed identity
|
||||||
|> Glob.drop2 (Glob.literal2 "test/a")
|
|> Glob.drop (Glob.literal "test/a")
|
||||||
|> Glob.keep2 (Glob.zeroOrMore [ "a", "b" ])
|
|> Glob.keep (Glob.zeroOrMore [ "a", "b" ])
|
||||||
|> Glob.drop2 (Glob.literal2 "/x.js")
|
|> Glob.drop (Glob.literal "/x.js")
|
||||||
|
|
||||||
|
|
||||||
type DataExtension
|
type DataExtension
|
||||||
@ -114,11 +114,11 @@ expect :
|
|||||||
, expectedMatch : match
|
, expectedMatch : match
|
||||||
, expectedPattern : String
|
, expectedPattern : String
|
||||||
}
|
}
|
||||||
-> Glob.NewGlob match
|
-> Glob.Glob match
|
||||||
-> Expect.Expectation
|
-> Expect.Expectation
|
||||||
expect { captures, expectedMatch, expectedPattern } glob =
|
expect { captures, expectedMatch, expectedPattern } glob =
|
||||||
glob
|
glob
|
||||||
|> Glob.runNew captures
|
|> Glob.run captures
|
||||||
|> Expect.equal
|
|> Expect.equal
|
||||||
{ pattern = expectedPattern
|
{ pattern = expectedPattern
|
||||||
, match = expectedMatch
|
, match = expectedMatch
|
||||||
|
Loading…
Reference in New Issue
Block a user