Fix string::is::longitude regex, more test coverage ()

This commit is contained in:
Dave MacLeod 2024-03-14 23:51:03 +09:00 committed by GitHub
parent 55e819bfec
commit b34cfc72fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions
core/src/fnc
lib/tests

View file

@ -179,7 +179,7 @@ pub mod is {
use uuid::Uuid;
#[rustfmt::skip] static LATITUDE_RE: Lazy<Regex> = Lazy::new(|| Regex::new("^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$").unwrap());
#[rustfmt::skip] static LONGITUDE_RE: Lazy<Regex> = Lazy::new(|| Regex::new("^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$").unwrap());
#[rustfmt::skip] static LONGITUDE_RE: Lazy<Regex> = Lazy::new(|| Regex::new("^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$").unwrap());
pub fn alphanum((arg,): (String,)) -> Result<Value, Error> {
Ok(arg.chars().all(char::is_alphanumeric).into())
@ -520,9 +520,24 @@ mod tests {
#[test]
fn is_longitude() {
let value = super::is::longitude((String::from("51.509865"),)).unwrap();
let value = super::is::longitude((String::from("91.509865"),)).unwrap();
assert_eq!(value, Value::Bool(true));
let value = super::is::longitude((String::from("-91.509865"),)).unwrap();
assert_eq!(value, Value::Bool(true));
let value = super::is::longitude((String::from("-180.00000"),)).unwrap();
assert_eq!(value, Value::Bool(true));
let value = super::is::longitude((String::from("-180.00001"),)).unwrap();
assert_eq!(value, Value::Bool(false));
let value = super::is::longitude((String::from("180.00000"),)).unwrap();
assert_eq!(value, Value::Bool(true));
let value = super::is::longitude((String::from("180.00001"),)).unwrap();
assert_eq!(value, Value::Bool(false));
let value = super::is::longitude((String::from("12345"),)).unwrap();
assert_eq!(value, Value::Bool(false));
}

View file

@ -3693,7 +3693,7 @@ async fn function_parse_is_latitude() -> Result<(), Error> {
#[tokio::test]
async fn function_parse_is_longitude() -> Result<(), Error> {
let sql = r#"
RETURN string::is::longitude("-0.136439");
RETURN string::is::longitude("-90.136439");
RETURN string::is::longitude("this is a test!");
"#;
let dbs = new_ds().await?;