Extracting type metadata from Elm code?

I also encountered this situation (almost everyone writing this kind of Route module does!).

What I do for now is to write (by hand) a routeFuzzer : Fuzzer Route being in charge of randomly generate all possible routes and then I only have one test being:

fuzz routeFuzzer
        "Test route serialization/parsing matching"
        (\route ->
            ("http://domain.com" ++ Route.toString route)
                |> Url.fromString
                |> Maybe.andThen Route.parse
                |> Expect.equal (Just route)
        )

This is a bit painful to write but if you change something in your route structure, this won’t compile and you cannot miss that. The only situation where you have to be very careful is when you add a new route (but this doesn’t happen very often).

1 Like