diff --git a/parsers/src/bind.rs b/parsers/src/bind.rs
index 127eb4f..f4f2bdf 100644
--- a/parsers/src/bind.rs
+++ b/parsers/src/bind.rs
@@ -170,11 +170,14 @@ mod tests {
//assert_eq!(bind.resource.unwrap(), "HelloTM");
assert_eq!(bind.resource.unwrap(), "Hello™");
- let elem: Element = "coucou@linkmauve.fr/HelloTM"
+ let elem: Element = "coucou@linkmauve.fr/Hello™"
.parse()
.unwrap();
let bind = BindResponse::try_from(elem).unwrap();
- assert_eq!(bind.jid, FullJid::new("coucou", "linkmauve.fr", "HelloTM"));
+ assert_eq!(
+ bind.jid,
+ FullJid::new("coucou@linkmauve.fr/HelloTM").unwrap()
+ );
}
#[cfg(not(feature = "disable-validation"))]
diff --git a/parsers/src/blocking.rs b/parsers/src/blocking.rs
index 246a715..7d1fad0 100644
--- a/parsers/src/blocking.rs
+++ b/parsers/src/blocking.rs
@@ -98,7 +98,6 @@ generate_empty_element!(
#[cfg(test)]
mod tests {
use super::*;
- use jid::BareJid;
#[cfg(target_pointer_width = "32")]
#[test]
@@ -141,14 +140,8 @@ mod tests {
fn test_items() {
let elem: Element = " ".parse().unwrap();
let two_items = vec![
- Jid::Bare(BareJid {
- node: Some(String::from("coucou")),
- domain: String::from("coucou"),
- }),
- Jid::Bare(BareJid {
- node: None,
- domain: String::from("domain"),
- }),
+ Jid::new("coucou@coucou").unwrap(),
+ Jid::new("domain").unwrap(),
];
let result_elem = elem.clone();
diff --git a/parsers/src/bookmarks.rs b/parsers/src/bookmarks.rs
index 6276d2b..182c696 100644
--- a/parsers/src/bookmarks.rs
+++ b/parsers/src/bookmarks.rs
@@ -112,7 +112,7 @@ mod tests {
assert_eq!(storage.conferences[0].autojoin, Autojoin::True);
assert_eq!(
storage.conferences[0].jid,
- BareJid::new("test-muc", "muc.localhost")
+ BareJid::new("test-muc@muc.localhost").unwrap()
);
assert_eq!(storage.conferences[0].clone().name.unwrap(), "Test MUC");
assert_eq!(storage.conferences[0].clone().nick.unwrap(), "Coucou");
diff --git a/parsers/src/delay.rs b/parsers/src/delay.rs
index 897b98c..cf0012d 100644
--- a/parsers/src/delay.rs
+++ b/parsers/src/delay.rs
@@ -57,7 +57,7 @@ mod tests {
.parse()
.unwrap();
let delay = Delay::try_from(elem).unwrap();
- assert_eq!(delay.from.unwrap(), BareJid::domain("capulet.com"));
+ assert_eq!(delay.from.unwrap(), BareJid::new("capulet.com").unwrap());
assert_eq!(
delay.stamp,
DateTime::from_str("2002-09-10T23:08:25Z").unwrap()
@@ -109,7 +109,7 @@ mod tests {
fn test_serialise_data() {
let elem: Element = "Reason".parse().unwrap();
let delay = Delay {
- from: Some(Jid::Bare(BareJid::new("juliet", "example.org"))),
+ from: Some(Jid::new("juliet@example.org").unwrap()),
stamp: DateTime::from_str("2002-09-10T23:08:25Z").unwrap(),
data: Some(String::from("Reason")),
};
diff --git a/parsers/src/disco.rs b/parsers/src/disco.rs
index 41df4f7..6625141 100644
--- a/parsers/src/disco.rs
+++ b/parsers/src/disco.rs
@@ -445,10 +445,10 @@ mod tests {
let elem2 = Element::from(query);
let query = DiscoItemsResult::try_from(elem2).unwrap();
assert_eq!(query.items.len(), 2);
- assert_eq!(query.items[0].jid, BareJid::domain("component"));
+ assert_eq!(query.items[0].jid, BareJid::new("component").unwrap());
assert_eq!(query.items[0].node, None);
assert_eq!(query.items[0].name, None);
- assert_eq!(query.items[1].jid, BareJid::domain("component2"));
+ assert_eq!(query.items[1].jid, BareJid::new("component2").unwrap());
assert_eq!(query.items[1].node, Some(String::from("test")));
assert_eq!(query.items[1].name, Some(String::from("A component")));
}
diff --git a/parsers/src/jid_prep.rs b/parsers/src/jid_prep.rs
index f04a872..d37f507 100644
--- a/parsers/src/jid_prep.rs
+++ b/parsers/src/jid_prep.rs
@@ -75,7 +75,7 @@ mod tests {
let response = JidPrepResponse::try_from(elem).unwrap();
assert_eq!(
response.jid,
- FullJid::new("romeo", "montague.lit", "orchard")
+ FullJid::new("romeo@montague.lit/orchard").unwrap()
);
}
}
diff --git a/parsers/src/jingle_s5b.rs b/parsers/src/jingle_s5b.rs
index 5d8b426..bbc845b 100644
--- a/parsers/src/jingle_s5b.rs
+++ b/parsers/src/jingle_s5b.rs
@@ -276,7 +276,6 @@ impl From for Element {
#[cfg(test)]
mod tests {
use super::*;
- use jid::BareJid;
use std::str::FromStr;
#[cfg(target_pointer_width = "32")]
@@ -344,7 +343,7 @@ mod tests {
payload: TransportPayload::Candidates(vec![Candidate {
cid: CandidateId(String::from("coucou")),
host: IpAddr::from_str("127.0.0.1").unwrap(),
- jid: Jid::Bare(BareJid::new("coucou", "coucou")),
+ jid: Jid::new("coucou@coucou").unwrap(),
port: None,
priority: 0u32,
type_: Type::Direct,
diff --git a/parsers/src/lib.rs b/parsers/src/lib.rs
index 6919a9b..ffa4952 100644
--- a/parsers/src/lib.rs
+++ b/parsers/src/lib.rs
@@ -24,7 +24,7 @@
#![warn(missing_docs)]
pub use crate::util::error::Error;
-pub use jid::{BareJid, FullJid, Jid, JidParseError};
+pub use jid::{BareJid, Error as JidParseError, FullJid, Jid};
pub use minidom::Element;
/// XML namespace definitions used through XMPP.
diff --git a/parsers/src/mam_prefs.rs b/parsers/src/mam_prefs.rs
index 76bfe8e..589809e 100644
--- a/parsers/src/mam_prefs.rs
+++ b/parsers/src/mam_prefs.rs
@@ -88,7 +88,7 @@ fn serialise_jid_list(name: &str, jids: Vec) -> ::std::option::IntoIter for Element {
#[cfg(test)]
mod tests {
use super::*;
- use jid::BareJid;
use std::str::FromStr;
#[cfg(target_pointer_width = "32")]
@@ -378,7 +377,7 @@ mod tests {
let elem: Element = "Hello world!".parse().unwrap();
#[cfg(feature = "component")]
let elem: Element = "Hello world!".parse().unwrap();
- let mut message = Message::new(Jid::Bare(BareJid::new("coucou", "example.org")));
+ let mut message = Message::new(Jid::new("coucou@example.org").unwrap());
message
.bodies
.insert(String::from(""), Body::from_str("Hello world!").unwrap());
diff --git a/parsers/src/muc/user.rs b/parsers/src/muc/user.rs
index d6657ba..a60cc36 100644
--- a/parsers/src/muc/user.rs
+++ b/parsers/src/muc/user.rs
@@ -301,7 +301,7 @@ mod tests {
use super::*;
use crate::message::Message;
use crate::presence::{Presence, Type as PresenceType};
- use crate::{BareJid, Jid};
+ use crate::Jid;
#[test]
fn test_simple() {
@@ -743,7 +743,7 @@ mod tests {
#[test]
fn message_payload() {
- let jid: Jid = Jid::Bare(BareJid::new("louise", "example.com"));
+ let jid: Jid = Jid::new("louise@example.com").unwrap();
let elem: Element = ""
.parse()
.unwrap();
diff --git a/parsers/src/presence.rs b/parsers/src/presence.rs
index 7ceb20c..bb8ee87 100644
--- a/parsers/src/presence.rs
+++ b/parsers/src/presence.rs
@@ -672,24 +672,21 @@ mod tests {
let elem: Element = presence.into();
assert_eq!(elem.attr("to"), None);
- let presence = Presence::new(Type::None).with_to(Jid::Bare(BareJid::domain("localhost")));
+ let presence = Presence::new(Type::None).with_to(Jid::new("localhost").unwrap());
let elem: Element = presence.into();
assert_eq!(elem.attr("to"), Some("localhost"));
- let presence = Presence::new(Type::None).with_to(BareJid::domain("localhost"));
+ let presence = Presence::new(Type::None).with_to(BareJid::new("localhost").unwrap());
let elem: Element = presence.into();
assert_eq!(elem.attr("to"), Some("localhost"));
- let presence = Presence::new(Type::None).with_to(Jid::Full(FullJid::new(
- "test",
- "localhost",
- "coucou",
- )));
+ let presence =
+ Presence::new(Type::None).with_to(Jid::new("test@localhost/coucou").unwrap());
let elem: Element = presence.into();
assert_eq!(elem.attr("to"), Some("test@localhost/coucou"));
let presence =
- Presence::new(Type::None).with_to(FullJid::new("test", "localhost", "coucou"));
+ Presence::new(Type::None).with_to(FullJid::new("test@localhost/coucou").unwrap());
let elem: Element = presence.into();
assert_eq!(elem.attr("to"), Some("test@localhost/coucou"));
}
diff --git a/parsers/src/pubsub/event.rs b/parsers/src/pubsub/event.rs
index c0ab830..aa3b706 100644
--- a/parsers/src/pubsub/event.rs
+++ b/parsers/src/pubsub/event.rs
@@ -273,7 +273,7 @@ mod tests {
assert_eq!(items[0].id, Some(ItemId(String::from("test"))));
assert_eq!(
items[0].publisher.clone().unwrap(),
- BareJid::new("test", "coucou")
+ BareJid::new("test@coucou").unwrap()
);
assert_eq!(items[0].payload, None);
}
@@ -404,7 +404,7 @@ mod tests {
)))
);
assert_eq!(subscription, Some(Subscription::Subscribed));
- assert_eq!(jid.unwrap(), BareJid::new("francisco", "denmark.lit"));
+ assert_eq!(jid.unwrap(), BareJid::new("francisco@denmark.lit").unwrap());
assert_eq!(expiry, Some("2006-02-28T23:59:59Z".parse().unwrap()));
}
_ => panic!(),
diff --git a/parsers/src/pubsub/pubsub.rs b/parsers/src/pubsub/pubsub.rs
index 19f16e0..0fdf648 100644
--- a/parsers/src/pubsub/pubsub.rs
+++ b/parsers/src/pubsub/pubsub.rs
@@ -546,7 +546,6 @@ impl From for Element {
mod tests {
use super::*;
use crate::data_forms::{DataForm, DataFormType, Field, FieldType};
- use jid::FullJid;
#[test]
fn create() {
@@ -746,7 +745,7 @@ mod tests {
let form = DataForm::try_from(elem).unwrap();
let options = Options {
- jid: Jid::Full(FullJid::new("juliet", "capulet.lit", "balcony")),
+ jid: Jid::new("juliet@capulet.lit/balcony").unwrap(),
node: None,
subid: None,
form: Some(form),
diff --git a/parsers/src/roster.rs b/parsers/src/roster.rs
index a461fcb..c6e0266 100644
--- a/parsers/src/roster.rs
+++ b/parsers/src/roster.rs
@@ -167,7 +167,10 @@ mod tests {
let roster = Roster::try_from(elem).unwrap();
assert_eq!(roster.ver, Some(String::from("ver11")));
assert_eq!(roster.items.len(), 4);
- assert_eq!(roster.items[0].jid, BareJid::new("romeo", "example.net"));
+ assert_eq!(
+ roster.items[0].jid,
+ BareJid::new("romeo@example.net").unwrap()
+ );
assert_eq!(roster.items[0].name, Some(String::from("Romeo")));
assert_eq!(roster.items[0].subscription, Subscription::Both);
assert_eq!(roster.items[0].ask, Ask::None);
@@ -176,7 +179,10 @@ mod tests {
vec!(Group::from_str("Friends").unwrap())
);
- assert_eq!(roster.items[3].jid, BareJid::new("contact", "example.org"));
+ assert_eq!(
+ roster.items[3].jid,
+ BareJid::new("contact@example.org").unwrap()
+ );
assert_eq!(roster.items[3].name, Some(String::from("MyContact")));
assert_eq!(roster.items[3].subscription, Subscription::None);
assert_eq!(roster.items[3].ask, Ask::Subscribe);
@@ -195,7 +201,10 @@ mod tests {
let roster = Roster::try_from(elem).unwrap();
assert!(roster.ver.is_none());
assert_eq!(roster.items.len(), 1);
- assert_eq!(roster.items[0].jid, BareJid::new("test", "example.org"));
+ assert_eq!(
+ roster.items[0].jid,
+ BareJid::new("test@example.org").unwrap()
+ );
assert_eq!(roster.items[0].name, None);
assert_eq!(roster.items[0].groups.len(), 2);
assert_eq!(roster.items[0].groups[0], Group::from_str("A").unwrap());
@@ -225,7 +234,10 @@ mod tests {
let roster = Roster::try_from(elem).unwrap();
assert!(roster.ver.is_none());
assert_eq!(roster.items.len(), 1);
- assert_eq!(roster.items[0].jid, BareJid::new("nurse", "example.com"));
+ assert_eq!(
+ roster.items[0].jid,
+ BareJid::new("nurse@example.com").unwrap()
+ );
assert_eq!(roster.items[0].name, Some(String::from("Nurse")));
assert_eq!(roster.items[0].groups.len(), 1);
assert_eq!(
@@ -242,7 +254,10 @@ mod tests {
let roster = Roster::try_from(elem).unwrap();
assert!(roster.ver.is_none());
assert_eq!(roster.items.len(), 1);
- assert_eq!(roster.items[0].jid, BareJid::new("nurse", "example.com"));
+ assert_eq!(
+ roster.items[0].jid,
+ BareJid::new("nurse@example.com").unwrap()
+ );
assert!(roster.items[0].name.is_none());
assert!(roster.items[0].groups.is_empty());
assert_eq!(roster.items[0].subscription, Subscription::Remove);
diff --git a/parsers/src/stanza_id.rs b/parsers/src/stanza_id.rs
index 1187850..eeb5d17 100644
--- a/parsers/src/stanza_id.rs
+++ b/parsers/src/stanza_id.rs
@@ -66,7 +66,7 @@ mod tests {
.unwrap();
let stanza_id = StanzaId::try_from(elem).unwrap();
assert_eq!(stanza_id.id, String::from("coucou"));
- assert_eq!(stanza_id.by, BareJid::new("coucou", "coucou"));
+ assert_eq!(stanza_id.by, BareJid::new("coucou@coucou").unwrap());
let elem: Element = ""
.parse()
@@ -119,7 +119,7 @@ mod tests {
.unwrap();
let stanza_id = StanzaId {
id: String::from("coucou"),
- by: Jid::Bare(BareJid::new("coucou", "coucou")),
+ by: Jid::new("coucou@coucou").unwrap(),
};
let elem2 = stanza_id.into();
assert_eq!(elem, elem2);
diff --git a/parsers/src/stream.rs b/parsers/src/stream.rs
index c1b5e1e..48eae77 100644
--- a/parsers/src/stream.rs
+++ b/parsers/src/stream.rs
@@ -92,7 +92,10 @@ mod tests {
fn test_simple() {
let elem: Element = "".parse().unwrap();
let stream = Stream::try_from(elem).unwrap();
- assert_eq!(stream.from, Some(BareJid::domain("some-server.example")));
+ assert_eq!(
+ stream.from,
+ Some(BareJid::new("some-server.example").unwrap())
+ );
assert_eq!(stream.to, None);
assert_eq!(stream.id, Some(String::from("abc")));
assert_eq!(stream.version, Some(String::from("1.0")));
diff --git a/parsers/src/util/error.rs b/parsers/src/util/error.rs
index 33b2a69..a2c6ea7 100644
--- a/parsers/src/util/error.rs
+++ b/parsers/src/util/error.rs
@@ -33,7 +33,7 @@ pub enum Error {
/// Generated when text which should be a [JID](../../jid/struct.Jid.html)
/// fails to parse.
- JidParseError(jid::JidParseError),
+ JidParseError(jid::Error),
/// Generated when text which should be a
/// [DateTime](../date/struct.DateTime.html) fails to parse.
@@ -92,8 +92,8 @@ impl From for Error {
}
}
-impl From for Error {
- fn from(err: jid::JidParseError) -> Error {
+impl From for Error {
+ fn from(err: jid::Error) -> Error {
Error::JidParseError(err)
}
}