This commit is contained in:
Casey Rodarmor 2023-11-16 13:51:57 -08:00 committed by GitHub
parent 63c0234c96
commit 53fec7b449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 188 additions and 156 deletions

View File

@ -40,7 +40,7 @@ complete -c just -a '(__fish_just_complete_recipes)'
pub(crate) const ZSH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[ pub(crate) const ZSH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
( (
r#" _arguments "${_arguments_options[@]}" \"#, r#" _arguments "${_arguments_options[@]}" \"#,
r#" local common=("#, r" local common=(",
), ),
( (
r"'*--set=[Override <VARIABLE> with <VALUE>]' \", r"'*--set=[Override <VARIABLE> with <VALUE>]' \",
@ -206,5 +206,5 @@ pub(crate) const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
fi fi
fi"#, fi"#,
), ),
(r#" just)"#, r#" "$1")"#), (r" just)", r#" "$1")"#),
]; ];

View File

@ -669,16 +669,7 @@ mod tests {
} }
} }
macro_rules! test { fn case(input: &str, expected: &str) {
($name:ident, $input:expr, $expected:expr $(,)*) => {
#[test]
fn $name() {
test($input, $expected);
}
};
}
fn test(input: &str, expected: &str) {
let justfile = compile(input); let justfile = compile(input);
let actual = format!("{}", justfile.color_display(Color::never())); let actual = format!("{}", justfile.color_display(Color::never()));
assert_eq!(actual, expected); assert_eq!(actual, expected);
@ -688,8 +679,9 @@ mod tests {
assert_eq!(redumped, actual); assert_eq!(redumped, actual);
} }
test! { #[test]
parse_empty, fn parse_empty() {
case(
" "
# hello # hello
@ -697,10 +689,12 @@ mod tests {
", ",
"", "",
);
} }
test! { #[test]
parse_string_default, fn parse_string_default() {
case(
r#" r#"
foo a="b\t": foo a="b\t":
@ -708,32 +702,37 @@ foo a="b\t":
"#, "#,
r#"foo a="b\t":"#, r#"foo a="b\t":"#,
);
} }
test! { #[test]
parse_multiple, fn parse_multiple() {
r#" case(
r"
a: a:
b: b:
"#, ", r"a:
r#"a:
b:"#, b:",
);
} }
test! { #[test]
parse_variadic, fn parse_variadic() {
r#" case(
r"
foo +a: foo +a:
"#, ",
r#"foo +a:"#, r"foo +a:",
);
} }
test! { #[test]
parse_variadic_string_default, fn parse_variadic_string_default() {
case(
r#" r#"
foo +a="Hello": foo +a="Hello":
@ -741,10 +740,12 @@ foo +a="Hello":
"#, "#,
r#"foo +a="Hello":"#, r#"foo +a="Hello":"#,
);
} }
test! { #[test]
parse_raw_string_default, fn parse_raw_string_default() {
case(
r" r"
foo a='b\t': foo a='b\t':
@ -752,58 +753,68 @@ foo a='b\t':
", ",
r"foo a='b\t':", r"foo a='b\t':",
);
} }
test! { #[test]
parse_export, fn parse_export() {
case(
r#" r#"
export a := "hello" export a := "hello"
"#, "#,
r#"export a := "hello""#, r#"export a := "hello""#,
);
} }
test! { #[test]
parse_alias_after_target, fn parse_alias_after_target() {
r#" case(
r"
foo: foo:
echo a echo a
alias f := foo alias f := foo
"#, ",
r#"alias f := foo r"alias f := foo
foo: foo:
echo a"# echo a",
);
} }
test! { #[test]
parse_alias_before_target, fn parse_alias_before_target() {
r#" case(
r"
alias f := foo alias f := foo
foo: foo:
echo a echo a
"#, ",
r#"alias f := foo r"alias f := foo
foo: foo:
echo a"# echo a",
);
} }
test! { #[test]
parse_alias_with_comment, fn parse_alias_with_comment() {
r#" case(
r"
alias f := foo #comment alias f := foo #comment
foo: foo:
echo a echo a
"#, ",
r#"alias f := foo r"alias f := foo
foo: foo:
echo a"# echo a",
);
} }
test! { #[test]
parse_complex, fn parse_complex() {
case(
" "
x: x:
y: y:
@ -837,11 +848,13 @@ x:
y: y:
z:" z:",
);
} }
test! { #[test]
parse_shebang, fn parse_shebang() {
case(
" "
practicum := 'hello' practicum := 'hello'
install: install:
@ -857,16 +870,17 @@ install:
if [[ -f {{ practicum }} ]]; then if [[ -f {{ practicum }} ]]; then
\treturn \treturn
fi", fi",
);
} }
test! { #[test]
parse_simple_shebang, fn parse_simple_shebang() {
"a:\n #!\n print(1)", case("a:\n #!\n print(1)", "a:\n #!\n print(1)");
"a:\n #!\n print(1)",
} }
test! { #[test]
parse_assignments, fn parse_assignments() {
case(
r#"a := "0" r#"a := "0"
c := a + b + a + b c := a + b + a + b
b := "1" b := "1"
@ -876,10 +890,12 @@ b := "1"
b := "1" b := "1"
c := a + b + a + b"#, c := a + b + a + b"#,
);
} }
test! { #[test]
parse_assignment_backticks, fn parse_assignment_backticks() {
case(
"a := `echo hello` "a := `echo hello`
c := a + b + a + b c := a + b + a + b
b := `echo goodbye`", b := `echo goodbye`",
@ -888,44 +904,47 @@ b := `echo goodbye`",
b := `echo goodbye` b := `echo goodbye`
c := a + b + a + b", c := a + b + a + b",
);
} }
test! { #[test]
parse_interpolation_backticks, fn parse_interpolation_backticks() {
case(
r#"a: r#"a:
echo {{ `echo hello` + "blarg" }} {{ `echo bob` }}"#, echo {{ `echo hello` + "blarg" }} {{ `echo bob` }}"#,
r#"a: r#"a:
echo {{ `echo hello` + "blarg" }} {{ `echo bob` }}"#, echo {{ `echo hello` + "blarg" }} {{ `echo bob` }}"#,
);
} }
test! { #[test]
eof_test, fn eof_test() {
"x:\ny:\nz:\na b c: x y z", case("x:\ny:\nz:\na b c: x y z", "a b c: x y z\n\nx:\n\ny:\n\nz:");
"a b c: x y z\n\nx:\n\ny:\n\nz:",
} }
test! { #[test]
string_quote_escape, fn string_quote_escape() {
r#"a := "hello\"""#, case(r#"a := "hello\"""#, r#"a := "hello\"""#);
r#"a := "hello\"""#,
} }
test! { #[test]
string_escapes, fn string_escapes() {
r#"a := "\n\t\r\"\\""#, case(r#"a := "\n\t\r\"\\""#, r#"a := "\n\t\r\"\\""#);
r#"a := "\n\t\r\"\\""#,
} }
test! { #[test]
parameters, fn parameters() {
case(
"a b c: "a b c:
{{b}} {{c}}", {{b}} {{c}}",
"a b c: "a b c:
{{ b }} {{ c }}", {{ b }} {{ c }}",
);
} }
test! { #[test]
unary_functions, fn unary_functions() {
case(
" "
x := arch() x := arch()
@ -935,10 +954,12 @@ a:
a: a:
{{ os() }} {{ os_family() }} {{ num_cpus() }}", {{ os() }} {{ os_family() }} {{ num_cpus() }}",
);
} }
test! { #[test]
env_functions, fn env_functions() {
case(
r#" r#"
x := env_var('foo',) x := env_var('foo',)
@ -948,42 +969,52 @@ a:
a: a:
{{ env_var_or_default('foo' + 'bar', 'baz') }} {{ env_var(env_var("baz")) }}"#, {{ env_var_or_default('foo' + 'bar', 'baz') }} {{ env_var(env_var("baz")) }}"#,
);
} }
test! { #[test]
parameter_default_string, fn parameter_default_string() {
case(
r#" r#"
f x="abc": f x="abc":
"#, "#,
r#"f x="abc":"#, r#"f x="abc":"#,
);
} }
test! { #[test]
parameter_default_raw_string, fn parameter_default_raw_string() {
r#" case(
r"
f x='abc': f x='abc':
"#, ",
r#"f x='abc':"#, r"f x='abc':",
);
} }
test! { #[test]
parameter_default_backtick, fn parameter_default_backtick() {
r#" case(
r"
f x=`echo hello`: f x=`echo hello`:
"#, ",
r#"f x=`echo hello`:"#, r"f x=`echo hello`:",
);
} }
test! { #[test]
parameter_default_concatenation_string, fn parameter_default_concatenation_string() {
case(
r#" r#"
f x=(`echo hello` + "foo"): f x=(`echo hello` + "foo"):
"#, "#,
r#"f x=(`echo hello` + "foo"):"#, r#"f x=(`echo hello` + "foo"):"#,
);
} }
test! { #[test]
parameter_default_concatenation_variable, fn parameter_default_concatenation_variable() {
case(
r#" r#"
x := "10" x := "10"
f y=(`echo hello` + x) +z="foo": f y=(`echo hello` + x) +z="foo":
@ -991,10 +1022,12 @@ f y=(`echo hello` + x) +z="foo":
r#"x := "10" r#"x := "10"
f y=(`echo hello` + x) +z="foo":"#, f y=(`echo hello` + x) +z="foo":"#,
);
} }
test! { #[test]
parameter_default_multiple, fn parameter_default_multiple() {
case(
r#" r#"
x := "10" x := "10"
f y=(`echo hello` + x) +z=("foo" + "bar"): f y=(`echo hello` + x) +z=("foo" + "bar"):
@ -1002,24 +1035,23 @@ f y=(`echo hello` + x) +z=("foo" + "bar"):
r#"x := "10" r#"x := "10"
f y=(`echo hello` + x) +z=("foo" + "bar"):"#, f y=(`echo hello` + x) +z=("foo" + "bar"):"#,
);
} }
test! { #[test]
concatenation_in_group, fn concatenation_in_group() {
"x := ('0' + '1')", case("x := ('0' + '1')", "x := ('0' + '1')");
"x := ('0' + '1')",
} }
test! { #[test]
string_in_group, fn string_in_group() {
"x := ('0' )", case("x := ('0' )", "x := ('0')");
"x := ('0')",
} }
#[rustfmt::skip] #[rustfmt::skip]
test! { #[test]
escaped_dos_newlines, fn escaped_dos_newlines() {
"@spam:\r case("@spam:\r
\t{ \\\r \t{ \\\r
\t\tfiglet test; \\\r \t\tfiglet test; \\\r
\t\tcargo build --color always 2>&1; \\\r \t\tcargo build --color always 2>&1; \\\r
@ -1031,6 +1063,6 @@ f y=(`echo hello` + x) +z=("foo" + "bar"):"#,
\tfiglet test; \\ \tfiglet test; \\
\tcargo build --color always 2>&1; \\ \tcargo build --color always 2>&1; \\
\tcargo test --color always -- --color always 2>&1; \\ \tcargo test --color always -- --color always 2>&1; \\
} | less", } | less");
} }
} }

