Skip to content

Commit

Permalink
refactor: remove unnecessary newline
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Mar 6, 2022
1 parent 4d7a7a0 commit 5a39c64
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'a> Cmd<'a> {
values.push(format!("{}__{}={}", VARIABLE_PREFIX, "call", fn_name));
}
}
values.join("")
values.join("\n").trim().to_string()
}
fn add_arg(&mut self, arg_data: &'a ArgData, position: &Position) -> Result<()> {
let arg_data = WrapArgData::new(arg_data, self.positional_idx);
Expand Down Expand Up @@ -319,17 +319,17 @@ impl<'a> WrapArgData<'a> {
return None;
}
if self.kind == ArgKind::Flag {
return Some(format!("{}_{}=1\n", VARIABLE_PREFIX, name));
return Some(format!("{}_{}=1", VARIABLE_PREFIX, name));
}
if self.multiple {
return matches.values_of(self.name).map(|values| {
let values: Vec<String> = values.map(escape_value).collect();
format!("{}_{}=( {} )\n", VARIABLE_PREFIX, name, values.join(" "))
format!("{}_{}=( {} )", VARIABLE_PREFIX, name, values.join(" "))
});
}
matches
.value_of(self.name)
.map(|value| format!("{}_{}={}\n", VARIABLE_PREFIX, name, escape_value(value)))
.map(|value| format!("{}_{}={}", VARIABLE_PREFIX, name, escape_value(value)))
}
fn detect_conflict(
&self,
Expand Down
14 changes: 7 additions & 7 deletions tests/escape_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const SCRIPT: &str = r###"

#[test]
fn test_syntax_error() {
plain!(SCRIPT, &["prog", "$foo"], stdout: "argc_value=\\$foo\n",);
plain!(SCRIPT, &["prog", "`pwd`"], stdout: "argc_value=\\`pwd\\`\n",);
plain!(SCRIPT, &["prog", "$(pwd)"], stdout: "argc_value=\\$\\(pwd\\)\n",);
plain!(SCRIPT, &["prog", "'"], stdout: "argc_value=\\'\n",);
plain!(SCRIPT, &["prog", "\\1"], stdout: "argc_value=\\\\1\n",);
plain!(SCRIPT, &["prog", ""], stdout: "argc_value=''\n",);
plain!(SCRIPT, &["prog", "\n"], stdout: "argc_value='\n'\n",);
plain!(SCRIPT, &["prog", "$foo"], stdout: "argc_value=\\$foo",);
plain!(SCRIPT, &["prog", "`pwd`"], stdout: "argc_value=\\`pwd\\`",);
plain!(SCRIPT, &["prog", "$(pwd)"], stdout: "argc_value=\\$\\(pwd\\)",);
plain!(SCRIPT, &["prog", "'"], stdout: "argc_value=\\'",);
plain!(SCRIPT, &["prog", "\\1"], stdout: "argc_value=\\\\1",);
plain!(SCRIPT, &["prog", ""], stdout: "argc_value=''",);
plain!(SCRIPT, &["prog", "\n"], stdout: "argc_value='\n'",);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: tests/spec_test.rs
assertion_line: 133
assertion_line: 143
expression: output

---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: tests/spec_test.rs
assertion_line: 139
assertion_line: 156
expression: output

---
Expand Down

0 comments on commit 5a39c64

Please sign in to comment.