From c3e644be782c2741b1d5971e6510f9cf91af22a8 Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Sat, 25 Jan 2025 16:01:56 -0700 Subject: [PATCH 1/3] fix: placeholder logic for > 2 placeholders --- crates/core/src/generator/templater.rs | 3 ++- crates/testfile/src/lib.rs | 25 +++++++++++++++++++++++++ crates/testfile/src/types.rs | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/core/src/generator/templater.rs b/crates/core/src/generator/templater.rs index 42475e7..66bb271 100644 --- a/crates/core/src/generator/templater.rs +++ b/crates/core/src/generator/templater.rs @@ -39,13 +39,14 @@ where for _ in 0..num_template_vals { let template_value = self.copy_end(arg, last_end); + let (template_key, template_end) = self.find_key(&template_value) .ok_or(ContenderError::SpamError( "failed to find placeholder key", Some(arg.to_string()), ))?; - last_end = template_end + 1; + last_end += template_end + 1; // skip if value in map, else look up in DB if placeholder_map.contains_key(&template_key) { diff --git a/crates/testfile/src/lib.rs b/crates/testfile/src/lib.rs index 64edef4..9a7d09d 100644 --- a/crates/testfile/src/lib.rs +++ b/crates/testfile/src/lib.rs @@ -476,4 +476,29 @@ pub mod tests { } } } + + #[test] + fn test_placeholders_count() { + use crate::{types::TestConfig, Templater}; + let test_config = TestConfig::default(); + + let count = test_config.num_placeholders("{lol}{baa}{hahaa}"); + + assert_eq!(count, 3); + } + + #[test] + fn test_placeholders_find() { + use crate::{types::TestConfig, Templater}; + + let test_config = TestConfig::default(); + + let mut placeholder_map = HashMap::new(); + test_config.find_placeholder_values("{lol}{baa}{hahaa}", &mut placeholder_map, &MockDb, "http://localhost:8545").unwrap(); + + println!("{:#?}", placeholder_map); + + assert_eq!(placeholder_map.len(), 3); + } + } diff --git a/crates/testfile/src/types.rs b/crates/testfile/src/types.rs index b9d471d..9abcb5e 100644 --- a/crates/testfile/src/types.rs +++ b/crates/testfile/src/types.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; /// Configuration to run a test scenario; used to generate PlanConfigs. /// Defines TOML schema for scenario files. -#[derive(Clone, Deserialize, Debug, Serialize)] +#[derive(Clone, Deserialize, Debug, Serialize, Default)] pub struct TestConfig { /// Template variables pub env: Option>, From 01f455474d4fe8633c02f8024b7438e409e213a2 Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Sat, 25 Jan 2025 16:05:10 -0700 Subject: [PATCH 2/3] chore: fmt --- crates/testfile/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/testfile/src/lib.rs b/crates/testfile/src/lib.rs index 9a7d09d..03fa218 100644 --- a/crates/testfile/src/lib.rs +++ b/crates/testfile/src/lib.rs @@ -494,11 +494,17 @@ pub mod tests { let test_config = TestConfig::default(); let mut placeholder_map = HashMap::new(); - test_config.find_placeholder_values("{lol}{baa}{hahaa}", &mut placeholder_map, &MockDb, "http://localhost:8545").unwrap(); + test_config + .find_placeholder_values( + "{lol}{baa}{hahaa}", + &mut placeholder_map, + &MockDb, + "http://localhost:8545", + ) + .unwrap(); println!("{:#?}", placeholder_map); assert_eq!(placeholder_map.len(), 3); } - } From 074bdcb0f002c1b8691d18ac08e386f000d54efd Mon Sep 17 00:00:00 2001 From: GregTheDev Date: Sat, 25 Jan 2025 16:08:31 -0700 Subject: [PATCH 3/3] chore: remove println from unit test --- crates/testfile/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/testfile/src/lib.rs b/crates/testfile/src/lib.rs index 03fa218..2c31e68 100644 --- a/crates/testfile/src/lib.rs +++ b/crates/testfile/src/lib.rs @@ -503,8 +503,6 @@ pub mod tests { ) .unwrap(); - println!("{:#?}", placeholder_map); - assert_eq!(placeholder_map.len(), 3); } }