Re: [GSOC][PATCH] userdiff: Add JavaScript function patterns
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Mar 4, 2024, 09:04 UTC
- Message-ID
- <ZeWOhxBDvyjH8gW7@tanuki>
- In-Reply-To
- <20240301074048.188835-1-sergiusnyah@gmail.com>
On Fri, Mar 01, 2024 at 08:40:48AM +0100, Sergius Nyah wrote:
Show 41 quoted lines
> This commit adds a patterns used to match JavaScript functions.
> It now correctly identifies function declarations, function expressions,
> and functions defined inside blocks. Add test for corresponding change in userdiff.
>
> Signed-off-by: Sergius Nyah <sergiusnyah@gmail.com>
> ---
> t/t4018-diff-funcname.sh | 22 ++++++++++++++++++++++
> userdiff.c | 12 ++++++++++++
> 2 files changed, 34 insertions(+)
>
> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
> index e026fac1f4..d35cce18a0 100755
> --- a/t/t4018-diff-funcname.sh
> +++ b/t/t4018-diff-funcname.sh
> @@ -120,3 +120,25 @@ do
> done
>
> test_done
> +
> +test_expect_success 'identify builtin patterns in JavaScript' '
> + # setup
> + echo "function myFunction() { return true; }" > test.js &&
> + echo "var myVar = function() { return false; }" >> test.js &&
> + git add test.js &&
> + git commit -m "add test.js" &&
> +
> + # modify the file
> + echo "function myFunction() { return false; }" > test.js &&
> + echo "var myVar = function() { return true; }" >> test.js &&
> +
> + # command under test
> + git diff >output &&
> +
> + # check results
> + test_i18ngrep "function myFunction() { return true; }" output &&
> + test_i18ngrep "function myFunction() { return false; }" output &&
> + test_i18ngrep "var myVar = function() { return false; }" output &&
> + test_i18ngrep "var myVar = function() { return true; }" output
> +'
> +test_done
> \ No newline at end of fileThis `test_done` only needs to be added because you add the new test before the preceding `test_done`. Instead, you should move up this test so that it comes before it.
Show 6 quoted lines
> diff --git a/userdiff.c b/userdiff.c
> index 2b1dab2649..bbe2bcb9a3 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> +PATTERNS("javascript",
> + /* Looks for lines that start with optional whitespace, followedMulti-line comments should start with their delimiters on separate lines. So the "/*" should be on its own line.
Also, the code should be indented with tabs and not spaces. It might help to read through Documentation/CodingGuidelines to get more familiar with Git's coding style.
Patrick
Show 13 quoted lines
> + * by 'function'* and any characters (for function declarations),
> + * or valid JavaScript identifiers, equals sign '=', 'function' keyword
> + * and any characters (for function expressions).
> + * Also considers functions defined inside blocks with '{...}'.
> + */
> + "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
> + /* This pattern matches JavaScript identifiers */
> + "[a-zA-Z_$][0-9a-zA-Z_$]*"
> + "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
> + "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),
> --
> 2.43.2
>