0 | module HTTP.Debug
 1 |
 2 | import HTTP.API.Decode
 3 | import HTTP.I18n.EN
 4 | import HTTP.URI
 5 | import Text.ILex
 6 |
 7 | %default total
 8 |
 9 | --------------------------------------------------------------------------------
10 | -- Decode Testing
11 | --------------------------------------------------------------------------------
12 |
13 | ||| Testing facility for value decoding.
14 | |||
15 | ||| Example usage at the REPL:
16 | |||
17 | ||| ```
18 | ||| :exec decodeTest Double "12.112"
19 | ||| ```
20 | export
21 | decodeTest : (0 a : Type) -> Decode a => Show a => String -> IO ()
22 | decodeTest a =
23 |  let loc := HTTPEN
24 |   in either (putStrLn . interpolate) printLn . decodeAs a . fromString
25 |
26 | ||| Testing facility for path decoding.
27 | |||
28 | ||| Example usage at the REPL:
29 | |||
30 | ||| ```
31 | ||| :exec decodeTest (Vect 3 Nat) "https://www.hock.com/1/2/3?foo=bar"
32 | ||| ```
33 | export
34 | decodeManyTest : (0 a : Type) -> DecodeMany a => Show a => String -> IO ()
35 | decodeManyTest a s =
36 |  let loc := HTTPEN
37 |   in case parseURI Virtual (fromString s) of
38 |        Left err => putStrLn "\{err}"
39 |        Right u  => case decodeMany {a} u.path of
40 |          Right ([],v) => printLn v
41 |          Right (b::bs,v) => putStrLn "only consumed up to \{b}: \{show v}"
42 |          Left x => putStrLn "\{x}"
43 |