@@ -1,3 +1,4 @@
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
@@ -20,7 +21,7 @@ import Data.Either
20import Data.Function
21import Data.Function
22import Data.List
23import Data.List
23− (maximumBy)
24+ (sortBy)
24import qualified Data.List.NonEmpty as NE
25import qualified Data.List.NonEmpty as NE
25import Data.Maybe
26import Data.Maybe
26 (fromJust, isJust, isNothing)
27 (fromJust, isJust, isNothing)
@@ -134,17 +135,29 @@ spec = describe "Servant.API.ContentTypes" $ do
134 == Just ("application/json;charset=utf-8", encode x)
135 == Just ("application/json;charset=utf-8", encode x)
136 it "respects the Accept spec ordering" $ do
137 it "respects the Accept spec ordering" $ do
137− let highest a b c = maximumBy (compare `on` snd)
138+ let highest a b c = last $ sortBy (compare `on` snd)
139+-- when qualities are same, http-media-0.8 picks first; 0.7 last.
140+#if MIN_VERSION_http_media(0,8,0)
141+ [ ("text/plain;charset=utf-8", c)
142+ , ("application/json;charset=utf-8", b)
143+ , ("application/octet-stream", a)
138 [ ("application/octet-stream", a)
146 [ ("application/octet-stream", a)
139 , ("application/json;charset=utf-8", b)
147 , ("application/json;charset=utf-8", b)
140 , ("text/plain;charset=utf-8", c)
148 , ("text/plain;charset=utf-8", c)
142 let acceptH a b c = addToAccept (Proxy :: Proxy OctetStream) a $
151 let acceptH a b c = addToAccept (Proxy :: Proxy OctetStream) a $
143− addToAccept (Proxy :: Proxy JSON) b $
152+ addToAccept (Proxy :: Proxy JSON) b $
144− addToAccept (Proxy :: Proxy PlainText ) c ""
153+ addToAccept (Proxy :: Proxy PlainText ) c $
145 let val a b c i = handleAcceptH (Proxy :: Proxy '[OctetStream, JSON, PlainText])
155 let val a b c i = handleAcceptH (Proxy :: Proxy '[OctetStream, JSON, PlainText])
146 (acceptH a b c) (i :: Int)
156 (acceptH a b c) (i :: Int)
157+ property $ \a b c i ->
158+ let acc = acceptH a b c
159+ in counterexample (show acc) $
147− property $ \a b c i -> fst (fromJust $ val a b c i) == fst (highest a b c)
160+ fst (fromJust $ val a b c i) === fst (highest a b c)
149 describe "handleCTypeH" $ do
162 describe "handleCTypeH" $ do