Skip to content

Commit

Permalink
Add more tests for x expression markers
Browse files Browse the repository at this point in the history
  • Loading branch information
jpikl committed Mar 30, 2024
1 parent f2fa343 commit 7b69737
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 0 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
0.4
- Rething syntax of `rew x` expression prefixes `:#`.
- Better shell specific examples for `rew x` + cleanup and reorder all `rew x` examples.
- Add `REW_PREFIX` env var to enforce stderr prefix over detecting it from argv[0]?
- Refactor and split `x.rs` into multiple files.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/rew-x.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ rew x '{!seq 1 3}. {}'
</div>
</div>

The `#` marker makes the rest of the expression to be interpreted by the current shell.
The `#` marker denotes "raw shell expression". Everything after it will be interpreted by the current shell.

For example, the following expression is equivalent to `{sh -c 'printf "%s\n" a b c'}`

Expand Down
3 changes: 2 additions & 1 deletion src/commands/x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ pub const META: Meta = command_meta! {
input: &["first", "second", "third"],
output: &["1. first", "2. second", "3. third"],
},
"The `#` marker makes the rest of the expression to be interpreted by the current shell.\n\n\
"The `#` marker denotes \"raw shell expression\". \
Everything after it will be interpreted by the current shell.\n\n\
For example, the following expression is equivalent to `{sh -c 'printf \"%s\\n\" a b c'}`": {
args: &["{# printf '%s\\n' a b c}. {}"],
input: &["first", "second", "third"],
Expand Down
8 changes: 8 additions & 0 deletions src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,18 @@ mod tests {
#[case("{:# n1|n2}", "{:#`n1|n2`}")]
#[case("{ :#n1|n2}", "{`:#n1`|`n2`}")] // :# is part for command name
#[case("{ :# n1|n2}", "{`:#` `n1`|`n2`}")] // :# is separate command
#[case("{: #n1|n2}", "{:`#n1`|`n2`}")] // # is part for command name
#[case("{: # n1|n2}", "{:`#` `n1`|`n2`}")] // # is separate command
#[case("{ : #n1|n2}", "{`:` `#n1`|`n2`}")] // : is separate command, # is part of its argument
#[case("{ : # n1|n2}", "{`:` `#` `n1`|`n2`}")] // : is separate command, # is its argument
#[case("{#:n1|n2}", "{#`:n1|n2`}")] // : is part of shell command
#[case("{#: n1|n2}", "{#`: n1|n2`}")] // : is part of shell command
#[case("{ #:n1|n2}", "{`#:n1`|`n2`}")] // #: is part for command name
#[case("{ #: n1|n2}", "{`#:` `n1`|`n2`}")] // #: is separate command
#[case("{# :n1|n2}", "{#`:n1|n2`}")] // : is part for command name
#[case("{# : n1|n2}", "{#`: n1|n2`}")] // : is separate command
#[case("{ # :n1|n2}", "{`#` `:n1`|`n2`}")] // # is separate command, : is part of its argument
#[case("{ # : n1|n2}", "{`#` `:` `n1`|`n2`}")] // # is separate command, : is its argument
// Escaping - General
#[case("%%", "%")]
#[case("%n", "\n")]
Expand Down

0 comments on commit 7b69737

Please sign in to comment.