Skip to content

Commit

Permalink
Remove redundant uses of format!()
Browse files Browse the repository at this point in the history
  • Loading branch information
simnalamburt committed Jun 3, 2023
1 parent af6ef9e commit a8d6df4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 42 deletions.
20 changes: 10 additions & 10 deletions src/client/data/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,16 +661,16 @@ mod test {
#[allow(unused)]
fn test_config() -> Config {
Config {
owners: vec![format!("test")],
nickname: Some(format!("test")),
username: Some(format!("test")),
realname: Some(format!("test")),
owners: vec!["test".to_string()],
nickname: Some("test".to_string()),
username: Some("test".to_string()),
realname: Some("test".to_string()),
password: Some(String::new()),
umodes: Some(format!("+BR")),
server: Some(format!("irc.test.net")),
umodes: Some("+BR".to_string()),
server: Some("irc.test.net".to_string()),
port: Some(6667),
encoding: Some(format!("UTF-8")),
channels: vec![format!("#test"), format!("#test2")],
encoding: Some("UTF-8".to_string()),
channels: vec!["#test".to_string(), "#test2".to_string()],

..Default::default()
}
Expand All @@ -679,7 +679,7 @@ mod test {
#[test]
fn is_owner() {
let cfg = Config {
owners: vec![format!("test"), format!("test2")],
owners: vec!["test".to_string(), "test2".to_string()],
..Default::default()
};
assert!(cfg.is_owner("test"));
Expand All @@ -692,7 +692,7 @@ mod test {
let cfg = Config {
options: {
let mut map = HashMap::new();
map.insert(format!("testing"), format!("test"));
map.insert("testing".to_string(), "test".to_string());
map
},
..Default::default()
Expand Down
4 changes: 2 additions & 2 deletions src/client/data/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod test {
fn create_user() {
let user = User::new("~owner");
let exp = User {
nickname: format!("owner"),
nickname: "owner".to_string(),
username: None,
hostname: None,
highest_access_level: Owner,
Expand All @@ -263,7 +263,7 @@ mod test {
fn create_user_complex() {
let user = User::new("~&+user");
let exp = User {
nickname: format!("user"),
nickname: "user".to_string(),
username: None,
hostname: None,
highest_access_level: Owner,
Expand Down
63 changes: 33 additions & 30 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,12 +1114,12 @@ mod test {

pub fn test_config() -> Config {
Config {
owners: vec![format!("test")],
nickname: Some(format!("test")),
alt_nicks: vec![format!("test2")],
server: Some(format!("irc.test.net")),
channels: vec![format!("#test"), format!("#test2")],
user_info: Some(format!("Testing.")),
owners: vec!["test".to_string()],
nickname: Some("test".to_string()),
alt_nicks: vec!["test2".to_string()],
server: Some("irc.test.net".to_string()),
channels: vec!["#test".to_string(), "#test2".to_string()],
user_info: Some("Testing.".to_string()),
use_mock_connection: true,
..Default::default()
}
Expand Down Expand Up @@ -1180,8 +1180,8 @@ mod test {
let value = ":irc.test.net 376 test :End of /MOTD command.\r\n";
let mut client = Client::from_config(Config {
mock_initial_value: Some(value.to_owned()),
nick_password: Some(format!("password")),
channels: vec![format!("#test"), format!("#test2")],
nick_password: Some("password".to_string()),
channels: vec!["#test".to_string(), "#test2".to_string()],
..test_config()
})
.await?;
Expand All @@ -1199,11 +1199,11 @@ mod test {
let value = ":irc.test.net 376 test :End of /MOTD command\r\n";
let mut client = Client::from_config(Config {
mock_initial_value: Some(value.to_owned()),
nickname: Some(format!("test")),
channels: vec![format!("#test"), format!("#test2")],
nickname: Some("test".to_string()),
channels: vec!["#test".to_string(), "#test2".to_string()],
channel_keys: {
let mut map = HashMap::new();
map.insert(format!("#test2"), format!("password"));
map.insert("#test2".to_string(), "password".to_string());
map
},
..test_config()
Expand All @@ -1223,10 +1223,10 @@ mod test {
:irc.test.net 376 test2 :End of /MOTD command.\r\n";
let mut client = Client::from_config(Config {
mock_initial_value: Some(value.to_owned()),
nickname: Some(format!("test")),
alt_nicks: vec![format!("test2")],
nick_password: Some(format!("password")),
channels: vec![format!("#test"), format!("#test2")],
nickname: Some("test".to_string()),
alt_nicks: vec!["test2".to_string()],
nick_password: Some("password".to_string()),
channels: vec!["#test".to_string(), "#test2".to_string()],
should_ghost: true,
..test_config()
})
Expand All @@ -1246,12 +1246,12 @@ mod test {
:irc.test.net 376 test2 :End of /MOTD command.\r\n";
let mut client = Client::from_config(Config {
mock_initial_value: Some(value.to_owned()),
nickname: Some(format!("test")),
alt_nicks: vec![format!("test2")],
nick_password: Some(format!("password")),
channels: vec![format!("#test"), format!("#test2")],
nickname: Some("test".to_string()),
alt_nicks: vec!["test2".to_string()],
nick_password: Some("password".to_string()),
channels: vec!["#test".to_string(), "#test2".to_string()],
should_ghost: true,
ghost_sequence: Some(vec![format!("RECOVER"), format!("RELEASE")]),
ghost_sequence: Some(vec!["RECOVER".to_string(), "RELEASE".to_string()]),
..test_config()
})
.await?;
Expand All @@ -1270,9 +1270,9 @@ mod test {
let value = ":irc.test.net 376 test :End of /MOTD command.\r\n";
let mut client = Client::from_config(Config {
mock_initial_value: Some(value.to_owned()),
nickname: Some(format!("test")),
umodes: Some(format!("+B")),
channels: vec![format!("#test"), format!("#test2")],
nickname: Some("test".to_string()),
umodes: Some("+B".to_string()),
channels: vec!["#test".to_string(), "#test2".to_string()],
..test_config()
})
.await?;
Expand Down Expand Up @@ -1319,7 +1319,7 @@ mod test {
async fn send() -> Result<()> {
let mut client = Client::from_config(test_config()).await?;
assert!(client
.send(PRIVMSG(format!("#test"), format!("Hi there!")))
.send(PRIVMSG("#test".to_string(), "Hi there!".to_string()))
.is_ok());
client.stream()?.collect().await?;
assert_eq!(
Expand All @@ -1333,7 +1333,10 @@ mod test {
async fn send_no_newline_injection() -> Result<()> {
let mut client = Client::from_config(test_config()).await?;
assert!(client
.send(PRIVMSG(format!("#test"), format!("Hi there!\r\nJOIN #bad")))
.send(PRIVMSG(
"#test".to_string(),
"Hi there!\r\nJOIN #bad".to_string()
))
.is_ok());
client.stream()?.collect().await?;
assert_eq!(
Expand Down Expand Up @@ -1391,7 +1394,7 @@ mod test {
assert_eq!(client.list_channels(), Some(vec!["#test".to_owned()]));
// we ignore the result, as soon as we queue an outgoing message we
// update client state, regardless if the queue is available or not.
let _ = client.send(PART(format!("#test"), None));
let _ = client.send(PART("#test".to_string(), None));
assert_eq!(client.list_channels(), Some(vec![]));
Ok(())
}
Expand Down Expand Up @@ -1520,8 +1523,8 @@ mod test {
let value = ":test!test@test PRIVMSG #test :\u{001}\r\n";
let mut client = Client::from_config(Config {
mock_initial_value: Some(value.to_owned()),
nickname: Some(format!("test")),
channels: vec![format!("#test"), format!("#test2")],
nickname: Some("test".to_string()),
channels: vec!["#test".to_string(), "#test2".to_string()],
..test_config()
})
.await?;
Expand Down Expand Up @@ -1664,8 +1667,8 @@ mod test {
#[tokio::test]
async fn identify_with_password() -> Result<()> {
let mut client = Client::from_config(Config {
nickname: Some(format!("test")),
password: Some(format!("password")),
nickname: Some("test".to_string()),
password: Some("password".to_string()),
..test_config()
})
.await?;
Expand Down

0 comments on commit a8d6df4

Please sign in to comment.