fix: Value equal implementation in the Bool match case (#2129)
Co-authored-by: tavindev <tavindev>
This commit is contained in:
parent
5c07a7b2d4
commit
e42c8fdb1a
2 changed files with 97 additions and 1 deletions
|
@ -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()),
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue