Skip to content

Commit

Permalink
feat: support escaping @ in the comment (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Nov 15, 2024
1 parent 49825fa commit 5c89c51
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ fn take_comment_lines(lines: &[&str], idx: usize, output: &mut String) -> usize
for line in lines.iter().skip(idx) {
if let Ok((text, _)) = parse_normal_comment(line) {
output.push('\n');
let text = match text.strip_prefix("\\@") {
Some(v) => v,
None => text,
};
output.push_str(text);
count += 1;
} else {
Expand Down
38 changes: 38 additions & 0 deletions tests/snapshots/integration__validate__escape_at_symbol.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
source: tests/validate.rs
expression: data
---
************ RUN ************
prog -h

# OUTPUT
command cat >&2 <<-'EOF'
Patch utils

Here is an example of a patch block:
--- a/hello.py
+++ b/hello.py
@ ... @@
def hello():
- print("Hello World")
+ name = input("What is your name? ")
+ print(f"Hello {name}")

USAGE: prog

EOF
exit 0

# RUN_OUTPUT
Patch utils

Here is an example of a patch block:
--- a/hello.py
+++ b/hello.py
@ ... @@
def hello():
- print("Hello World")
+ name = input("What is your name? ")
+ print(f"Hello {name}")

USAGE: prog
17 changes: 17 additions & 0 deletions tests/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ fn help_notations() {
snapshot_multi!(script, [vec!["prog", "-h"]]);
}

#[test]
fn escape_at_symbol() {
let script = r###"
# @describe Patch utils
#
# Here is an example of a patch block:
# --- a/hello.py
# +++ b/hello.py
# \@@ ... @@
# def hello():
# - print("Hello World")
# + name = input("What is your name? ")
# + print(f"Hello {name}")
"###;
snapshot_multi!(script, [vec!["prog", "-h"]]);
}

#[test]
fn version_missing() {
let script = r###"
Expand Down

0 comments on commit 5c89c51

Please sign in to comment.