From 0616f9f946363385cc3e34c919da0ead22bf553c Mon Sep 17 00:00:00 2001 From: James Pace Date: Sun, 26 Jul 2026 06:59:31 -0400 Subject: [PATCH] Fix bug in export_graph. Don't query the value for the root key. --- src/lib.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a52a18d..ef06fab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -269,6 +269,11 @@ impl DiagnosticGraph { let mut statuses = Vec::::new(); for key in keys_in_order.iter() { + if *key == self.root() { + // The root key will always be the first one through this + // loop. + continue; + } let status_at_key = self.value_of(&key)?; statuses.push(status_at_key.copy_with_new_name(self.full_name_from_key(&key)?)); } @@ -428,4 +433,29 @@ mod tests { Ok(()) } + + #[test] + fn export_graph() -> Result<()> { + let statuses = vec![ + make_a_status_with_name_and_level("/a", DiagnosticLevel::UNSET), + make_a_status_with_name_and_level("/a/b/c", DiagnosticLevel::OK), + make_a_status_with_name_and_level("/a/b", DiagnosticLevel::UNSET), + make_a_status_with_name_and_level("/a/d", DiagnosticLevel::UNSET), + ]; + let mut graph = DiagnosticGraph::new(); + graph.add_status_vec(&statuses)?; + + let exported = graph.export_graph()?; + + assert!(exported.len() == 4); + // Searching doen the b tree first would also be + // technically correct, but this is the order the implementation + // is currently going with. + assert!(exported[0].name() == "/a"); + assert!(exported[1].name() == "/a/d"); + assert!(exported[2].name() == "/a/b"); + assert!(exported[3].name() == "/a/b/c"); + + Ok(()) + } }