1
+ {-# LANGUAGE CPP #-}
1
2
{-# LANGUAGE DataKinds #-}
2
3
{-# LANGUAGE DeriveGeneric #-}
3
4
{-# LANGUAGE MultiParamTypeClasses #-}
@@ -20,7 +21,7 @@ import Data.Either
20
21
import Data.Function
21
22
(on )
22
23
import Data.List
23
- (maximumBy )
24
+ (sortBy )
24
25
import qualified Data.List.NonEmpty as NE
25
26
import Data.Maybe
26
27
(fromJust , isJust , isNothing )
@@ -134,17 +135,29 @@ spec = describe "Servant.API.ContentTypes" $ do
134
135
== Just (" application/json;charset=utf-8" , encode x)
135
136
136
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)
144
+ ]
145
+ #else
138
146
[ (" application/octet-stream" , a)
139
147
, (" application/json;charset=utf-8" , b)
140
148
, (" text/plain;charset=utf-8" , c)
141
149
]
150
+ #endif
142
151
let acceptH a b c = addToAccept (Proxy :: Proxy OctetStream ) a $
143
- addToAccept (Proxy :: Proxy JSON ) b $
144
- addToAccept (Proxy :: Proxy PlainText ) c " "
152
+ addToAccept (Proxy :: Proxy JSON ) b $
153
+ addToAccept (Proxy :: Proxy PlainText ) c $
154
+ " "
145
155
let val a b c i = handleAcceptH (Proxy :: Proxy '[OctetStream , JSON , PlainText ])
146
156
(acceptH a b c) (i :: Int )
147
- property $ \ a b c i -> fst (fromJust $ val a b c i) == fst (highest a b c)
157
+ property $ \ a b c i ->
158
+ let acc = acceptH a b c
159
+ in counterexample (show acc) $
160
+ fst (fromJust $ val a b c i) === fst (highest a b c)
148
161
149
162
describe " handleCTypeH" $ do
150
163
0 commit comments