From bb88ad3db3ea9a123b929315749217957c12ed9a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 4 Jan 2023 14:06:19 -0600 Subject: [PATCH] fix(trycmd): Allow empty code fences Fixes #190 --- src/schema.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/schema.rs b/src/schema.rs index b575705d..aa649096 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -220,7 +220,9 @@ impl TryCmd { let mut stdout_start; if let Some((line_num, line)) = lines.pop_front() { - if let Some(raw) = line.strip_prefix("$ ") { + if line.starts_with(&fence_pattern) { + break; + } else if let Some(raw) = line.strip_prefix("$ ") { cmdline.extend(shlex::Shlex::new(raw.trim())); cmd_start = line_num; stdout_start = line_num + 1; @@ -772,6 +774,22 @@ mod test { assert_eq!(expected, actual); } + #[test] + fn parse_trycmd_empty_fence() { + let expected = TryCmd { + steps: vec![], + ..Default::default() + }; + let actual = TryCmd::parse_trycmd( + " +``` +``` +", + ) + .unwrap(); + assert_eq!(expected, actual); + } + #[test] fn parse_trycmd_command() { let expected = TryCmd {