From 372cd6596987ea30311576f4f81dcecee3f5ecc4 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 6 Jan 2023 10:26:25 +0000 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20treat=20`NONE`=20and=20`NULL`?= =?UTF-8?q?=20as=20the=20same?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/sql/value/value.rs | 9 +++--- lib/tests/compare.rs | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 lib/tests/compare.rs diff --git a/lib/src/sql/value/value.rs b/lib/src/sql/value/value.rs index 28547ce8..2ff60849 100644 --- a/lib/src/sql/value/value.rs +++ b/lib/src/sql/value/value.rs @@ -602,11 +602,11 @@ impl Value { // ----------------------------------- pub fn is_none(&self) -> bool { - matches!(self, Value::None | Value::Null) + matches!(self, Value::None) } pub fn is_null(&self) -> bool { - matches!(self, Value::None | Value::Null) + matches!(self, Value::Null) } pub fn is_some(&self) -> bool { @@ -1002,6 +1002,7 @@ impl Value { true => self, _ => Value::None, }, + Kind::Option(v) => todo!(), } } @@ -1530,14 +1531,14 @@ mod tests { #[test] fn check_none() { assert_eq!(true, Value::None.is_none()); - assert_eq!(true, Value::Null.is_none()); + assert_eq!(false, Value::Null.is_none()); assert_eq!(false, Value::from(1).is_none()); } #[test] fn check_null() { - assert_eq!(true, Value::None.is_null()); assert_eq!(true, Value::Null.is_null()); + assert_eq!(false, Value::None.is_null()); assert_eq!(false, Value::from(1).is_null()); } diff --git a/lib/tests/compare.rs b/lib/tests/compare.rs new file mode 100644 index 00000000..31ba0185 --- /dev/null +++ b/lib/tests/compare.rs @@ -0,0 +1,62 @@ +mod parse; +use surrealdb::dbs::Session; +use surrealdb::err::Error; +use surrealdb::kvs::Datastore; +use surrealdb::sql::Value; + +#[tokio::test] +async fn compare_empty() -> Result<(), Error> { + let sql = r#" + RETURN NONE = NONE; + RETURN NULL = NULL; + RETURN NONE = NULL; + RETURN [] = []; + RETURN {} = {}; + RETURN [] = {}; + RETURN 0 = 0; + RETURN 0 = 0.0; + RETURN 0 = 0.1; + "#; + 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(), 9); + // + let tmp = res.remove(0).result?; + let val = Value::True; + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::True; + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::False; + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::True; + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::True; + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::False; + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::True; + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::True; + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::False; + assert_eq!(tmp, val); + // + Ok(()) +}