From 23cfc150223fd6e16851ba69e4a1b40d89428b59 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Wed, 10 Jul 2024 12:41:08 +0300 Subject: [PATCH 1/2] Add PartialEq to make assert_eq!() possible --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index c7799df..1e7d5ef 100644 --- a/src/error.rs +++ b/src/error.rs @@ -48,7 +48,7 @@ pub enum Metadata { } /// Parsing errors. -#[derive(Error, Clone, Debug)] +#[derive(Error, Clone, Debug, PartialEq)] pub enum Parse { /// This generally indicates the string passed in had less than 3 digits in /// it. From 9bb7ec94089577d2faf078e79f1c706ef5150762 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Wed, 10 Jul 2024 12:52:49 +0300 Subject: [PATCH 2/2] Add tests for not truncating national part of the number --- src/formatter.rs | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/src/formatter.rs b/src/formatter.rs index 999aa0e..61b0944 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -262,6 +262,7 @@ fn replace( #[cfg(test)] mod test { use crate::country; + use crate::error::Parse; use crate::formatter::Mode; use crate::parser; @@ -378,4 +379,91 @@ mod test { .to_string() ); } + + // TODO: Amend to be() when fixed + #[test] + fn be1() { + assert_eq!( + "+375800111111", + parser::parse(Some(country::BY), "+375800111111") + .unwrap() + .format() + .to_string() + ); + } + + #[test] + fn be2() { + assert_eq!( + "+375800111111", + parser::parse(None, "+375800111111") + .unwrap() + .format() + .to_string() + ); + } + + // TODO: Amend to ru() when fixed + #[test] + fn ru1() { + assert_eq!( + "+78005553535", + parser::parse(Some(country::RU), "+78005553535") + .unwrap() + .format() + .to_string() + ); + } + + #[test] + fn ru2() { + assert_eq!( + "+78005553535", + parser::parse(Some(country::RU), "8005553535") + .unwrap() + .format() + .to_string() + ); + } + + #[test] + fn ru3() { + assert_eq!( + "+78005553535", + parser::parse(None, "+78005553535") + .unwrap() + .format() + .to_string() + ); + } + + // TODO: Amend to it() when fixed + #[test] + fn it1() { + assert_eq!( + Parse::InvalidCountryCode, + parser::parse(None, "3912312312").unwrap_err() + ); + } + + #[test] + fn it2() { + assert_eq!( + "+39 391 2312312", + parser::parse(Some(country::IT), "3912312312") + .unwrap() + .format() + .mode(Mode::International) + .to_string() + ); + } + + #[test] + fn it3() { + // Looks like valid, but should be invalid? + assert_eq!( + Parse::NoNumber, // placeholder error + parser::parse(None, "+3912312312").unwrap_err() + ); + } }