|
1 | 1 | use color_eyre::eyre::{eyre, Context, ContextCompat, Result}; |
2 | 2 | use convert_case::{Case, Casing}; |
| 3 | +use regex::Regex; |
3 | 4 | use std::path::Path; |
| 5 | +use std::sync::LazyLock; |
4 | 6 |
|
5 | 7 | use crate::parsing::{find_suite, find_test, get_group_comment, get_groups, get_suite_chunk}; |
6 | 8 | use crate::runner::Runner; |
7 | 9 | use crate::target::Target; |
8 | 10 | use crate::ConfigMeta; |
9 | 11 | use crate::{document::Document, group::Group, suite::Suite, test::Test}; |
10 | 12 |
|
| 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 | + |
11 | 17 | fn case_from_str(s: &str) -> Result<Case> { |
12 | 18 | match s { |
13 | 19 | "Alternating" => Ok(Case::Alternating), |
@@ -36,9 +42,12 @@ fn case_from_str(s: &str) -> Result<Case> { |
36 | 42 | } |
37 | 43 |
|
38 | 44 | 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| { |
40 | 46 | 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() |
42 | 51 | } |
43 | 52 |
|
44 | 53 | pub fn insert_after_keyword(original: &str, to_insert: &str, keyword: &str) -> String { |
|
0 commit comments