fix: Value equal implementation in the Bool match case (#2129)

Co-authored-by: tavindev <tavindev>
This commit is contained in:
Gustavo 2023-06-13 19:00:16 +01:00 committed by GitHub
parent 5c07a7b2d4
commit e42c8fdb1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 1 deletions

View file

@ -2248,7 +2248,10 @@ impl Value {
match self {
Value::None => other.is_none(),
Value::Null => other.is_null(),
Value::Bool(v) => *v,
Value::Bool(v) => match other {
Value::Bool(w) => v == w,
_ => false,
},
Value::Uuid(v) => match other {
Value::Uuid(w) => v == w,
Value::Regex(w) => w.regex().is_match(v.to_raw().as_str()),

View file

@ -107,3 +107,96 @@ async fn select_writeable_subqueries() -> Result<(), Error> {
//
Ok(())
}
#[tokio::test]
async fn select_where_field_is_bool() -> Result<(), Error> {
let sql = "
CREATE test:1 SET active = false;
CREATE test:2 SET active = false;
CREATE test:3 SET active = true;
SELECT * FROM test WHERE active = false;
SELECT * FROM test WHERE active != true;
SELECT * FROM test WHERE active = true;
";
let dbs = Datastore::new("memory").await?;
let ses = Session::for_kv().with_ns("test").with_db("test");
let res = &mut dbs.execute(&sql, &ses, None, false).await?;
assert_eq!(res.len(), 6);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: test:1,
active: false
}
]",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: test:2,
active: false
}
]",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: test:3,
active: true
}
]",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: test:1,
active: false
},
{
id: test:2,
active: false
}
]",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: test:1,
active: false
},
{
id: test:2,
active: false
}
]",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: test:3,
active: true
}
]",
);
assert_eq!(tmp, val);
Ok(())
}