mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-24 06:54:03 +03:00
Add starting point for new glob experiment.
This commit is contained in:
parent
5635566712
commit
8791747ad7
62
tests/GlobTestsNew.elm
Normal file
62
tests/GlobTestsNew.elm
Normal file
@ -0,0 +1,62 @@
|
||||
module GlobTestsNew exposing (all)
|
||||
|
||||
import Expect
|
||||
import Test exposing (Test, describe, test)
|
||||
|
||||
|
||||
{-| -}
|
||||
type Glob a
|
||||
= Glob { pattern : String, regexPattern : String, capture : String -> ( a, String ) }
|
||||
|
||||
|
||||
{-| -}
|
||||
literal : String -> Glob String
|
||||
literal string =
|
||||
Glob { pattern = string, regexPattern = string, capture = \filePath -> ( string, filePath ) }
|
||||
|
||||
|
||||
all : Test
|
||||
all =
|
||||
describe "glob"
|
||||
[ test "literal" <|
|
||||
\() ->
|
||||
literal "hello"
|
||||
|> expect "hello"
|
||||
{ expectedMatch = "hello"
|
||||
, expectedPattern = "hello"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
type DataExtension
|
||||
= Yml
|
||||
| Json
|
||||
|
||||
|
||||
run : String -> Glob match -> match
|
||||
run filePath (Glob { pattern, regexPattern, capture }) =
|
||||
capture filePath
|
||||
|> Tuple.first
|
||||
|
||||
|
||||
expect :
|
||||
String
|
||||
->
|
||||
{ expectedMatch : match
|
||||
, expectedPattern : String
|
||||
}
|
||||
-> Glob match
|
||||
-> Expect.Expectation
|
||||
expect filePath { expectedMatch, expectedPattern } glob =
|
||||
{ pattern = getPattern glob
|
||||
, match = glob |> run filePath
|
||||
}
|
||||
|> Expect.equal
|
||||
{ pattern = expectedPattern
|
||||
, match = expectedMatch
|
||||
}
|
||||
|
||||
|
||||
getPattern : Glob match -> String
|
||||
getPattern (Glob { pattern }) =
|
||||
pattern
|
Loading…
Reference in New Issue
Block a user