Skip to content

Commit f3e902f

Browse files
committed
fix: fixes casing of version strings
Addresses an edge case where the `convert_case` crate incorrectly transforms version strings like "v_1" into "V_1". This change introduces a regular expression to correct these patterns, ensuring that version strings are properly cased as "v1".
1 parent 21fd4b4 commit f3e902f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/render.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
use color_eyre::eyre::{eyre, Context, ContextCompat, Result};
22
use convert_case::{Case, Casing};
3+
use regex::Regex;
34
use std::path::Path;
5+
use std::sync::LazyLock;
46

57
use crate::parsing::{find_suite, find_test, get_group_comment, get_groups, get_suite_chunk};
68
use crate::runner::Runner;
79
use crate::target::Target;
810
use crate::ConfigMeta;
911
use crate::{document::Document, group::Group, suite::Suite, test::Test};
1012

13+
// Regex to fix version patterns like v_1, v_2, v_3 back to v1, v2, v3
14+
// This is needed because convert_case treats letter-to-number transitions as word boundaries
15+
static VERSION_PATTERN: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"v_(\d+)").unwrap());
16+
1117
fn case_from_str(s: &str) -> Result<Case> {
1218
match s {
1319
"Alternating" => Ok(Case::Alternating),
@@ -36,9 +42,12 @@ fn case_from_str(s: &str) -> Result<Case> {
3642
}
3743

3844
fn convert_case_filter(input: &str, case: &str) -> String {
39-
input.to_case(case_from_str(case).unwrap_or_else(|e| {
45+
let result = input.to_case(case_from_str(case).unwrap_or_else(|e| {
4046
panic!("failed to convert case: {}", e);
41-
}))
47+
}));
48+
// Fix common version patterns like v_1, v_2, v_3 back to v1, v2, v3
49+
// The convert_case crate treats letter-to-number transitions as word boundaries
50+
VERSION_PATTERN.replace_all(&result, "v$1").to_string()
4251
}
4352

4453
pub fn insert_after_keyword(original: &str, to_insert: &str, keyword: &str) -> String {

0 commit comments

Comments
 (0)