aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-17 19:21:56 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-17 19:21:56 +0200
commit2b9ceaead3f3cd80e973cccecb9a3eebc51154f7 (patch)
treedf2378943480647606b6a06f62c0f4b8b2ab406d /spec
parentac4cf4a0a494eafe55364f816569c517684fdf32 (diff)
downloadthermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.tar
thermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.tar.gz
thermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.tar.bz2
thermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.tar.xz
thermoprint-2b9ceaead3f3cd80e973cccecb9a3eebc51154f7.zip
Fixes for GHC 8.0.1
Diffstat (limited to 'spec')
-rw-r--r--spec/src/Thermoprint/API.hs32
-rw-r--r--spec/src/Thermoprint/Identifiers.hs8
-rw-r--r--spec/src/Thermoprint/Printout.hs42
-rw-r--r--spec/thermoprint-spec.cabal2
4 files changed, 54 insertions, 30 deletions
diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs
index 9e91487..8e98db8 100644
--- a/spec/src/Thermoprint/API.hs
+++ b/spec/src/Thermoprint/API.hs
@@ -100,12 +100,6 @@ instance Exception PrintingError
100 100
101type DraftTitle = Text 101type DraftTitle = Text
102 102
103instance FromText UTCTime where
104 fromText = parseTimeM True defaultTimeLocale "%F_%T%Q" . T.unpack
105
106instance ToText UTCTime where
107 toText = T.pack . formatTime defaultTimeLocale "%F_%T%Q"
108
109data Range a = Min a | Max a | Through a a 103data Range a = Min a | Max a | Through a a
110 deriving (Show, Eq, Generic) 104 deriving (Show, Eq, Generic)
111 105
@@ -121,17 +115,19 @@ contains (Min min) x = min <= x
121contains (Max max) x = max >= x 115contains (Max max) x = max >= x
122contains (Through min max) x = min <= x && x <= max 116contains (Through min max) x = min <= x && x <= max
123 117
124instance ToText a => ToText (Range a) where 118instance ToHttpApiData a => ToHttpApiData (Range a) where
125 toText (Min min) = toText min <> "-" 119 toUrlPiece (Min min) = toUrlPiece min <> "-"
126 toText (Max max) = "-" <> toText max 120 toUrlPiece (Max max) = "-" <> toUrlPiece max
127 toText (Through min max) = toText min <> "-" <> toText max 121 toUrlPiece (Through min max) = toUrlPiece min <> "-" <> toUrlPiece max
128 122
129instance FromText a => FromText (Range a) where 123instance FromHttpApiData a => FromHttpApiData (Range a) where
130 fromText t = listToMaybe $ through <> max <> min 124 parseUrlPiece t = listToEither $ through <> max <> min
131 where 125 where
132 through = [ Through min max | ((fromText -> Just min), (T.uncons -> Just ('-', (fromText -> Just max)))) <- zip (T.inits t) (T.tails t) ] 126 through = [ Through min max | ((parseUrlPiece -> Right min), (T.uncons -> Just ('-', (parseUrlPiece -> Right max)))) <- zip (T.inits t) (T.tails t) ]
133 min = [ Min min | (fromText -> Just min) <- T.inits t ] 127 min = [ Min min | (parseUrlPiece -> Right min) <- T.inits t ]
134 max = [ Max max | (fromText -> Just max) <- T.tails t ] 128 max = [ Max max | (parseUrlPiece -> Right max) <- T.tails t ]
129 listToEither [x] = Right x
130 listToEither _ = Left t
135 131
136type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus) 132type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus)
137 :<|> "jobs" :> ( 133 :<|> "jobs" :> (
@@ -144,16 +140,16 @@ type ThermoprintAPI = "printers" :> Get '[JSON] (Map PrinterId PrinterStatus)
144 :<|> "job" :> Capture "jobId" JobId :> ( 140 :<|> "job" :> Capture "jobId" JobId :> (
145 Get '[JSON] Printout 141 Get '[JSON] Printout
146 :<|> "status" :> Get '[JSON] JobStatus 142 :<|> "status" :> Get '[JSON] JobStatus
147 :<|> Delete '[PlainText] () 143 :<|> Delete '[JSON] ()
148 ) 144 )
149 :<|> "drafts" :> ( 145 :<|> "drafts" :> (
150 Get '[JSON] (Map DraftId (Maybe DraftTitle)) 146 Get '[JSON] (Map DraftId (Maybe DraftTitle))
151 :<|> QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Post '[JSON] DraftId 147 :<|> QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Post '[JSON] DraftId
152 ) 148 )
153 :<|> "draft" :> Capture "draftId" DraftId :> ( 149 :<|> "draft" :> Capture "draftId" DraftId :> (
154 QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Put '[PlainText] () 150 QueryParam "title" DraftTitle :> ReqBody '[JSON] Printout :> Put '[JSON] ()
155 :<|> Get '[JSON] (Maybe DraftTitle, Printout) 151 :<|> Get '[JSON] (Maybe DraftTitle, Printout)
156 :<|> Delete '[PlainText] () 152 :<|> Delete '[JSON] ()
157 :<|> QueryParam "printer" PrinterId :> Post '[JSON] JobId 153 :<|> QueryParam "printer" PrinterId :> Post '[JSON] JobId
158 ) 154 )
159 155
diff --git a/spec/src/Thermoprint/Identifiers.hs b/spec/src/Thermoprint/Identifiers.hs
index ed8534e..2a07318 100644
--- a/spec/src/Thermoprint/Identifiers.hs
+++ b/spec/src/Thermoprint/Identifiers.hs
@@ -12,17 +12,17 @@ import Data.Typeable (Typeable)
12import GHC.Generics (Generic) 12import GHC.Generics (Generic)
13import Control.DeepSeq (NFData) 13import Control.DeepSeq (NFData)
14 14
15import Servant.API (ToText, FromText) 15import Servant.API (ToHttpApiData, FromHttpApiData)
16import Data.Aeson (FromJSON, ToJSON) 16import Data.Aeson (FromJSON, ToJSON)
17 17
18newtype PrinterId = PrinterId Integer 18newtype PrinterId = PrinterId Integer
19 deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromText, ToText, FromJSON, ToJSON, Typeable, Generic, NFData) 19 deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON, Typeable, Generic, NFData)
20 20
21newtype JobId = JobId Integer 21newtype JobId = JobId Integer
22 deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromText, ToText, FromJSON, ToJSON, Typeable, Generic, NFData) 22 deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON, Typeable, Generic, NFData)
23 23
24newtype DraftId = DraftId Integer 24newtype DraftId = DraftId Integer
25 deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromText, ToText, FromJSON, ToJSON, Typeable, Generic, NFData) 25 deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON, Typeable, Generic, NFData)
26 26
27castId :: (Integral a, Enum b) => a -> b 27castId :: (Integral a, Enum b) => a -> b
28castId = toEnum . fromInteger . toInteger 28castId = toEnum . fromInteger . toInteger
diff --git a/spec/src/Thermoprint/Printout.hs b/spec/src/Thermoprint/Printout.hs
index 2be0a83..8c33e07 100644
--- a/spec/src/Thermoprint/Printout.hs
+++ b/spec/src/Thermoprint/Printout.hs
@@ -1,6 +1,6 @@
1{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} 1{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
2{-# LANGUAGE OverloadedStrings #-} 2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} 3{-# LANGUAGE FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
4{-# OPTIONS_HADDOCK show-extensions #-} 4{-# OPTIONS_HADDOCK show-extensions #-}
5 5
6-- | 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
@@ -63,19 +63,47 @@ import Prelude hiding (fold)
63 63
64 64
65-- | A 'Printout' is a sequence of visually seperated 'Paragraph's 65-- | A 'Printout' is a sequence of visually seperated 'Paragraph's
66type Printout = Seq Paragraph 66newtype Printout = Printout { getParagraphs :: Seq Paragraph }
67 deriving (Show, Generic, NFData)
68
69instance Eq Paragraph => Eq Printout where
70 (==) = (==) `on` getParagraphs
71
72instance Monoid Printout where
73 mempty = Printout mempty
74 mappend a b = Printout $ (mappend `on` getParagraphs) a b
75
76instance FromJSON Printout where
77 parseJSON = fmap Printout . parseJSON
78
79instance ToJSON Printout where
80 toJSON = toJSON . getParagraphs
81
82instance Arbitrary Printout where
83 arbitrary = Printout <$> arbitrary
67 84
68-- | A 'Paragraph' is a non-seperated sequence of 'Chunk's 85-- | A 'Paragraph' is a non-seperated sequence of 'Chunk's
69type Paragraph = Seq Chunk 86newtype Paragraph = Paragraph { getChunks :: Seq Chunk }
87 deriving (Show, Generic, NFData)
88
89instance Eq Chunk => Eq Paragraph where
90 (==) = (==) `on` getChunks
91
92instance Monoid Paragraph where
93 mempty = Paragraph mempty
94 mappend a b = Paragraph $ (mappend `on` getChunks) a b
95
96instance Arbitrary Paragraph where
97 arbitrary = Paragraph <$> arbitrary
70 98
71instance FromJSON Paragraph where 99instance FromJSON Paragraph where
72 parseJSON o@(Array _) = Seq.fromList <$> parseJSON o 100 parseJSON o@(Array _) = Paragraph . Seq.fromList <$> parseJSON o
73 parseJSON o@(Object _) = Seq.singleton <$> parseJSON o 101 parseJSON o@(Object _) = Paragraph . Seq.singleton <$> parseJSON o
74 parseJSON o@(String _) = Seq.singleton <$> parseJSON o 102 parseJSON o@(String _) = Paragraph . Seq.singleton <$> parseJSON o
75 parseJSON v = typeMismatch "Paragraph" v 103 parseJSON v = typeMismatch "Paragraph" v
76 104
77instance ToJSON Paragraph where 105instance ToJSON Paragraph where
78 toJSON cs 106 toJSON (Paragraph cs)
79 | (a :< as) <- viewl cs 107 | (a :< as) <- viewl cs
80 , Seq.null as = toJSON a 108 , Seq.null as = toJSON a
81 | otherwise = toJSON $ toList cs 109 | otherwise = toJSON $ toList cs
diff --git a/spec/thermoprint-spec.cabal b/spec/thermoprint-spec.cabal
index e236e05..28680fb 100644
--- a/spec/thermoprint-spec.cabal
+++ b/spec/thermoprint-spec.cabal
@@ -2,7 +2,7 @@
2-- documentation, see http://haskell.org/cabal/users-guide/ 2-- documentation, see http://haskell.org/cabal/users-guide/
3 3
4name: thermoprint-spec 4name: thermoprint-spec
5version: 3.0.0 5version: 4.0.0
6synopsis: A specification of the API and the payload datatypes and associated utilities 6synopsis: A specification of the API and the payload datatypes and associated utilities
7-- description: 7-- description:
8homepage: http://dirty-haskell.org/tags/thermoprint.html 8homepage: http://dirty-haskell.org/tags/thermoprint.html