dbus-qq 0.0.2 → 0.1.0
raw patch · 4 files changed
+105/−92 lines, 4 filesdep +QuickCheckdep +dbusdep +dbus-qqdep −dbus-coredep ~basedep ~containersPVP ok
version bump matches the API change (PVP)
Dependencies added: QuickCheck, dbus, dbus-qq
Dependencies removed: dbus-core
Dependency ranges changed: base, containers
API changes (from Hackage documentation)
Files
- DBus/QuasiQuoter.hs +16/−16
- Tests.hs +0/−70
- dbus-qq.cabal +19/−6
- tests/Tests.hs +70/−0
DBus/QuasiQuoter.hs view
@@ -11,15 +11,15 @@ import Data.Maybe (fromJust) import Data.Word import Data.Int-import qualified DBus.Types as DT+import qualified DBus import Language.Haskell.TH import Language.Haskell.TH.Quote import Text.ParserCombinators.Parsec hiding ((<|>), many) data DBusFunction = DBusFunction [Type] [Type] --- |A quasi-quoter to convert a function of type @['DT.Variant'] ->--- ['DT.Variant']@ into a function of a specified static type.+-- |A quasi-quoter to convert a function of type @['DBus.Variant'] ->+-- ['DBus.Variant']@ into a function of a specified static type. -- -- This quasi-quoter takes a signature of the form: --@@ -30,11 +30,11 @@ -- Types on the left of the arrow correspond to argument types, while those on -- the right are return types. ----- The result is a combinator which takes any function of type ['DT.Variant'] ->--- ['DT.Variant'], assumes that its arguments and results are of the specified+-- The result is a combinator which takes any function of type ['DBus.Variant'] ->+-- ['DBus.Variant'], assumes that its arguments and results are of the specified -- number and types, and returns a function of the corresponding static type. ----- For example, if @f :: ['DT.Variant'] -> ['DT.Variant']@,+-- For example, if @f :: ['DBus.Variant'] -> ['DBus.Variant']@, -- -- @ -- ['dbus'| i s -> s a{uv} |] f@@ -43,7 +43,7 @@ -- has type -- -- @--- Int -> String -> (String, 'Map.Map' 'Word32' 'DT.Variant')+-- Int -> String -> (String, 'Map.Map' 'Word32' 'DBus.Variant') -- @ dbus :: QuasiQuoter dbus = QuasiQuoter@@ -54,7 +54,7 @@ } -- |A generalized version of the 'dbus' quasi-quoter which works on functions of--- type @['DT.Variant'] -> f ['DT.Variant']@, for any 'Functor' @f@.+-- type @['DBus.Variant'] -> f ['DBus.Variant']@, for any 'Functor' @f@. dbusF :: QuasiQuoter dbusF = QuasiQuoter { quoteExp = expQuoter True@@ -99,9 +99,9 @@ (char 't' *> return (ConT ''Word64)) <|> (char 'd' *> return (ConT ''Double)) <|> (char 's' *> return (ConT ''String)) <|>- (char 'o' *> return (ConT ''DT.ObjectPath)) <|>- (char 'g' *> return (ConT ''DT.Signature)) <|>- (char 'v' *> return (ConT ''DT.Variant)) <|>+ (char 'o' *> return (ConT ''DBus.ObjectPath)) <|>+ (char 'g' *> return (ConT ''DBus.Signature)) <|>+ (char 'v' *> return (ConT ''DBus.Variant)) <|> array <|> struct @@ -120,16 +120,16 @@ thToVariant :: Type -> Name -> Exp thToVariant t name =- VarE 'DT.toVariant `AppE` (VarE name `SigE` t)+ VarE 'DBus.toVariant `AppE` (VarE name `SigE` t) thFromVariant :: Bool -> [Type] -> Exp -> Q Exp-thFromVariant functor ts exp =+thFromVariant functor ts expr = if functor- then [| fmap $(unpack) $(return exp) |]- else [| $(unpack) $(return exp) |]+ then [| fmap $(unpack) $(return expr) |]+ else [| $(unpack) $(return expr) |] where n = length ts- convert t = [| \x -> (fromJust $ DT.fromVariant x) :: $(return t) |]+ convert t = [| \x -> (fromJust $ DBus.fromVariant x) :: $(return t) |] apply fs = do xs <- replicateM n $ newName "x" return . LamE [TupP (map VarP xs)] . TupE $
− Tests.hs
@@ -1,70 +0,0 @@-{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}--import DBus.QuasiQuoter-import DBus.Types-import Data.Int-import qualified Data.Map as Map-import Data.Maybe-import Data.Word-import Test.QuickCheck-import Text.Printf--main :: IO ()-main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests--prop_simple x y = show (x + y) == [dbus| i i -> s |] f x y- where- f :: [Variant] -> [Variant]- f xs = [toVariant . show . sum $ (map (fromJust . fromVariant) xs :: [Int32])]--prop_nospaces x y = show (x + y) == [dbus|ii->s|] f x y- where- f :: [Variant] -> [Variant]- f xs = [toVariant . show . sum $ (map (fromJust . fromVariant) xs :: [Int32])]--prop_spaces x y = show (x + y) == [dbus| ii-> s |] f x y- where- f :: [Variant] -> [Variant]- f xs = [toVariant . show . sum $ (map (fromJust . fromVariant) xs :: [Int32])]--prop_functor x y = Just (show (x + y)) == [dbusF| i i -> s |] f x y- where- f :: [Variant] -> Maybe [Variant]- f xs = Just [toVariant . show . sum $ (map (fromJust . fromVariant) xs :: [Int32])]--prop_maps = Map.empty == [dbus| a{su} -> a{on} |] f Map.empty- where- f :: [Variant] -> [Variant]- f _ = [toVariant (Map.empty :: Map.Map ObjectPath Int16)]--prop_tuples x y = show x ++ y == [dbus| (is) -> s |] f (x, y)- where- f :: [Variant] -> [Variant]- f [x] =- let (n, s) = fromJust (fromVariant x) :: (Int32, String)- in [toVariant $ show n ++ s]--prop_retvals x = (x, x) == [dbus| i -> ii |] f x- where- f :: [Variant] -> [Variant]- f [x] = [x, x]--prop_values x = x * 2 == [dbus| -> i |] f- where- f :: [Variant] -> [Variant]- f _ = [toVariant (x * 2)]--prop_unit x = () == [dbus| s -> |] f x- where- f :: [Variant] -> [Variant]- f _ = []--tests = [("simple", quickCheck prop_simple)- ,("functor", quickCheck prop_functor)- ,("maps", quickCheck prop_maps)- ,("tuples", quickCheck prop_tuples)- ,("retvals", quickCheck prop_retvals)- ,("values", quickCheck prop_values)- ,("unit", quickCheck prop_unit)- ,("no spaces", quickCheck prop_nospaces)- ,("spaces", quickCheck prop_spaces)]
dbus-qq.cabal view
@@ -1,5 +1,5 @@ Name: dbus-qq-Version: 0.0.2+Version: 0.1.0 Synopsis: Quasi-quoter for DBus functions Description: This package contains a quasi-quoter to automatically convert functions of the form @[Variant] -> [Variant]@ to functions of the actual types, returning a tuple of the results. License: BSD3@@ -9,13 +9,26 @@ Category: Network Build-type: Simple Cabal-version: >=1.8-Extra-source-files: Tests.hs +Source-repository head+ type: git+ location: git://github.com/pcapriotti/dbus-qq.git+ Library Exposed-modules: DBus.QuasiQuoter- Build-depends: base (== 4.*), parsec (== 3.1.*), dbus-core (== 0.9.*), template-haskell, containers (< 0.5)+ Build-depends: base >= 4.5 && < 4.7+ , parsec == 3.1.*+ , dbus == 0.10.*+ , containers >= 0.4 && < 0.6+ , template-haskell Extensions: TemplateHaskell, QuasiQuotes -Source-repository head- type: git- location: git://github.com/pcapriotti/dbus-qq.git+test-suite tests+ type: exitcode-stdio-1.0+ hs-source-dirs: tests+ main-is: Tests.hs+ build-depends: base >= 4.5 && < 4.7+ , dbus-qq+ , QuickCheck == 2.5.*+ , dbus == 0.10.*+ , containers >= 0.4 && < 0.6
+ tests/Tests.hs view
@@ -0,0 +1,70 @@+{-# LANGUAGE QuasiQuotes #-}++import DBus.QuasiQuoter+import DBus+import Data.Int+import qualified Data.Map as Map+import Data.Maybe+import Data.Word+import Test.QuickCheck+import Text.Printf++main :: IO ()+main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests++prop_simple x y = show (x + y) == [dbus| i i -> s |] f x y+ where+ f :: [Variant] -> [Variant]+ f xs = [toVariant . show . sum $ (map (fromJust . fromVariant) xs :: [Int32])]++prop_nospaces x y = show (x + y) == [dbus|ii->s|] f x y+ where+ f :: [Variant] -> [Variant]+ f xs = [toVariant . show . sum $ (map (fromJust . fromVariant) xs :: [Int32])]++prop_spaces x y = show (x + y) == [dbus| ii-> s |] f x y+ where+ f :: [Variant] -> [Variant]+ f xs = [toVariant . show . sum $ (map (fromJust . fromVariant) xs :: [Int32])]++prop_functor x y = Just (show (x + y)) == [dbusF| i i -> s |] f x y+ where+ f :: [Variant] -> Maybe [Variant]+ f xs = Just [toVariant . show . sum $ (map (fromJust . fromVariant) xs :: [Int32])]++prop_maps = Map.empty == [dbus| a{su} -> a{on} |] f Map.empty+ where+ f :: [Variant] -> [Variant]+ f _ = [toVariant (Map.empty :: Map.Map ObjectPath Int16)]++prop_tuples x y = show x ++ y == [dbus| (is) -> s |] f (x, y)+ where+ f :: [Variant] -> [Variant]+ f [x] =+ let (n, s) = fromJust (fromVariant x) :: (Int32, String)+ in [toVariant $ show n ++ s]++prop_retvals x = (x, x) == [dbus| i -> ii |] f x+ where+ f :: [Variant] -> [Variant]+ f [x] = [x, x]++prop_values x = x * 2 == [dbus| -> i |] f+ where+ f :: [Variant] -> [Variant]+ f _ = [toVariant (x * 2)]++prop_unit x = () == [dbus| s -> |] f x+ where+ f :: [Variant] -> [Variant]+ f _ = []++tests = [("simple", quickCheck prop_simple)+ ,("functor", quickCheck prop_functor)+ ,("maps", quickCheck prop_maps)+ ,("tuples", quickCheck prop_tuples)+ ,("retvals", quickCheck prop_retvals)+ ,("values", quickCheck prop_values)+ ,("unit", quickCheck prop_unit)+ ,("no spaces", quickCheck prop_nospaces)+ ,("spaces", quickCheck prop_spaces)]