From 40e8fab5db09f3c38c68f4ed09f435d6b3f8b212 Mon Sep 17 00:00:00 2001 From: Ishaan Goel Date: Mon, 30 Sep 2024 20:54:58 +0530 Subject: [PATCH] added test for `with_message` function --- zung_mini/src/progbar/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/zung_mini/src/progbar/mod.rs b/zung_mini/src/progbar/mod.rs index 4220c47..d948806 100644 --- a/zung_mini/src/progbar/mod.rs +++ b/zung_mini/src/progbar/mod.rs @@ -166,7 +166,7 @@ impl ProgBar { /// ```rust /// use zung_mini::progbar::ProgBarExt; /// - /// for _ in (0..).progbar().with_message("Processing...".to_string()) { + /// for _ in (0..).progbar().with_message("Processing...") { /// // Perform work here /// # break; /// }; @@ -517,4 +517,20 @@ mod tests { assert_eq!(progbar.bound.percentage.get(), i * 10); } } + + #[test] + fn test_with_message() { + let mut progbar = (0..).progbar().with_message("Loading..."); + + // Test the initial message + assert_eq!(progbar.message, "Loading..."); + + // Test updating the message + progbar = progbar.with_message("Processing..."); + assert_eq!(progbar.message, "Processing..."); + + // Ensure the progress bar can still iterate, though unbounded. + assert_eq!(progbar.next(), Some(0)); // First item + assert_eq!(progbar.step, 1); // Progress updated by 1 step + } }