module Signet.Unstable.Type.IdTest where import qualified Data.ByteString.Char8 as Ascii import qualified Signet.Unstable.Exception.InvalidId as InvalidId import qualified Signet.Unstable.Extra.Tasty as Tasty import qualified Signet.Unstable.Type.Id as Id import Test.Tasty.HUnit ((@?=)) spec :: Tasty.Spec spec :: Spec spec = TestName -> Spec -> Spec Tasty.describe TestName "Signet.Unstable.Type.Id" (Spec -> Spec) -> Spec -> Spec forall a b. (a -> b) -> a -> b $ do TestName -> Spec -> Spec Tasty.describe TestName "parse" (Spec -> Spec) -> Spec -> Spec forall a b. (a -> b) -> a -> b $ do TestName -> Assertion -> Spec Tasty.it TestName "fails with input containing separator" (Assertion -> Spec) -> Assertion -> Spec forall a b. (a -> b) -> a -> b $ do let byteString :: ByteString byteString = TestName -> ByteString Ascii.pack TestName "invalid.id" let result :: Either InvalidId Id result = ByteString -> Either InvalidId Id Id.parse ByteString byteString Either InvalidId Id result Either InvalidId Id -> Either InvalidId Id -> Assertion forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion @?= InvalidId -> Either InvalidId Id forall a b. a -> Either a b Left (ByteString -> InvalidId InvalidId.MkInvalidId ByteString byteString) TestName -> Assertion -> Spec Tasty.it TestName "succeeds with valid input" (Assertion -> Spec) -> Assertion -> Spec forall a b. (a -> b) -> a -> b $ do let byteString :: ByteString byteString = TestName -> ByteString Ascii.pack TestName "valid-id" let result :: Either InvalidId Id result = ByteString -> Either InvalidId Id Id.parse ByteString byteString Either InvalidId Id result Either InvalidId Id -> Either InvalidId Id -> Assertion forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion @?= Id -> Either InvalidId Id forall a b. b -> Either a b Right (ByteString -> Id Id.MkId ByteString byteString) TestName -> Spec -> Spec Tasty.describe TestName "render" (Spec -> Spec) -> Spec -> Spec forall a b. (a -> b) -> a -> b $ do TestName -> Assertion -> Spec Tasty.it TestName "returns the original ByteString" (Assertion -> Spec) -> Assertion -> Spec forall a b. (a -> b) -> a -> b $ do let byteString :: ByteString byteString = TestName -> ByteString Ascii.pack TestName "valid-id" let id_ :: Id id_ = ByteString -> Id Id.MkId ByteString byteString Id -> ByteString Id.render Id id_ ByteString -> ByteString -> Assertion forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion @?= ByteString byteString