Remove eager parsing of "false"
truthiness (#4775)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
065ac9cd5a
commit
4d92005125
2 changed files with 17 additions and 14 deletions
|
@ -961,7 +961,7 @@ impl Value {
|
|||
Value::Geometry(_) => true,
|
||||
Value::Array(v) => !v.is_empty(),
|
||||
Value::Object(v) => !v.is_empty(),
|
||||
Value::Strand(v) => !v.is_empty() && !v.eq_ignore_ascii_case("false"),
|
||||
Value::Strand(v) => !v.is_empty(),
|
||||
Value::Number(v) => v.is_truthy(),
|
||||
Value::Duration(v) => v.as_nanos() > 0,
|
||||
Value::Datetime(v) => v.timestamp() > 0,
|
||||
|
@ -3164,7 +3164,7 @@ mod tests {
|
|||
assert!(Value::from(1.1).is_truthy());
|
||||
assert!(Value::from(-1.1).is_truthy());
|
||||
assert!(Value::from("true").is_truthy());
|
||||
assert!(!Value::from("false").is_truthy());
|
||||
assert!(Value::from("false").is_truthy());
|
||||
assert!(Value::from("falsey").is_truthy());
|
||||
assert!(Value::from("something").is_truthy());
|
||||
assert!(Value::from(Uuid::new()).is_truthy());
|
||||
|
|
|
@ -599,10 +599,11 @@ async fn function_array_len() -> Result<(), Error> {
|
|||
#[tokio::test]
|
||||
async fn function_array_logical_and() -> Result<(), Error> {
|
||||
test_queries(
|
||||
r#"RETURN array::logical_and([true, false, true, false], [true, true, false, false]);
|
||||
RETURN array::logical_and([1, 0, 1, 0], ["true", "true", "false", "false"]);
|
||||
r#"
|
||||
RETURN array::logical_and([true, false, true, false], [true, true, false, false]);
|
||||
RETURN array::logical_and([1, 0, 1, 0], [true, true, false, false]);
|
||||
RETURN array::logical_and([0, 1], []);"#,
|
||||
&["[true, false, false, false]", r#"[1, 0, "false", 0]"#, "[0, null]"],
|
||||
&["[true, false, false, false]", r#"[1, 0, false, 0]"#, "[0, null]"],
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
|
@ -611,10 +612,11 @@ RETURN array::logical_and([0, 1], []);"#,
|
|||
#[tokio::test]
|
||||
async fn function_array_logical_or() -> Result<(), Error> {
|
||||
test_queries(
|
||||
r#"RETURN array::logical_or([true, false, true, false], [true, true, false, false]);
|
||||
RETURN array::logical_or([1, 0, 1, 0], ["true", "true", "false", "false"]);
|
||||
r#"
|
||||
RETURN array::logical_or([true, false, true, false], [true, true, false, false]);
|
||||
RETURN array::logical_or([1, 0, 1, 0], [true, true, false, false]);
|
||||
RETURN array::logical_or([0, 1], []);"#,
|
||||
&["[true, true, true, false]", r#"[1, "true", 1, 0]"#, "[0, 1]"],
|
||||
&["[true, true, true, false]", r#"[1, true, 1, 0]"#, "[0, 1]"],
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
|
@ -623,10 +625,11 @@ RETURN array::logical_or([0, 1], []);"#,
|
|||
#[tokio::test]
|
||||
async fn function_array_logical_xor() -> Result<(), Error> {
|
||||
test_queries(
|
||||
r#"RETURN array::logical_xor([true, false, true, false], [true, true, false, false]);
|
||||
RETURN array::logical_xor([1, 0, 1, 0], ["true", "true", "false", "false"]);
|
||||
r#"
|
||||
RETURN array::logical_xor([true, false, true, false], [true, true, false, false]);
|
||||
RETURN array::logical_xor([1, 0, 1, 0], [true, true, false, false]);
|
||||
RETURN array::logical_xor([0, 1], []);"#,
|
||||
&["[false, true, true, false]", r#"[false, "true", 1, 0]"#, "[0, 1]"],
|
||||
&["[false, true, true, false]", r#"[false, true, 1, 0]"#, "[0, 1]"],
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue