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 |   either (putStrLn . interpolate) printLn . decodeAs a . fromString
24 |
25 | ||| Testing facility for path decoding.
26 | |||
27 | ||| Example usage at the REPL:
28 | |||
29 | ||| ```
30 | ||| :exec decodeTest (Vect 3 Nat) "https://www.hock.com/1/2/3?foo=bar"
31 | ||| ```
32 | export
33 | decodeManyTest : (0 a : Type) -> DecodeMany a => Show a => String -> IO ()
34 | decodeManyTest a s =
35 |   case parseURI Virtual (fromString s) of
36 |     Left err => putStrLn "\{err}"
37 |     Right u  => case decodeMany {a} u.path of
38 |       Right ([],v) => printLn v
39 |       Right (b::bs,v) => putStrLn "only consumed up to \{b}: \{show v}"
40 |       Left x => putStrLn "\{x}"
41 |