View File

@ -1020,11 +1020,11 @@ mod tests {
test! { test! {
name: recipe_named_alias, name: recipe_named_alias,
text: r#" text: r"
[private] [private]
alias: alias:
echo 'echoing alias' echo 'echoing alias'
"#, ",
tree: (justfile tree: (justfile
(recipe alias (body ("echo 'echoing alias'"))) (recipe alias (body ("echo 'echoing alias'")))
), ),
@ -1154,13 +1154,13 @@ mod tests {
test! { test! {
name: recipe_plus_variadic, name: recipe_plus_variadic,
text: r#"foo +bar:"#, text: r"foo +bar:",
tree: (justfile (recipe foo (params +(bar)))), tree: (justfile (recipe foo (params +(bar)))),
} }
test! { test! {
name: recipe_star_variadic, name: recipe_star_variadic,
text: r#"foo *bar:"#, text: r"foo *bar:",
tree: (justfile (recipe foo (params *(bar)))), tree: (justfile (recipe foo (params *(bar)))),
} }
@ -1172,13 +1172,13 @@ mod tests {
test! { test! {
name: recipe_variadic_variable_default, name: recipe_variadic_variable_default,
text: r#"foo +bar=baz:"#, text: r"foo +bar=baz:",
tree: (justfile (recipe foo (params +(bar baz)))), tree: (justfile (recipe foo (params +(bar baz)))),
} }
test! { test! {
name: recipe_variadic_addition_group_default, name: recipe_variadic_addition_group_default,
text: r#"foo +bar=(baz + bob):"#, text: r"foo +bar=(baz + bob):",
tree: (justfile (recipe foo (params +(bar ((+ baz bob)))))), tree: (justfile (recipe foo (params +(bar ((+ baz bob)))))),
} }
@ -1440,9 +1440,9 @@ mod tests {
test! { test! {
name: recipe_variadic_with_default_after_default, name: recipe_variadic_with_default_after_default,
text: r#" text: r"
f a=b +c=d: f a=b +c=d:
"#, ",
tree: (justfile (recipe f (params (a b) +(c d)))), tree: (justfile (recipe f (params (a b) +(c d)))),
} }