Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: placeholder logic for > 2 placeholders #109

Merged
merged 3 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/core/src/generator/templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
29 changes: 29 additions & 0 deletions crates/testfile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,33 @@ 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();

assert_eq!(placeholder_map.len(), 3);
}
}
2 changes: 1 addition & 1 deletion crates/testfile/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashMap<String, String>>,
Expand Down
Loading