Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

National trunk prefix #77

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
88 changes: 88 additions & 0 deletions src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ fn replace(
#[cfg(test)]
mod test {
use crate::country;
use crate::error::Parse;
use crate::formatter::Mode;
use crate::parser;

Expand Down Expand Up @@ -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()
);
}
}
Loading