mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-24 06:54:03 +03:00
Add test setup for branch generator.
This commit is contained in:
parent
012aac229a
commit
fe3c79f30a
@ -1,16 +1,17 @@
|
||||
module Pages.Internal.RoutePattern exposing
|
||||
( Ending(..), RoutePattern, Segment(..), view, toVariant
|
||||
( Ending(..), RoutePattern, Segment(..), view, toVariant, routeToBranch
|
||||
, Param(..), fromModuleName, toRouteParamTypes, toRouteParamsRecord
|
||||
)
|
||||
|
||||
{-| Exposed for internal use only (used in generated code).
|
||||
|
||||
@docs Ending, RoutePattern, Segment, view, toVariant
|
||||
@docs Ending, RoutePattern, Segment, view, toVariant, routeToBranch
|
||||
|
||||
-}
|
||||
|
||||
import Elm
|
||||
import Elm.Annotation exposing (Annotation)
|
||||
import Elm.Case
|
||||
import Html exposing (Html)
|
||||
|
||||
|
||||
@ -123,6 +124,15 @@ toRouteParamTypes pattern =
|
||||
)
|
||||
|
||||
|
||||
routeToBranch : RoutePattern -> Elm.Case.Branch
|
||||
routeToBranch route =
|
||||
Elm.Case.branchList 0
|
||||
(\_ ->
|
||||
Elm.val "Index"
|
||||
|> Elm.just
|
||||
)
|
||||
|
||||
|
||||
{-| -}
|
||||
toVariant : RoutePattern -> Elm.Variant
|
||||
toVariant pattern =
|
||||
|
@ -2,6 +2,7 @@ module Pages.RouteParamsTest exposing (..)
|
||||
|
||||
import Elm
|
||||
import Elm.Annotation
|
||||
import Elm.Case
|
||||
import Elm.ToString
|
||||
import Expect exposing (Expectation)
|
||||
import Pages.Internal.RoutePattern as RoutePattern
|
||||
@ -132,9 +133,38 @@ suite =
|
||||
]
|
||||
)
|
||||
]
|
||||
, describe "toCase"
|
||||
[ test "root route" <|
|
||||
\() ->
|
||||
[]
|
||||
|> testCaseGenerator
|
||||
(Elm.Case.branchList 0
|
||||
(\_ ->
|
||||
Elm.val "Index"
|
||||
|> Elm.just
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
testCaseGenerator : Elm.Case.Branch -> List String -> Expectation
|
||||
testCaseGenerator expected moduleName =
|
||||
RoutePattern.fromModuleName moduleName
|
||||
|> Maybe.map (RoutePattern.routeToBranch >> toStringCase)
|
||||
|> Maybe.withDefault "<ERROR>"
|
||||
|> Expect.equal (expected |> toStringCase)
|
||||
|
||||
|
||||
toStringCase : Elm.Case.Branch -> String
|
||||
toStringCase branch =
|
||||
Elm.Case.custom (Elm.val "segments")
|
||||
(Elm.Annotation.list Elm.Annotation.string)
|
||||
[ branch ]
|
||||
|> Elm.ToString.expression
|
||||
|> .body
|
||||
|
||||
|
||||
expectRouteDefinition : Elm.Variant -> List String -> Expectation
|
||||
expectRouteDefinition expected moduleName =
|
||||
RoutePattern.fromModuleName moduleName
|
||||
|
Loading…
Reference in New Issue
Block a user