Remove redundant uses of format!()

This commit is contained in:
Hyeon Kim 2021-11-15 03:04:48 +09:00
parent af6ef9eec2
commit a8d6df4e31
No known key found for this signature in database
GPG key ID: 0F85F46EE242057F
3 changed files with 45 additions and 42 deletions

View file

@ -661,16 +661,16 @@ mod test {
#[allow(unused)] #[allow(unused)]
fn test_config() -> Config { fn test_config() -> Config {
Config { Config {
owners: vec![format!("test")], owners: vec!["test".to_string()],
nickname: Some(format!("test")), nickname: Some("test".to_string()),
username: Some(format!("test")), username: Some("test".to_string()),
realname: Some(format!("test")), realname: Some("test".to_string()),
password: Some(String::new()), password: Some(String::new()),
umodes: Some(format!("+BR")), umodes: Some("+BR".to_string()),
server: Some(format!("irc.test.net")), server: Some("irc.test.net".to_string()),
port: Some(6667), port: Some(6667),
encoding: Some(format!("UTF-8")), encoding: Some("UTF-8".to_string()),
channels: vec![format!("#test"), format!("#test2")], channels: vec!["#test".to_string(), "#test2".to_string()],
..Default::default() ..Default::default()
} }
@ -679,7 +679,7 @@ mod test {
#[test] #[test]
fn is_owner() { fn is_owner() {
let cfg = Config { let cfg = Config {
owners: vec![format!("test"), format!("test2")], owners: vec!["test".to_string(), "test2".to_string()],
..Default::default() ..Default::default()
}; };
assert!(cfg.is_owner("test")); assert!(cfg.is_owner("test"));
@ -692,7 +692,7 @@ mod test {
let cfg = Config { let cfg = Config {
options: { options: {
let mut map = HashMap::new(); let mut map = HashMap::new();
map.insert(format!("testing"), format!("test")); map.insert("testing".to_string(), "test".to_string());
map map
}, },
..Default::default() ..Default::default()

View file

@ -248,7 +248,7 @@ mod test {
fn create_user() { fn create_user() {
let user = User::new("~owner"); let user = User::new("~owner");
let exp = User { let exp = User {
nickname: format!("owner"), nickname: "owner".to_string(),
username: None, username: None,
hostname: None, hostname: None,
highest_access_level: Owner, highest_access_level: Owner,
@ -263,7 +263,7 @@ mod test {
fn create_user_complex() { fn create_user_complex() {
let user = User::new("~&+user"); let user = User::new("~&+user");
let exp = User { let exp = User {
nickname: format!("user"), nickname: "user".to_string(),
username: None, username: None,
hostname: None, hostname: None,
highest_access_level: Owner, highest_access_level: Owner,

View file

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