git.iko.soy/typeable/servant
on master help sign in
fix rebase issues
commitdab3c9b62db5fcc72b8eae2cec9d1a3c24a3e45b authorJulian K. Arni <jkarni@gmail.com> dateWed 18 Feb 2015, 10:40 (12 years ago) parenta75c723
3 files changed+23−30
src/Servant/QQ.hs+7−5 src/Servant/Utils/Links.hs+11−17 test/Servant/Utils/LinksSpec.hs+5−8
src/Servant/QQ.hs+7−5
@@ -72,7 +72,8 @@ data PathElemE
7272data OptsE
7373data SitemapE
7474
75−
75+sitemap = undefined
76+{-
7677data Validation e a = Failure e
7778 | Success a
7879
@@ -93,13 +94,13 @@ data Exp a where
9394data ParseError = ParseError Int String
9495
9596parseEverything :: String -> Exp SitemapE
96−parseEverything str = removeComments <$> lines str
97+parseEverything str = undefined {-removeComments <$> lines str
9798 where removeComments = takeWhile (/= '#')
9899 parseLines _ [] = []
99100 parseLines lineno (x:xs) = case opts of
100− [] -> (parseUrlLine x):parseLines rest
101− xs -> (parseUrlLine x `AddOpts`
102− where (opts, rest) = span (startsWith ' ') xs
101+ [] -> (parseUrlLine x):parseLines rest
102+ xs -> undefined
103+ where (opts, rest) = span (startsWith ' ') xs -}
103104
104105
105106
@@ -340,3 +341,4 @@ sitemap = QuasiQuoter { quoteExp = undefined
340341 Right st -> return st
341342 , quoteDec = undefined
342343 }
344+-}
src/Servant/Utils/Links.hs+11−17
@@ -136,6 +136,10 @@ type family Or (a :: Constraint) (b :: Constraint) :: Constraint where
136136 Or () b = ()
137137 Or a () = ()
138138
139+-- | If both a or b produce an empty constraint, produce an empty constraint.
140+type family And (a :: Constraint) (b :: Constraint) :: Constraint where
141+ And () () = ()
142+
139143-- | You may use this type family to tell the type checker that your custom type
140144-- may be skipped as part of a link. This is useful for things like
141145-- 'QueryParam' that are optional in a URI and do not affect them if they are
@@ -164,29 +168,19 @@ type family IsElem endpoint api :: Constraint where
164168 IsElem sa (MatrixParam x y :> sb) = IsElem sa sb
165169 IsElem sa (MatrixParams x y :> sb) = IsElem sa sb
166170 IsElem sa (MatrixFlag x :> sb) = IsElem sa sb
167− IsElem e e = ()
168− IsElem e a = IsElem' e a
169171 IsElem (Get ct typ) (Get ct' typ) = IsSubList ct ct'
170172 IsElem (Post ct typ) (Post ct' typ) = IsSubList ct ct'
171173 IsElem (Put ct typ) (Put ct' typ) = IsSubList ct ct'
172− IsElem e e = 'True
173− IsElem e a = 'False
174+ IsElem e e = ()
175+ IsElem e a = IsElem' e a
174176
175177
176−type family IsSubList a b where
177− IsSubList '[] b = 'True
178− IsSubList '[x] (x ': xs) = 'True
178+type family IsSubList a b :: Constraint where
179+ IsSubList '[] b = ()
180+ IsSubList '[x] (x ': xs) = ()
179181 IsSubList '[x] (y ': ys) = IsSubList '[x] ys
180182 IsSubList (x ': xs) y = IsSubList '[x] y `And` IsSubList xs y
181− IsSubList a b = 'False
182−
183−type family IsLink'' l where
184− IsLink'' (e :> Get cts x) = IsLink' e
185− IsLink'' (e :> Post cts x) = IsLink' e
186− IsLink'' (e :> Put cts x) = IsLink' e
187− IsLink'' (e :> Delete) = IsLink' e
188− IsLink'' a = 'False
189−
183+ IsSubList a b = 'True ~ 'False
190184
191185-- Phantom types for Param
192186data Matrix
@@ -343,7 +337,7 @@ instance HasLink (Get y r) where
343337 type MkLink (Get y r) = URI
344338 toLink _ = linkURI
345339
346−instance HasLink (Post r) where
340+instance HasLink (Post y r) where
347341 type MkLink (Post y r) = URI
348342 toLink _ = linkURI
349343
test/Servant/Utils/LinksSpec.hs+5−8
@@ -8,10 +8,7 @@ module Servant.Utils.LinksSpec where
88import Test.Hspec ( Spec, it, describe, shouldBe, Expectation )
99import Data.Proxy ( Proxy(..) )
1010
11−import Servant.API ( type (:<|>), ReqBody, QueryParam, MatrixParam, MatrixParams
12− , MatrixFlag, Get, Post, Capture, type (:>) , HTML , JSON, XML )
13−import Servant.QQSpec ( (~>) )
14−import Servant.Utils.Links ( IsElem, IsLink )
11+import Servant.API
1512
1613type TestApi =
1714 -- Capture and query/matrix params
@@ -69,7 +66,7 @@ spec = describe "Servant.Utils.Links" $ do
6966 let l3 = Proxy :: Proxy ("parent" :> MatrixParams "name" String
7067 :> "child"
7168 :> MatrixParam "gender" String
72− :> Get String)
69+ :> Get '[JSON] String)
7370 apiLink l3 ["Hubert?x=;&", "Cumberdale"] "Edward?"
7471 `shouldBeURI` "parent;name[]=Hubert%3Fx%3D%3B%26;\
7572 \name[]=Cumberdale/child;gender=Edward%3F"
@@ -86,8 +83,8 @@ spec = describe "Servant.Utils.Links" $ do
8683 apiLink l2 False True `shouldBeURI` "ducks;loud"
8784
8885 it "Generates correct links for all of the verbs" $ do
89− apiLink (Proxy :: Proxy ("get" :> Get ())) `shouldBeURI` "get"
90− apiLink (Proxy :: Proxy ("put" :> Put ())) `shouldBeURI` "put"
91− apiLink (Proxy :: Proxy ("post" :> Post ())) `shouldBeURI` "post"
86+ apiLink (Proxy :: Proxy ("get" :> Get '[JSON] ())) `shouldBeURI` "get"
87+ apiLink (Proxy :: Proxy ("put" :> Put '[JSON] ())) `shouldBeURI` "put"
88+ apiLink (Proxy :: Proxy ("post" :> Post '[JSON] ())) `shouldBeURI` "post"
9289 apiLink (Proxy :: Proxy ("delete" :> Delete)) `shouldBeURI` "delete"
9390 apiLink (Proxy :: Proxy ("raw" :> Raw)) `shouldBeURI` "raw"