1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FunctionalDependencies #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE OverlappingInstances #-}
6{-# LANGUAGE QuasiQuotes #-}
7{-# LANGUAGE TypeFamilies #-}
8{-# LANGUAGE TypeOperators #-}
9{-# LANGUAGE UndecidableInstances #-}
10module Servant.API.QQSpec where
15{-import Servant.API.QQ-}
17--------------------------------------------------------------------------
19--------------------------------------------------------------------------
21-- Methods ---------------------------------------------------------------
22type SimpleGet = [sitemap|
25type SimpleGet' = "hello" :> Get ()
26type SimpleGet'' = "hello" :> Get Bool
28type SimpleGet2 = [sitemap|
31type SimpleGet2' = "hello" :> Get Bool
32type SimpleGet2'' = "hello" :> Get Int
34type SimplePost = [sitemap|
37type SimplePost' = "hello" :> Post ()
38type SimplePost'' = "hello" :> Post Bool
40type SimplePost2 = [sitemap|
43type SimplePost2' = "hello" :> Post Bool
44type SimplePost2'' = "hello" :> Post ()
46type SimplePut = [sitemap|
49type SimplePut' = "hello" :> Put ()
50type SimplePut'' = "hello" :> Put Bool
52type SimplePut2 = [sitemap|
55type SimplePut2' = "hello" :> Put Bool
56type SimplePut2'' = "hello" :> Put ()
58-- Parameters ------------------------------------------------------------
60type SimpleReqBody = [sitemap|
63type SimpleReqBody' = "hello" :> ReqBody () :> Post Bool
64type SimpleReqBody'' = "hello" :> ReqBody Bool :> Post ()
66type SimpleCapture = [sitemap|
69type SimpleCapture' = "hello" :> Capture "p" Int :> Post Bool
70type SimpleCapture'' = "hello" :> Capture "r" Int :> Post Bool
71type SimpleCapture''' = "hello" :> Capture "p" Bool :> Post Bool
73type SimpleQueryParam = [sitemap|
76type SimpleQueryParam' = "hello" :> QueryParam "p" Int :> Post Bool
77type SimpleQueryParam'' = "hello" :> QueryParam "r" Int :> Post Bool
78type SimpleQueryParam''' = "hello" :> QueryParam "p" Bool :> Post Bool
80-- Combinations ----------------------------------------------------------
82type TwoPaths = [sitemap|
86type TwoPaths' = ("hello" :> Post Bool) :<|> ("hello" :> Get Bool)
87--------------------------------------------------------------------------
89--------------------------------------------------------------------------
93 describe "'sitemap' QuasiQuoter" $ do
94 it "Handles simple GET types" $ do
95 (u::SimpleGet) ~= (u::SimpleGet' ) ~> True
96 (u::SimpleGet) ~= (u::SimpleGet'' ) ~> False
97 (u::SimpleGet2) ~= (u::SimpleGet2' ) ~> True
98 (u::SimpleGet2) ~= (u::SimpleGet2'') ~> False
99 it "Handles simple POST types" $ do
100 (u::SimplePost) ~= (u::SimplePost' ) ~> True
101 (u::SimplePost) ~= (u::SimplePost'' ) ~> False
102 (u::SimplePost2) ~= (u::SimplePost2' ) ~> True
103 (u::SimplePost2) ~= (u::SimplePost2'') ~> False
104 it "Handles simple PUT types" $ do
105 (u::SimplePut) ~= (u::SimplePut' ) ~> True
106 (u::SimplePut) ~= (u::SimplePut'' ) ~> False
107 (u::SimplePut2) ~= (u::SimplePut2' ) ~> True
108 (u::SimplePut2) ~= (u::SimplePut2'') ~> False
109 it "Handles simple request body types" $ do
110 (u::SimpleReqBody) ~= (u::SimpleReqBody' ) ~> True
111 (u::SimpleReqBody) ~= (u::SimpleReqBody'') ~> False
112 it "Handles simple captures" $ do
113 (u::SimpleCapture) ~= (u::SimpleCapture' ) ~> True
114 (u::SimpleCapture) ~= (u::SimpleCapture'') ~> False
115 (u::SimpleCapture) ~= (u::SimpleCapture''') ~> False
116 it "Handles simple querystring parameters" $ do
117 (u::SimpleQueryParam) ~= (u::SimpleQueryParam' ) ~> True
118 (u::SimpleQueryParam) ~= (u::SimpleQueryParam'') ~> False
119 (u::SimpleQueryParam) ~= (u::SimpleQueryParam''') ~> False
120 it "Handles multiples paths" $ do
121 (u::TwoPaths) ~= (u::TwoPaths') ~> True
124--------------------------------------------------------------------------
126--------------------------------------------------------------------------
130-- Kiselyov's Type Equality predicate
131class TypeEq x y b | x y -> b where { areEq :: x -> y -> Bool }
132instance TypeEq x x HTrue where { areEq _ _ = True }
133instance b ~ HFalse => TypeEq x y b where { areEq _ _ = False}
136(~=) :: TypeEq x y b => x -> y -> Bool
143(~>) :: (Show a, Eq a) => a -> a -> Expectation
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list