diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-20 12:29:48 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-20 12:29:48 +0000 |
commit | d5beb20783df5f13357dd6d2a55c48c97da578f4 (patch) | |
tree | 6be932afdd75bca3940f3bf6f8c1e7cd789841d2 /spec | |
parent | 1b598d96cafa99da25609125da71d31fbab361bb (diff) | |
download | thermoprint-d5beb20783df5f13357dd6d2a55c48c97da578f4.tar thermoprint-d5beb20783df5f13357dd6d2a55c48c97da578f4.tar.gz thermoprint-d5beb20783df5f13357dd6d2a55c48c97da578f4.tar.bz2 thermoprint-d5beb20783df5f13357dd6d2a55c48c97da578f4.tar.xz thermoprint-d5beb20783df5f13357dd6d2a55c48c97da578f4.zip |
Store Printouts in persistent-dbs
Diffstat (limited to 'spec')
-rw-r--r-- | spec/src/Thermoprint/Printout.hs | 14 | ||||
-rw-r--r-- | spec/thermoprint-spec.cabal | 1 | ||||
-rw-r--r-- | spec/thermoprint-spec.nix | 7 |
3 files changed, 17 insertions, 5 deletions
diff --git a/spec/src/Thermoprint/Printout.hs b/spec/src/Thermoprint/Printout.hs index 1106d2f..397a1af 100644 --- a/spec/src/Thermoprint/Printout.hs +++ b/spec/src/Thermoprint/Printout.hs | |||
@@ -1,5 +1,6 @@ | |||
1 | {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} | 1 | {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} |
2 | {-# LANGUAGE OverloadedStrings #-} | 2 | {-# LANGUAGE OverloadedStrings #-} |
3 | {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} | ||
3 | {-# OPTIONS_HADDOCK show-extensions #-} | 4 | {-# OPTIONS_HADDOCK show-extensions #-} |
4 | 5 | ||
5 | -- | This module contains the definition of the structure -- 'Printout' -- used to represent the content of a job | 6 | -- | This module contains the definition of the structure -- 'Printout' -- used to represent the content of a job |
@@ -20,13 +21,16 @@ import Data.Sequence (Seq, (|>), (<|)) | |||
20 | import Data.Text.Lazy (Text) | 21 | import Data.Text.Lazy (Text) |
21 | 22 | ||
22 | import Data.ByteString.Lazy (ByteString) | 23 | import Data.ByteString.Lazy (ByteString) |
24 | import qualified Data.ByteString.Lazy as LBS (toStrict) | ||
23 | 25 | ||
24 | import GHC.Generics (Generic) | 26 | import GHC.Generics (Generic) |
25 | import Control.DeepSeq (NFData) | 27 | import Control.DeepSeq (NFData) |
26 | import Data.Aeson (FromJSON(..), ToJSON(..), Value(..)) | 28 | import Data.Aeson (FromJSON(..), ToJSON(..), Value(..)) |
27 | import qualified Data.Aeson as JSON (encode, decode) | 29 | import qualified Data.Aeson as JSON (encode, decode, eitherDecodeStrict') |
28 | import Data.Aeson.Types (typeMismatch) | 30 | import Data.Aeson.Types (typeMismatch) |
29 | 31 | ||
32 | import Database.Persist.Class (PersistField(..)) | ||
33 | |||
30 | import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary, genericShrink) | 34 | import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary, genericShrink) |
31 | import Test.QuickCheck.Modifiers (NonNegative(..)) | 35 | import Test.QuickCheck.Modifiers (NonNegative(..)) |
32 | import Test.QuickCheck.Gen (oneof, scale) | 36 | import Test.QuickCheck.Gen (oneof, scale) |
@@ -48,6 +52,9 @@ import Data.Function (on) | |||
48 | 52 | ||
49 | import Data.Foldable (toList, fold) | 53 | import Data.Foldable (toList, fold) |
50 | 54 | ||
55 | import Data.Bifunctor | ||
56 | import Control.Monad ((<=<)) | ||
57 | |||
51 | import Data.Encoding (encodeLazyByteStringExplicit, decodeLazyByteString) | 58 | import Data.Encoding (encodeLazyByteStringExplicit, decodeLazyByteString) |
52 | import Data.Encoding.UTF8 | 59 | import Data.Encoding.UTF8 |
53 | import qualified Data.ByteString.Base64.Lazy as Base64 (encode, decode) | 60 | import qualified Data.ByteString.Base64.Lazy as Base64 (encode, decode) |
@@ -58,6 +65,10 @@ import Prelude hiding (fold) | |||
58 | -- | A 'Printout' is a sequence of visually seperated 'Paragraph's | 65 | -- | A 'Printout' is a sequence of visually seperated 'Paragraph's |
59 | type Printout = Seq Paragraph | 66 | type Printout = Seq Paragraph |
60 | 67 | ||
68 | instance PersistField Printout where | ||
69 | toPersistValue = toPersistValue . LBS.toStrict . JSON.encode | ||
70 | fromPersistValue = first T.pack . JSON.eitherDecodeStrict' <=< fromPersistValue | ||
71 | |||
61 | -- | A 'Paragraph' is a non-seperated sequence of 'Chunk's | 72 | -- | A 'Paragraph' is a non-seperated sequence of 'Chunk's |
62 | type Paragraph = Seq Chunk | 73 | type Paragraph = Seq Chunk |
63 | 74 | ||
@@ -127,7 +138,6 @@ instance Monoid Line where | |||
127 | | otherwise = JuxtaPos (x <| ys) | 138 | | otherwise = JuxtaPos (x <| ys) |
128 | x `mappend` y = JuxtaPos $ Seq.fromList [x, y] | 139 | x `mappend` y = JuxtaPos $ Seq.fromList [x, y] |
129 | 140 | ||
130 | |||
131 | text :: Text -> Either Block Line | 141 | text :: Text -> Either Block Line |
132 | -- ^ Smart constructor for 'Line'/'Block' which maps word and line boundaries (as determined by 'isSpace' and '(== '\n')' respectively) to the structure of 'Block' and 'Line'. | 142 | -- ^ Smart constructor for 'Line'/'Block' which maps word and line boundaries (as determined by 'isSpace' and '(== '\n')' respectively) to the structure of 'Block' and 'Line'. |
133 | -- | 143 | -- |
diff --git a/spec/thermoprint-spec.cabal b/spec/thermoprint-spec.cabal index da79ee8..942cbe4 100644 --- a/spec/thermoprint-spec.cabal +++ b/spec/thermoprint-spec.cabal | |||
@@ -44,6 +44,7 @@ library | |||
44 | , aeson >=0.9.0 && <1 | 44 | , aeson >=0.9.0 && <1 |
45 | , base64-bytestring >=1.0.0 && <2 | 45 | , base64-bytestring >=1.0.0 && <2 |
46 | , encoding >=0.8 && <1 | 46 | , encoding >=0.8 && <1 |
47 | , persistent >=2.2 && <3 | ||
47 | -- hs-source-dirs: | 48 | -- hs-source-dirs: |
48 | default-language: Haskell2010 | 49 | default-language: Haskell2010 |
49 | 50 | ||
diff --git a/spec/thermoprint-spec.nix b/spec/thermoprint-spec.nix index 1825ddd..6d94ef6 100644 --- a/spec/thermoprint-spec.nix +++ b/spec/thermoprint-spec.nix | |||
@@ -1,6 +1,7 @@ | |||
1 | { mkDerivation, aeson, base, base64-bytestring, bytestring, Cabal | 1 | { mkDerivation, aeson, base, base64-bytestring, bytestring, Cabal |
2 | , cabal-test-quickcheck, containers, deepseq, encoding, hspec | 2 | , cabal-test-quickcheck, containers, deepseq, encoding, hspec |
3 | , QuickCheck, quickcheck-instances, servant, stdenv, text | 3 | , persistent, QuickCheck, quickcheck-instances, servant, stdenv |
4 | , text | ||
4 | }: | 5 | }: |
5 | mkDerivation { | 6 | mkDerivation { |
6 | pname = "thermoprint-spec"; | 7 | pname = "thermoprint-spec"; |
@@ -8,8 +9,8 @@ mkDerivation { | |||
8 | src = ./.; | 9 | src = ./.; |
9 | libraryHaskellDepends = [ | 10 | libraryHaskellDepends = [ |
10 | aeson base base64-bytestring bytestring Cabal cabal-test-quickcheck | 11 | aeson base base64-bytestring bytestring Cabal cabal-test-quickcheck |
11 | containers deepseq encoding QuickCheck quickcheck-instances servant | 12 | containers deepseq encoding persistent QuickCheck |
12 | text | 13 | quickcheck-instances servant text |
13 | ]; | 14 | ]; |
14 | testHaskellDepends = [ | 15 | testHaskellDepends = [ |
15 | aeson base hspec QuickCheck quickcheck-instances | 16 | aeson base hspec QuickCheck quickcheck-instances |