Skip to content

Commit ca3b719

Browse files
authored
Support mutli-line code inlines in descriptives (#71)
Much to my surprise, a code inline in a descriptive wasn't working if it was spread over several lines. This branch fixes that scenario so an inline containing a multiline string or even just a function call spread over several lines is still valid.
2 parents 4875a24 + 803264a commit ca3b719

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

src/parsing/parser.rs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,7 @@ fn is_enum_response(content: &str) -> bool {
24022402

24032403
/// Detect response patterns with double quotes
24042404
fn malformed_response_pattern(content: &str) -> bool {
2405-
let re = regex!(r#"^\s*".+?"(\s*\|\s*".+?")*"#);
2405+
let re = regex!(r#"^\s*".+?"(\s*\|\s*".+?")+\s*$"#);
24062406
re.is_match(content)
24072407
}
24082408

@@ -4339,4 +4339,69 @@ echo test
43394339
}
43404340
);
43414341
}
4342+
4343+
#[test]
4344+
fn multiline_code_inline() {
4345+
let mut input = Parser::new();
4346+
4347+
// Test multiline code inline in descriptive text
4348+
let source = r#"
4349+
This is { exec(a,
4350+
b, c)
4351+
} a valid inline.
4352+
"#;
4353+
4354+
input.initialize(source);
4355+
let result = input.read_descriptive();
4356+
4357+
assert!(
4358+
result.is_ok(),
4359+
"Multiline code inline should parse successfully"
4360+
);
4361+
4362+
let paragraphs = result.unwrap();
4363+
assert_eq!(paragraphs.len(), 1, "Should have exactly one paragraph");
4364+
4365+
let descriptives = &paragraphs[0].0;
4366+
assert_eq!(
4367+
descriptives.len(),
4368+
3,
4369+
"Should have 3 descriptive elements: text, code inline, text"
4370+
);
4371+
4372+
// First element should be "This is"
4373+
match &descriptives[0] {
4374+
Descriptive::Text(text) => assert_eq!(*text, "This is"),
4375+
_ => panic!("First element should be text"),
4376+
}
4377+
4378+
// Second element should be the multiline code inline
4379+
match &descriptives[1] {
4380+
Descriptive::CodeInline(Expression::Execution(func)) => {
4381+
assert_eq!(
4382+
func.target
4383+
.0,
4384+
"exec"
4385+
);
4386+
assert_eq!(
4387+
func.parameters
4388+
.len(),
4389+
3
4390+
);
4391+
// Check that all parameters were parsed correctly
4392+
if let Expression::Variable(Identifier(name)) = &func.parameters[0] {
4393+
assert_eq!(*name, "a");
4394+
} else {
4395+
panic!("First parameter should be variable 'a'");
4396+
}
4397+
}
4398+
_ => panic!("Second element should be code inline with function execution"),
4399+
}
4400+
4401+
// Third element should be "a valid inline."
4402+
match &descriptives[2] {
4403+
Descriptive::Text(text) => assert_eq!(*text, "a valid inline."),
4404+
_ => panic!("Third element should be text"),
4405+
}
4406+
}
43424407
}

0 commit comments

Comments
 (0)