Fix distinctOn test, split it into two.
This commit is contained in:
parent
1e07c9f904
commit
11555a9095
23
test/Test.hs
23
test/Test.hs
@ -18,6 +18,7 @@
|
|||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
import Control.Applicative ((<$>))
|
import Control.Applicative ((<$>))
|
||||||
|
import Control.Arrow ((&&&))
|
||||||
import Control.Exception (IOException)
|
import Control.Exception (IOException)
|
||||||
import Control.Monad (replicateM, replicateM_)
|
import Control.Monad (replicateM, replicateM_)
|
||||||
import Control.Monad.IO.Class (MonadIO(liftIO))
|
import Control.Monad.IO.Class (MonadIO(liftIO))
|
||||||
@ -810,6 +811,20 @@ main = do
|
|||||||
#if defined(WITH_POSTGRESQL)
|
#if defined(WITH_POSTGRESQL)
|
||||||
describe "SELECT DISTINCT ON" $ do
|
describe "SELECT DISTINCT ON" $ do
|
||||||
it "works on a simple example" $ do
|
it "works on a simple example" $ do
|
||||||
|
run $ do
|
||||||
|
[p1k, p2k, _] <- mapM insert [p1, p2, p3]
|
||||||
|
[_, bpB, bpC] <- mapM insert'
|
||||||
|
[ BlogPost "A" p1k
|
||||||
|
, BlogPost "B" p1k
|
||||||
|
, BlogPost "C" p2k ]
|
||||||
|
ret <- select $
|
||||||
|
from $ \bp ->
|
||||||
|
distinctOn [bp ^. BlogPostAuthorId] $ do
|
||||||
|
orderBy [asc (bp ^. BlogPostAuthorId), desc (bp ^. BlogPostTitle)]
|
||||||
|
return bp
|
||||||
|
liftIO $ ret `shouldBe` sortBy (comparing (blogPostAuthorId . entityVal)) [bpB, bpC]
|
||||||
|
|
||||||
|
it "works on a slightly less simple example" $ do
|
||||||
run $ do
|
run $ do
|
||||||
[p1k, p2k, _] <- mapM insert [p1, p2, p3]
|
[p1k, p2k, _] <- mapM insert [p1, p2, p3]
|
||||||
[bpA, bpB, bpC] <- mapM insert'
|
[bpA, bpB, bpC] <- mapM insert'
|
||||||
@ -818,10 +833,12 @@ main = do
|
|||||||
, BlogPost "C" p2k ]
|
, BlogPost "C" p2k ]
|
||||||
ret <- select $
|
ret <- select $
|
||||||
from $ \bp ->
|
from $ \bp ->
|
||||||
distinctOn [bp ^. BlogPostAuthorId, bp ^. BlogPostTitle] $ do
|
distinctOn [bp ^. BlogPostAuthorId] $
|
||||||
orderBy [asc (bp ^. BlogPostAuthorId), desc (bp ^. BlogPostTitle)]
|
distinctOn [bp ^. BlogPostTitle] $ do
|
||||||
|
orderBy [asc (bp ^. BlogPostAuthorId), asc (bp ^. BlogPostTitle)]
|
||||||
return bp
|
return bp
|
||||||
liftIO $ ret `shouldBe` sortBy (comparing (blogPostAuthorId . entityVal)) [bpB, bpC]
|
let cmp = (blogPostAuthorId &&& blogPostTitle) . entityVal
|
||||||
|
liftIO $ ret `shouldBe` sortBy (comparing cmp) [bpA, bpB, bpC]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
describe "coalesce/coalesceDefault" $ do
|
describe "coalesce/coalesceDefault" $ do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user