Skip to content

Commit 51c0e10

Browse files
committed
fix tests
1 parent a2b1508 commit 51c0e10

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

contrib/tools/config-docs-generator/src/generate_markdown.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -443,21 +443,7 @@ fn struct_to_section_name(struct_name: &str, custom_mappings: &HashMap<String, S
443443
if let Some(section_name) = custom_mappings.get(struct_name) {
444444
return section_name.clone();
445445
}
446-
447-
// Convert struct name to section name (e.g., "NodeConfig" -> "[node]")
448-
// NOTE: This function contains hardcoded mappings from Rust struct names to their
449-
// desired TOML section names in the Markdown output. It must be updated if new
450-
// top-level configuration structs are added or existing ones are renamed.
451-
match struct_name {
452-
"BurnchainConfig" => "[burnchain]".to_string(),
453-
"NodeConfig" => "[node]".to_string(),
454-
"MinerConfig" => "[miner]".to_string(),
455-
"ConnectionOptionsFile" => "[connection_options]".to_string(),
456-
"FeeEstimationConfigFile" => "[fee_estimation]".to_string(),
457-
"EventObserverConfigFile" => "[[events_observer]]".to_string(),
458-
"InitialBalanceFile" => "[[ustx_balance]]".to_string(),
459-
_ => format!("[{}]", struct_name.to_lowercase()),
460-
}
446+
format!("[{}]", struct_name.to_lowercase())
461447
}
462448

463449
fn struct_to_section_name_with_context(
@@ -646,6 +632,11 @@ mod tests {
646632
let mut struct_to_anchor = HashMap::new();
647633
let mut field_to_struct = HashMap::new();
648634
let mut constants = HashMap::new();
635+
let mut custom_mappings = HashMap::new();
636+
637+
// Add custom mappings like the real ones
638+
custom_mappings.insert("NodeConfig".to_string(), "[node]".to_string());
639+
custom_mappings.insert("MinerConfig".to_string(), "[miner]".to_string());
649640

650641
// Add some test structs and fields
651642
struct_to_anchor.insert("NodeConfig".to_string(), "#node".to_string());
@@ -667,7 +658,7 @@ mod tests {
667658
struct_to_anchor,
668659
field_to_struct,
669660
constants,
670-
custom_mappings: HashMap::new(),
661+
custom_mappings,
671662
}
672663
}
673664

@@ -676,7 +667,8 @@ mod tests {
676667
#[test]
677668
fn test_generate_markdown_empty_config() {
678669
let config_docs = create_config_docs(vec![]);
679-
let result = generate_markdown(&config_docs, None, &HashMap::new()).unwrap();
670+
let template_path = "templates/reference_template.md";
671+
let result = generate_markdown(&config_docs, template_path, &HashMap::new()).unwrap();
680672

681673
assert!(result.contains("# Stacks Node Configuration Reference"));
682674
assert!(result.contains("## Table of Contents"));
@@ -688,7 +680,8 @@ mod tests {
688680
fn test_generate_markdown_with_one_struct_no_fields() {
689681
let struct_doc = create_struct_doc("TestStruct", Some("A test struct"), vec![]);
690682
let config_docs = create_config_docs(vec![struct_doc]);
691-
let result = generate_markdown(&config_docs, None, &HashMap::new()).unwrap();
683+
let template_path = "templates/reference_template.md";
684+
let result = generate_markdown(&config_docs, template_path, &HashMap::new()).unwrap();
692685

693686
assert!(result.contains("# Stacks Node Configuration Reference"));
694687
assert!(result.contains("- [[teststruct]](#teststruct)"));
@@ -702,7 +695,8 @@ mod tests {
702695
let field = create_field_doc("test_field", "A test field");
703696
let struct_doc = create_struct_doc("TestStruct", Some("A test struct"), vec![field]);
704697
let config_docs = create_config_docs(vec![struct_doc]);
705-
let result = generate_markdown(&config_docs, None, &HashMap::new()).unwrap();
698+
let template_path = "templates/reference_template.md";
699+
let result = generate_markdown(&config_docs, template_path, &HashMap::new()).unwrap();
706700

707701
assert!(result.contains("# Stacks Node Configuration Reference"));
708702
assert!(result.contains("- [[teststruct]](#teststruct)"));
@@ -717,7 +711,28 @@ mod tests {
717711

718712
#[test]
719713
fn test_struct_to_section_name_known_structs() {
720-
let mappings = HashMap::new();
714+
let mut mappings = HashMap::new();
715+
// Load the expected mappings based on section_name_mappings.json
716+
mappings.insert("BurnchainConfig".to_string(), "[burnchain]".to_string());
717+
mappings.insert("NodeConfig".to_string(), "[node]".to_string());
718+
mappings.insert("MinerConfig".to_string(), "[miner]".to_string());
719+
mappings.insert(
720+
"ConnectionOptionsFile".to_string(),
721+
"[connection_options]".to_string(),
722+
);
723+
mappings.insert(
724+
"FeeEstimationConfigFile".to_string(),
725+
"[fee_estimation]".to_string(),
726+
);
727+
mappings.insert(
728+
"EventObserverConfigFile".to_string(),
729+
"[[events_observer]]".to_string(),
730+
);
731+
mappings.insert(
732+
"InitialBalanceFile".to_string(),
733+
"[[ustx_balance]]".to_string(),
734+
);
735+
721736
assert_eq!(
722737
struct_to_section_name("BurnchainConfig", &mappings),
723738
"[burnchain]"

0 commit comments

Comments
 (0)