Skip to content

Commit

Permalink
Merge pull request #109 from 0xgregthedev/fix/placeholders
Browse files Browse the repository at this point in the history
fix: placeholder logic for > 2 placeholders
  • Loading branch information
zeroXbrock authored Jan 26, 2025
2 parents 302d3c3 + 074bdcb commit af56f00
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
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

0 comments on commit af56f00

Please sign in to comment.