fix, tests: add guess_from test, fix url detection

feat/type-attributes
Tomáš Mládek 2023-05-19 17:14:33 +02:00
parent 35cd36e4b9
commit 6bb7e5a4e3
1 changed files with 17 additions and 1 deletions

View File

@ -184,7 +184,7 @@ impl EntryValue {
Ok(num) => EntryValue::Number(num),
Err(_) => {
lazy_static! {
static ref URL_REGEX: Regex = Regex::new("^[a-zA-Z0-9_]://").unwrap();
static ref URL_REGEX: Regex = Regex::new("^[a-zA-Z0-9_]+://").unwrap();
}
if URL_REGEX.is_match(string) {
EntryValue::Address(Address::Url(string.to_string()))
@ -309,4 +309,20 @@ mod tests {
let addr = Address::Url("https://upend.dev".into());
assert_eq!(EntryValue::Address(addr.clone()), addr.into());
}
#[test]
fn test_guess_value() {
assert_eq!(
EntryValue::guess_from("UPEND"),
EntryValue::String("UPEND".into())
);
assert_eq!(
EntryValue::guess_from("1337.93"),
EntryValue::Number(1337.93)
);
assert_eq!(
EntryValue::guess_from("https://upend.dev"),
EntryValue::Address(Address::Url("https://upend.dev".to_string()))
);
}
}