From 5670ce0aa42a317ef2c858de7573513f1d1ce56d Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 22 Nov 2023 11:08:36 +0700 Subject: [PATCH 1/3] chore: debug for op value and flags --- grovedb/src/batch/mod.rs | 24 +++-------------------- grovedb/src/element/mod.rs | 1 + grovedb/src/tests/query_tests.rs | 4 ++-- grovedb/src/visualize.rs | 33 ++++++++++++++++++++++++++++---- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index 8f275095..f6a4e7ea 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -380,27 +380,9 @@ impl fmt::Debug for GroveDbOp { self.key.visualize(key_drawer).unwrap(); let op_dbg = match &self.op { - Op::Insert { element } => match element { - Element::Item(..) => "Insert Item".to_string(), - Element::Reference(..) => "Insert Ref".to_string(), - Element::Tree(..) => "Insert Tree".to_string(), - Element::SumTree(..) => "Insert Sum Tree".to_string(), - Element::SumItem(..) => "Insert Sum Item".to_string(), - }, - Op::Replace { element } => match element { - Element::Item(..) => "Replace Item".to_string(), - Element::Reference(..) => "Replace Ref".to_string(), - Element::Tree(..) => "Replace Tree".to_string(), - Element::SumTree(..) => "Replace Sum Tree".to_string(), - Element::SumItem(..) => "Replace Sum Item".to_string(), - }, - Op::Patch { element, .. } => match element { - Element::Item(..) => "Patch Item".to_string(), - Element::Reference(..) => "Patch Ref".to_string(), - Element::Tree(..) => "Patch Tree".to_string(), - Element::SumTree(..) => "Patch Sum Tree".to_string(), - Element::SumItem(..) => "Patch Sum Item".to_string(), - }, + Op::Insert { element } => format!("Insert {:?}", element), + Op::Replace { element } => format!("Replace {:?}", element), + Op::Patch { element, .. } => format!("Patch {:?}", element), Op::RefreshReference { reference_path_type, max_reference_hop, diff --git a/grovedb/src/element/mod.rs b/grovedb/src/element/mod.rs index 009f85ae..411e7673 100644 --- a/grovedb/src/element/mod.rs +++ b/grovedb/src/element/mod.rs @@ -118,3 +118,4 @@ impl fmt::Debug for Element { f.write_str(&String::from_utf8_lossy(&v)) } } + diff --git a/grovedb/src/tests/query_tests.rs b/grovedb/src/tests/query_tests.rs index c8e53ff8..af954deb 100644 --- a/grovedb/src/tests/query_tests.rs +++ b/grovedb/src/tests/query_tests.rs @@ -2663,12 +2663,12 @@ fn test_query_b_depends_on_query_a() { fn test_prove_absent_path_with_intermediate_emtpy_tree() { // root // test_leaf (empty) - let mut grovedb = make_test_grovedb(); + let grovedb = make_test_grovedb(); // prove the absence of key "book" in ["test_leaf", "invalid"] let mut query = Query::new(); query.insert_key(b"book".to_vec()); - let mut path_query = + let path_query = PathQuery::new_unsized(vec![TEST_LEAF.to_vec(), b"invalid".to_vec()], query); let proof = grovedb diff --git a/grovedb/src/visualize.rs b/grovedb/src/visualize.rs index 3abbbfd0..41dfc74e 100644 --- a/grovedb/src/visualize.rs +++ b/grovedb/src/visualize.rs @@ -44,12 +44,24 @@ use crate::{ impl Visualize for Element { fn visualize(&self, mut drawer: Drawer) -> Result> { match self { - Element::Item(value, _) => { + Element::Item(value, flags) => { drawer.write(b"item: ")?; drawer = value.visualize(drawer)?; + + if let Some(f) = flags { + if f.len() > 0 { + drawer = f.visualize(drawer)?; + } + } } - Element::SumItem(value, _) => { + Element::SumItem(value, flags) => { drawer.write(format!("sum_item: {value}").as_bytes())?; + + if let Some(f) = flags { + if f.len() > 0 { + drawer = f.visualize(drawer)?; + } + } } Element::Reference(_ref, ..) => { drawer.write(b"ref")?; @@ -64,13 +76,26 @@ impl Visualize for Element { // } // drawer.write(b"]")?; } - Element::Tree(root_key, _) => { + Element::Tree(root_key, flags) => { drawer.write(b"tree: ")?; drawer = root_key.as_deref().visualize(drawer)?; + + if let Some(f) = flags { + if f.len() > 0 { + drawer = f.visualize(drawer)?; + } + } } - Element::SumTree(root_key, ..) => { + Element::SumTree(root_key, value, flags) => { drawer.write(b"sum_tree: ")?; drawer = root_key.as_deref().visualize(drawer)?; + drawer.write(format!(" {value}").as_bytes())?; + + if let Some(f) = flags { + if f.len() > 0 { + drawer = f.visualize(drawer)?; + } + } } } Ok(drawer) From 21f3dceb701fa265d4045565f799258f51a3faed Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 22 Nov 2023 11:22:25 +0700 Subject: [PATCH 2/3] style: fix formatting --- grovedb/src/element/mod.rs | 1 - grovedb/src/tests/query_tests.rs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/grovedb/src/element/mod.rs b/grovedb/src/element/mod.rs index 411e7673..009f85ae 100644 --- a/grovedb/src/element/mod.rs +++ b/grovedb/src/element/mod.rs @@ -118,4 +118,3 @@ impl fmt::Debug for Element { f.write_str(&String::from_utf8_lossy(&v)) } } - diff --git a/grovedb/src/tests/query_tests.rs b/grovedb/src/tests/query_tests.rs index af954deb..7d5fc680 100644 --- a/grovedb/src/tests/query_tests.rs +++ b/grovedb/src/tests/query_tests.rs @@ -2668,8 +2668,7 @@ fn test_prove_absent_path_with_intermediate_emtpy_tree() { // prove the absence of key "book" in ["test_leaf", "invalid"] let mut query = Query::new(); query.insert_key(b"book".to_vec()); - let path_query = - PathQuery::new_unsized(vec![TEST_LEAF.to_vec(), b"invalid".to_vec()], query); + let path_query = PathQuery::new_unsized(vec![TEST_LEAF.to_vec(), b"invalid".to_vec()], query); let proof = grovedb .prove_query(&path_query) From ec20366fd670cfb65bf19eef55f25b68b861fb26 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 23 Nov 2023 18:39:18 +0700 Subject: [PATCH 3/3] style: fix clippy warnings --- grovedb/src/visualize.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/grovedb/src/visualize.rs b/grovedb/src/visualize.rs index 41dfc74e..6bba2f83 100644 --- a/grovedb/src/visualize.rs +++ b/grovedb/src/visualize.rs @@ -49,7 +49,7 @@ impl Visualize for Element { drawer = value.visualize(drawer)?; if let Some(f) = flags { - if f.len() > 0 { + if !f.is_empty() { drawer = f.visualize(drawer)?; } } @@ -58,7 +58,7 @@ impl Visualize for Element { drawer.write(format!("sum_item: {value}").as_bytes())?; if let Some(f) = flags { - if f.len() > 0 { + if !f.is_empty() { drawer = f.visualize(drawer)?; } } @@ -81,7 +81,7 @@ impl Visualize for Element { drawer = root_key.as_deref().visualize(drawer)?; if let Some(f) = flags { - if f.len() > 0 { + if !f.is_empty() { drawer = f.visualize(drawer)?; } } @@ -92,7 +92,7 @@ impl Visualize for Element { drawer.write(format!(" {value}").as_bytes())?; if let Some(f) = flags { - if f.len() > 0 { + if !f.is_empty() { drawer = f.visualize(drawer)?; } }