Browse Source

Remove IsString instance of `Jid'

IsString instances are never supposed to fail, but parsing Strings to
JIDs might. We might do this later with Template Haskell instead, or
something.
master
Jon Kristensen 13 years ago
parent
commit
2ca1ca20bb
  1. 2
      source/Network/Xmpp/Marshal.hs
  2. 3
      source/Network/Xmpp/Types.hs
  3. 6
      tests/Tests.hs

2
source/Network/Xmpp/Marshal.hs

@ -277,4 +277,4 @@ xpJid :: PU Text Jid
xpJid = PU { unpickleTree = \input -> case jidFromText input of xpJid = PU { unpickleTree = \input -> case jidFromText input of
Nothing -> UnpickleError $ ErrorMessage "Could not parse JID." Nothing -> UnpickleError $ ErrorMessage "Could not parse JID."
Just jid -> Result jid Nothing Just jid -> Result jid Nothing
, pickleTree = \input -> pack $ jidToText input } , pickleTree = \input -> jidToText input }

3
source/Network/Xmpp/Types.hs

@ -936,9 +936,6 @@ parseJid s = case jidFromText $ Text.pack s of
Just jid -> jid Just jid -> jid
Nothing -> error $ "Jid value (" ++ s ++ ") did not validate" Nothing -> error $ "Jid value (" ++ s ++ ") did not validate"
instance IsString Jid where
fromString = fromJust . jidFromText . Text.pack
-- | Converts a Text to a JID. -- | Converts a Text to a JID.
jidFromText :: Text -> Maybe Jid jidFromText :: Text -> Maybe Jid
jidFromText t = do jidFromText t = do

6
tests/Tests.hs

@ -28,13 +28,13 @@ import System.Environment
import System.Log.Logger import System.Log.Logger
testUser1 :: Jid testUser1 :: Jid
testUser1 = "echo1@species64739.dyndns.org/bot" testUser1 = parseJid "echo1@species64739.dyndns.org/bot"
testUser2 :: Jid testUser2 :: Jid
testUser2 = "echo2@species64739.dyndns.org/bot" testUser2 = parseJid "echo2@species64739.dyndns.org/bot"
supervisor :: Jid supervisor :: Jid
supervisor = "uart14@species64739.dyndns.org" supervisor = parseJid "uart14@species64739.dyndns.org"
config = def{sessionStreamConfiguration config = def{sessionStreamConfiguration
= def{connectionDetails = UseHost "localhost" (PortNumber 5222)}} = def{connectionDetails = UseHost "localhost" (PortNumber 5222)}}

Loading…
Cancel
Save