ok/jj
1
0
Fork 0
forked from mirrors/jj

Allow negative numbers in the template grammar

This allows negative numbers, which also means functions which took numbers can now take negative numbers

Luckily, they all already handled this exactly as expected.
This commit is contained in:
Zachary Dremann 2023-08-22 14:40:51 -04:00
parent 6b5544f335
commit 9702a425e5
3 changed files with 80 additions and 2 deletions

View file

@ -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 | "_")* }

View file

@ -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

View file

@ -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" ++