A peer-to-peer stack for code collaboration
Add Serialisable instance for more types.
Julian Arni12707c836639
diff --git a/src/Radicle.hs b/src/Radicle.hsindex fd7f685..c9f2627 100644--- a/src/Radicle.hs+++ b/src/Radicle.hs@@ -35,6 +35,8 @@ module Radicle, pattern Ref, pattern Lambda, maybeJson+ , UntaggedValue+ , untag-- *** LangError, LangError(..), LangErrorData(..)diff --git a/src/Radicle/Internal.hs b/src/Radicle/Internal.hsindex aa3ae62..bb3df9b 100644--- a/src/Radicle/Internal.hs+++ b/src/Radicle/Internal.hs@@ -9,6 +9,7 @@ import Prelude (error)import Protoludeimport Language.Haskell.TH.Quote+import Radicle.Internal.Annotation as Ximport Radicle.Internal.CLI as Ximport Radicle.Internal.Core as Ximport Radicle.Internal.Effects as Xdiff --git a/src/Radicle/Internal/Annotation.hs b/src/Radicle/Internal/Annotation.hsindex 38a73eb..03ae057 100644--- a/src/Radicle/Internal/Annotation.hs+++ b/src/Radicle/Internal/Annotation.hs@@ -59,6 +59,8 @@ thisPos = InternalPos (pack (prettyCallStack callStack))data WithPos a = WithPos SrcPos aderiving (Read, Show, Generic, Functor, Foldable, Traversable)+instance Serialise a => Serialise (WithPos a)+-- Ignore source locations when comparing.instance Eq a => Eq (WithPos a) whereWithPos _ x == WithPos _ y = x == ydiff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hsindex 3bd0316..0facf11 100644--- a/src/Radicle/Internal/Core.hs+++ b/src/Radicle/Internal/Core.hs@@ -142,6 +142,8 @@ data ValueF r =| LambdaF [Ident] (NonEmpty r) (Env r)deriving (Eq, Ord, Read, Show, Generic, Functor)+instance Serialise r => Serialise (ValueF r)+{-# COMPLETE Atom, Keyword, String, Number, Boolean, List, Vec, PrimFn, Dict, Ref, Lambda #-}type ValueConC t = (HasCallStack, Ann.Annotation t, Copointed t)diff --git a/test/spec/Radicle/Internal/Arbitrary.hs b/test/spec/Radicle/Internal/Arbitrary.hsindex 675f151..9bea0f6 100644--- a/test/spec/Radicle/Internal/Arbitrary.hs+++ b/test/spec/Radicle/Internal/Arbitrary.hs@@ -45,6 +45,9 @@ instance Arbitrary Value whereisPrimop x = x `elem` Map.keys (getPrimFns prims)isNum x = isJust (readMaybe (toS $ fromIdent x) :: Maybe Scientific)+instance Arbitrary UntaggedValue where+ arbitrary = untag <$> (arbitrary :: Gen Value)+instance Arbitrary Ident wherearbitrary = ((:) <$> firstL <*> rest) `suchThatMap` (mkIdent . toS)wherediff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hsindex 86db288..f0ee195 100644--- a/test/spec/Radicle/Tests.hs+++ b/test/spec/Radicle/Tests.hs@@ -3,6 +3,7 @@ module Radicle.Tests whereimport Protolude hiding (toList)+import Codec.Serialise (Serialise, deserialise, serialise)import Data.List (isInfixOf, isSuffixOf)import qualified Data.Map.Strict as Mapimport Data.Maybe (fromJust)@@ -685,6 +686,26 @@ test_from_to_radicle =<> "\nGot\n\t" <> show gotcounterexample info $ got == expected+test_cbor :: [TestTree]+test_cbor =+ [ testGroup "UntaggedValue"+ [ testForType (Proxy :: Proxy UntaggedValue) ]+ , testGroup "Value"+ [ testForType (Proxy :: Proxy Value) ]+ ]+ where+ testForType+ :: forall a. (Arbitrary a, Show a, Serialise a, Eq a)+ => Proxy a -> TestTree+ testForType _ =+ testProperty "deserialise . serialise == id" $ \(v :: a) -> do+ let expected = v+ got = deserialise (serialise v)+ info = "Expected\n\t" <> show expected+ <> "\nGot\n\t" <> show got+ counterexample info $ got == expected++-- Tests all radicle files 'repl' dir. These should use the 'should-be'-- function to ensure they are in the proper format.test_source_files :: IO TestTree