File: PersistValueSpec.hs

package info (click to toggle)
haskell-persistent 2.14.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,120 kB
  • sloc: haskell: 12,767; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 1,478 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Database.Persist.PersistValueSpec where

import Test.Hspec
import Database.Persist.PersistValue
import Data.List.NonEmpty (NonEmpty(..), (<|))
import qualified Data.Text as T
import Test.Hspec
import Test.Hspec.QuickCheck
import Test.QuickCheck
import Data.Aeson
import qualified Data.ByteString.Char8 as BS8


spec :: Spec
spec = describe "PersistValueSpec" $ do
    describe "PersistValue" $ do
        describe "Aeson" $ do
            let
                testPrefix constr prefixChar bytes =
                    takePrefix (toJSON (constr (BS8.pack bytes)))
                    ===
                    String (T.singleton prefixChar)
                roundTrip constr bytes =
                    fromJSON (toJSON (constr (BS8.pack bytes)))
                    ===
                    Data.Aeson.Success (constr (BS8.pack bytes))
                subject constr prefixChar = do
                    prop ("encodes with a " ++ [prefixChar] ++ " prefix") $
                        testPrefix constr prefixChar
                    prop "Round Trips" $
                        roundTrip constr

            describe "PersistDbSpecific" $ do
                subject (PersistLiteral_ DbSpecific) 'p'
            describe "PersistLiteral" $ do
                subject PersistLiteral 'l'
            describe "PersistLiteralEscaped" $ do
                subject PersistLiteralEscaped 'e'

takePrefix :: Value -> Value
takePrefix (String a) = String (T.take 1 a)
takePrefix a = a