diff --git a/cli/src/template.pest b/cli/src/template.pest index d73cddc59..232bd4542 100644 --- a/cli/src/template.pest +++ b/cli/src/template.pest @@ -25,8 +25,8 @@ raw_literal = @{ literal_char+ } literal = { "\"" ~ (raw_literal | escape)* ~ "\"" } integer_literal = { - ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* - | "0" + "-"? ~ ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* + | "-"? ~ "0" } identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* } diff --git a/cli/tests/test_log_command.rs b/cli/tests/test_log_command.rs index 0973f1f96..0f2ce72b0 100644 --- a/cli/tests/test_log_command.rs +++ b/cli/tests/test_log_command.rs @@ -632,6 +632,16 @@ fn test_log_shortest_length_parameter() { @ 2 ◉ 0 "###); + insta::assert_snapshot!( + test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id.shortest(-0)"]), @r###" + @ 2 + ◉ 0 + "###); + insta::assert_snapshot!( + test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id.shortest(-100)"]), @r###" + @ 2 + ◉ 0 + "###); insta::assert_snapshot!( test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id.shortest(100)"]), @r###" @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 diff --git a/cli/tests/test_templater.rs b/cli/tests/test_templater.rs index 4d6a8b0c1..401a5728b 100644 --- a/cli/tests/test_templater.rs +++ b/cli/tests/test_templater.rs @@ -164,6 +164,14 @@ fn test_templater_parse_error() { | = Method "foo" doesn't exist for type "Integer" "###); + insta::assert_snapshot!(render_err(r#"(-empty)"#), @r###" + Error: Failed to parse template: --> 1:2 + | + 1 | (-empty) + | ^--- + | + = expected template + "###); insta::assert_snapshot!(render_err(r#"("foo" ++ "bar").baz()"#), @r###" Error: Failed to parse template: --> 1:18 @@ -516,6 +524,66 @@ fn test_templater_fill_function() { over the lazy dog "###); + // A low value will not chop words, but can chop a label by words + insta::assert_snapshot!( + render(r#"fill(9, "Longlonglongword an some short words " ++ + label("error", "longlonglongword and short words") ++ " back out\n")"#), + @r###" + Longlonglongword + an some + short + words + longlonglongword + and short + words + back out + "###); + + // Filling to 0 means breaking at every word + insta::assert_snapshot!( + render(r#"fill(0, "The quick fox jumps over the " ++ + label("error", "lazy") ++ " dog\n")"#), + @r###" + The + quick + fox + jumps + over + the + lazy + dog + "###); + + // Filling to -0 is the same as 0 + insta::assert_snapshot!( + render(r#"fill(-0, "The quick fox jumps over the " ++ + label("error", "lazy") ++ " dog\n")"#), + @r###" + The + quick + fox + jumps + over + the + lazy + dog + "###); + + // Filling to negatives are clamped to the same as zero + insta::assert_snapshot!( + render(r#"fill(-10, "The quick fox jumps over the " ++ + label("error", "lazy") ++ " dog\n")"#), + @r###" + The + quick + fox + jumps + over + the + lazy + dog + "###); + // Word-wrap, then indent insta::assert_snapshot!( render(r#""START marker to help insta\n" ++