aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-01-20 12:29:48 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-01-20 12:29:48 +0000
commitd5beb20783df5f13357dd6d2a55c48c97da578f4 (patch)
tree6be932afdd75bca3940f3bf6f8c1e7cd789841d2 /spec
parent1b598d96cafa99da25609125da71d31fbab361bb (diff)
downloadthermoprint-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.hs14
-rw-r--r--spec/thermoprint-spec.cabal1
-rw-r--r--spec/thermoprint-spec.nix7
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, (|>), (<|))
20import Data.Text.Lazy (Text) 21import Data.Text.Lazy (Text)
21 22
22import Data.ByteString.Lazy (ByteString) 23import Data.ByteString.Lazy (ByteString)
24import qualified Data.ByteString.Lazy as LBS (toStrict)
23 25
24import GHC.Generics (Generic) 26import GHC.Generics (Generic)
25import Control.DeepSeq (NFData) 27import Control.DeepSeq (NFData)
26import Data.Aeson (FromJSON(..), ToJSON(..), Value(..)) 28import Data.Aeson (FromJSON(..), ToJSON(..), Value(..))
27import qualified Data.Aeson as JSON (encode, decode) 29import qualified Data.Aeson as JSON (encode, decode, eitherDecodeStrict')
28import Data.Aeson.Types (typeMismatch) 30import Data.Aeson.Types (typeMismatch)
29 31
32import Database.Persist.Class (PersistField(..))
33
30import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary, genericShrink) 34import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary, genericShrink)
31import Test.QuickCheck.Modifiers (NonNegative(..)) 35import Test.QuickCheck.Modifiers (NonNegative(..))
32import Test.QuickCheck.Gen (oneof, scale) 36import Test.QuickCheck.Gen (oneof, scale)
@@ -48,6 +52,9 @@ import Data.Function (on)
48 52
49import Data.Foldable (toList, fold) 53import Data.Foldable (toList, fold)
50 54
55import Data.Bifunctor
56import Control.Monad ((<=<))
57
51import Data.Encoding (encodeLazyByteStringExplicit, decodeLazyByteString) 58import Data.Encoding (encodeLazyByteStringExplicit, decodeLazyByteString)
52import Data.Encoding.UTF8 59import Data.Encoding.UTF8
53import qualified Data.ByteString.Base64.Lazy as Base64 (encode, decode) 60import 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
59type Printout = Seq Paragraph 66type Printout = Seq Paragraph
60 67
68instance 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
62type Paragraph = Seq Chunk 73type 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
131text :: Text -> Either Block Line 141text :: 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}:
5mkDerivation { 6mkDerivation {
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