From 7529d7f77668c222444b28c27faaca2e67227e4a Mon Sep 17 00:00:00 2001 From: "Julian K. Arni" Date: Thu, 8 Oct 2015 12:09:23 +0200 Subject: [PATCH] getLast (and last missing servant-client test) --- servant-client/test/Servant/ClientSpec.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/servant-client/test/Servant/ClientSpec.hs b/servant-client/test/Servant/ClientSpec.hs index 00caf9b4..4ea5cacf 100644 --- a/servant-client/test/Servant/ClientSpec.hs +++ b/servant-client/test/Servant/ClientSpec.hs @@ -29,7 +29,7 @@ import Control.Monad.Trans.Except import Data.Aeson import Data.Char import Data.Foldable (forM_) -import Data.Monoid +import Data.Monoid hiding (getLast) import Data.Proxy import qualified Data.Text as T import GHC.Generics @@ -166,9 +166,9 @@ sucessSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do let getDeleteEmpty = getNth (Proxy :: Proxy 1) $ client api baseUrl manager (left show <$> runExceptT getDeleteEmpty) `shouldReturn` Right () - {-it "allows content type" $ \(_, baseUrl) -> do-} - {-let getDeleteContentType = getNth (Proxy :: Proxy 14) $ client api baseUrl manager-} - {-(left show <$> runExceptT getDeleteContentType) `shouldReturn` Right ()-} + it "allows content type" $ \(_, baseUrl) -> do + let getDeleteContentType = getLast $ client api baseUrl manager + (left show <$> runExceptT getDeleteContentType) `shouldReturn` Right () it "Servant.API.Capture" $ \(_, baseUrl) -> do let getCapture = getNth (Proxy :: Proxy 2) $ client api baseUrl manager @@ -350,8 +350,14 @@ class GetNth (n :: Nat) a b | n a -> b where instance GetNth 0 (x :<|> y) x where getNth _ (x :<|> _) = x -{-instance GetNth 0 x x where-} - {-getNth _ = id-} - instance (GetNth (n - 1) x y) => GetNth n (a :<|> x) y where getNth _ (_ :<|> x) = getNth (Proxy :: Proxy (n - 1)) x + +class GetLast a b | a -> b where + getLast :: a -> b + +instance (GetLast b c) => GetLast (a :<|> b) c where + getLast (_ :<|> b) = getLast b + +instance GetLast a a where + getLast a = a