Skip to content

Commit

Permalink
Replace map_or_else with unwrap_or and add a test for get_value_u32
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmh-zxz committed Jan 14, 2024
1 parent dbf4917 commit c41a7c4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub(crate) mod properties {
value
.to_string()
.parse::<u32>()
.map_or_else(|_e| default, |v| v)
.unwrap_or(default)
})
}

Expand All @@ -123,7 +123,7 @@ pub(crate) mod properties {
value
.to_string()
.parse::<bool>()
.map_or_else(|_e| default, |v| v)
.unwrap_or(default)
})
}
}
Expand Down Expand Up @@ -182,7 +182,8 @@ mod tests {
#[cfg(test)]
mod test_props {
use crate::api::constants::ENV_NACOS_CLIENT_NAMING_PUSH_EMPTY_PROTECTION;
use crate::properties::{get_value, get_value_bool};
use crate::api::constants::ENV_NACOS_CLIENT_COMMON_THREAD_CORES;
use crate::properties::{get_value, get_value_bool, get_value_u32};

#[test]
fn test_get_value() {
Expand All @@ -195,6 +196,12 @@ mod test_props {
let v = get_value_bool(ENV_NACOS_CLIENT_NAMING_PUSH_EMPTY_PROTECTION, true);
assert_eq!(v, true);
}

#[test]
fn test_get_value_u32() {
let v = get_value_u32(ENV_NACOS_CLIENT_COMMON_THREAD_CORES, 91);
assert_eq!(v, 91);
}
}

#[cfg(test)]
Expand Down

0 comments on commit c41a7c4

Please sign in to comment.