Message ID | 20220301155431.2534136-1-jaydeepjd.8914@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | userdiff: add builtin diff driver for Kotlin language. | expand |
Jaydeep P Das <jaydeepjd.8914@gmail.com> writes: > diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt > index a71dad2674..4b36d51beb 100644 > --- a/Documentation/gitattributes.txt > +++ b/Documentation/gitattributes.txt > @@ -829,6 +829,8 @@ patterns are available: > > - `java` suitable for source code in the Java language. > > +- `kotlin` suitable for source code in the Kotlin language. > + > - `markdown` suitable for Markdown documents. > > - `matlab` suitable for source code in the MATLAB and Octave languages. I do not speak the language, but hopefully those who do will find issues and help us correct them if there still are any. The patch organization looks good. Will queue. Thanks. > diff --git a/userdiff.c b/userdiff.c > index 8578cb0d12..f23f098f19 100644 > --- a/userdiff.c > +++ b/userdiff.c > @@ -168,6 +168,13 @@ PATTERNS("java", > "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" > "|[-+*/<>%&^|=!]=" > "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), > +PATTERNS("kotlin", > + "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*[ \t]*)$", > + /* -- */ > + "[a-zA-Z_][a-zA-Z0-9_]*" > + "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" > + "|[-+*/<>%&^|=!]=" > + "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), > PATTERNS("markdown", > "^ {0,3}#{1,6}[ \t].*", > /* -- */
Thanks for the review. I have some criticism regarding `t/t4018-diff-funcname.sh`. When any test fails, its verbose output is not "verbose" enough. For example, If due to wrong xfuncname regex or wrong test, all of the following hunk headers @@...@@ @@...@@fun right(){ @@...@@fun produce the same verbose output: `not ok:....hunk header:[testfilename]` Initially, I had a difficult time to debug what was going wrong so as a temporary fix, I made `t/t4018-diff-funcname.sh` to `cat` out the hunk stored in `actual`. ``` # check each individual file for i in $(git ls-files) do test_expect_success "hunk header of file: $i" " git diff -U1 $i >actual && echo 'hunk:' && cat actual && echo && grep '@@ .* @@.*RIGHT' actual " done ``` Is there another proper way to make the test script produce the hunk for each test? Thanks, Jaydeep.
Am 01.03.22 um 16:54 schrieb Jaydeep P Das: > diff --git a/t/t4018/kotlin-nested-fun b/t/t4018/kotlin-nested-fun > new file mode 100644 > index 0000000000..12186858cb > --- /dev/null > +++ b/t/t4018/kotlin-nested-fun > @@ -0,0 +1,9 @@ > +class LEFT{ > + class CENTER{ > + fun RIGHT( a:Int){ > + //comment > + //comment > + ChangeMe > + } > + } > +} Nice move to include a test with an indented key phrase. The t4018 test cases all look fine. I don't speek Kotlin, though, so... > diff --git a/t/t4034/kotlin/expect b/t/t4034/kotlin/expect > new file mode 100644 > index 0000000000..80eea3e386 > --- /dev/null > +++ b/t/t4034/kotlin/expect > @@ -0,0 +1,33 @@ > +<BOLD>diff --git a/pre b/post<RESET> > +<BOLD>index e8a199a..e6ebebb 100644<RESET> > +<BOLD>--- a/pre<RESET> > +<BOLD>+++ b/post<RESET> > +<CYAN>@@ -1,16 +1,16 @@<RESET> > +println("Hello World<RED>!\n<RESET><GREEN>?<RESET>") > +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<RED>0xabcdef<RESET><GREEN>) (0xaybcdef)<RESET> '<RED>x<RESET><GREEN>y<RESET>' > +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> > +!<RED>a a<RESET><GREEN>x x<RESET>.inv() <RED>a<RESET><GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>&<RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>/<RED>b a<RESET><GREEN>y x<RESET>%<RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET> shl <RED>b a<RESET><GREEN>y x<RESET> shr <RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET><<RED>b a<RESET><GREEN>y x<RESET><=<RED>b a<RESET><GREEN>y x<RESET>><RED>b a<RESET><GREEN>y x<RESET>>=<RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET>==<RED>b a<RESET><GREEN>y x<RESET>!=<RED>b a<RESET><GREEN>y x<RESET>===<RED>b<RESET> > +<RED>a and b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x xnd y<RESET> > +<GREEN>x<RESET>^<RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET> or <RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET>&&<RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET>||<RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> > +<RED>a<RESET><GREEN>y<RESET> > +<GREEN>x<RESET>,y > diff --git a/t/t4034/kotlin/post b/t/t4034/kotlin/post > new file mode 100644 > index 0000000000..e6ebebb5e9 > --- /dev/null > +++ b/t/t4034/kotlin/post > @@ -0,0 +1,16 @@ > +println("Hello World?") > +(1) (-1e10) (0xaybcdef) 'y' > +[x] x->y x.y > +!x x.inv() x*y x&y > +x*y x/y x%y > +x+y x-y > +x shl y x shr y > +x<y x<=y x>y x>=y > +x==y x!=y x===y > +x xnd y > +x^y > +x or y > +x&&y > +x||y > +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y > +x,y > diff --git a/t/t4034/kotlin/pre b/t/t4034/kotlin/pre > new file mode 100644 > index 0000000000..e8a199adb0 > --- /dev/null > +++ b/t/t4034/kotlin/pre > @@ -0,0 +1,16 @@ > +println("Hello World!\n") > +1 -1e10 0xabcdef 'x' > +[a] a->b a.b > +!a a.inv() a*b a&b > +a*b a/b a%b > +a+b a-b > +a shl b a shr b > +a<b a<=b a>b a>=b > +a==b a!=b a===b > +a and b > +a^b > +a or b > +a&&b > +a||b > +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b > +a,y I know you just copied an existing test case. But actually, it misses the important parts of the word regex patterns. In particular, it only tests that a change of a to x is found, but does not test that the operators are not split into individual characters. Please have a look at my series 1cf93847c1ed~..386076ec92c7 and in particular 1cf93847c1ed to see what you actually want to test. For example, you could test a change from a+=b to a-=b, i.e., that operators += and -= are not split into +, -, and =. > diff --git a/userdiff.c b/userdiff.c > index 8578cb0d12..f23f098f19 100644 > --- a/userdiff.c > +++ b/userdiff.c > @@ -168,6 +168,13 @@ PATTERNS("java", > "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" > "|[-+*/<>%&^|=!]=" > "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), > +PATTERNS("kotlin", > + "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*[ \t]*)$", I would guess that the trailing [ \t]* is pointless and always empty, because it is covered by the preceding .*, so you can remove it. > + /* -- */ > + "[a-zA-Z_][a-zA-Z0-9_]*" > + "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" The first part intends to match integers and floatingpoint numbers. Word regex can be loose. This one, however, is too loose. For example, it treats -e+2 as a single token, but that is actually a whole expression consisting of several tokens and is not unlikely to occur in real code. See also 350b87cd6585. I am pretty sure that, e.g., -1 and +2.5 are both two tokens each, i.e., the sign is not part of the number token. Also, it looks like 3.0e5 is a floating point number; is 3.0E5 not? > + "|[-+*/<>%&^|=!]=" > + "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), > PATTERNS("markdown", > "^ {0,3}#{1,6}[ \t].*", > /* -- */ -- Hannes
Am 01.03.22 um 19:09 schrieb jaydeepjd.8914@gmail.com: > When any test fails, its verbose output is not "verbose" enough. > For example, If due to wrong xfuncname regex or wrong test, all of the > following hunk headers > > @@...@@ > @@...@@fun right(){ > @@...@@fun > > produce the same verbose output: > > `not ok:....hunk header:[testfilename]` You run ./t4018-diff-funcname.sh -v -i which stops at the first failing test case. You get expecting success of 4018.160 'hunk header: kotlin-interface': git diff -U1 kotlin-interface >actual && grep '@@ .* @@.*RIGHT' actual not ok 160 - hunk header: kotlin-interface # # git diff -U1 kotlin-interface >actual && # grep '@@ .* @@.*RIGHT' actual # from which you see that you have to inspect the file actual: less trash\ directory.t4018-diff-funcname/actual -- Hannes
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index a71dad2674..4b36d51beb 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -829,6 +829,8 @@ patterns are available: - `java` suitable for source code in the Java language. +- `kotlin` suitable for source code in the Kotlin language. + - `markdown` suitable for Markdown documents. - `matlab` suitable for source code in the MATLAB and Octave languages. diff --git a/t/t4018/kotlin-class b/t/t4018/kotlin-class new file mode 100644 index 0000000000..bb864f22e6 --- /dev/null +++ b/t/t4018/kotlin-class @@ -0,0 +1,5 @@ +class RIGHT { + //comment + //comment + return ChangeMe +} diff --git a/t/t4018/kotlin-enum-class b/t/t4018/kotlin-enum-class new file mode 100644 index 0000000000..8885f908fd --- /dev/null +++ b/t/t4018/kotlin-enum-class @@ -0,0 +1,5 @@ +enum class RIGHT{ + // Left + // a comment + ChangeMe +} diff --git a/t/t4018/kotlin-fun b/t/t4018/kotlin-fun new file mode 100644 index 0000000000..2a60280256 --- /dev/null +++ b/t/t4018/kotlin-fun @@ -0,0 +1,5 @@ +fun RIGHT(){ + //a comment + //b comment + return ChangeMe() +} diff --git a/t/t4018/kotlin-inheritace-class b/t/t4018/kotlin-inheritace-class new file mode 100644 index 0000000000..77376c1f05 --- /dev/null +++ b/t/t4018/kotlin-inheritace-class @@ -0,0 +1,5 @@ +open class RIGHT{ + // a comment + // b comment + // ChangeMe +} diff --git a/t/t4018/kotlin-inline-class b/t/t4018/kotlin-inline-class new file mode 100644 index 0000000000..7bf46dd8d4 --- /dev/null +++ b/t/t4018/kotlin-inline-class @@ -0,0 +1,5 @@ +value class RIGHT(Args){ + // a comment + // b comment + ChangeMe +} diff --git a/t/t4018/kotlin-interface b/t/t4018/kotlin-interface new file mode 100644 index 0000000000..f686ba7770 --- /dev/null +++ b/t/t4018/kotlin-interface @@ -0,0 +1,5 @@ +interface RIGHT{ + //another comment + //another comment + //ChangeMe +} diff --git a/t/t4018/kotlin-nested-fun b/t/t4018/kotlin-nested-fun new file mode 100644 index 0000000000..12186858cb --- /dev/null +++ b/t/t4018/kotlin-nested-fun @@ -0,0 +1,9 @@ +class LEFT{ + class CENTER{ + fun RIGHT( a:Int){ + //comment + //comment + ChangeMe + } + } +} diff --git a/t/t4018/kotlin-public-class b/t/t4018/kotlin-public-class new file mode 100644 index 0000000000..9433fcc226 --- /dev/null +++ b/t/t4018/kotlin-public-class @@ -0,0 +1,5 @@ +public class RIGHT{ + //comment1 + //comment2 + ChangeMe +} diff --git a/t/t4018/kotlin-sealed-class b/t/t4018/kotlin-sealed-class new file mode 100644 index 0000000000..0efa4a4eaf --- /dev/null +++ b/t/t4018/kotlin-sealed-class @@ -0,0 +1,5 @@ +sealed class RIGHT { + // a comment + // b comment + ChangeMe +} diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index d5abcf4b4c..15764ee9ac 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -324,6 +324,7 @@ test_language_driver dts test_language_driver fortran test_language_driver html test_language_driver java +test_language_driver kotlin test_language_driver matlab test_language_driver objc test_language_driver pascal diff --git a/t/t4034/kotlin/expect b/t/t4034/kotlin/expect new file mode 100644 index 0000000000..80eea3e386 --- /dev/null +++ b/t/t4034/kotlin/expect @@ -0,0 +1,33 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index e8a199a..e6ebebb 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,16 +1,16 @@<RESET> +println("Hello World<RED>!\n<RESET><GREEN>?<RESET>") +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<RED>0xabcdef<RESET><GREEN>) (0xaybcdef)<RESET> '<RED>x<RESET><GREEN>y<RESET>' +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> +!<RED>a a<RESET><GREEN>x x<RESET>.inv() <RED>a<RESET><GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>/<RED>b a<RESET><GREEN>y x<RESET>%<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET> shl <RED>b a<RESET><GREEN>y x<RESET> shr <RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET><<RED>b a<RESET><GREEN>y x<RESET><=<RED>b a<RESET><GREEN>y x<RESET>><RED>b a<RESET><GREEN>y x<RESET>>=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>==<RED>b a<RESET><GREEN>y x<RESET>!=<RED>b a<RESET><GREEN>y x<RESET>===<RED>b<RESET> +<RED>a and b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x xnd y<RESET> +<GREEN>x<RESET>^<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET> or <RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>||<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>,y diff --git a/t/t4034/kotlin/post b/t/t4034/kotlin/post new file mode 100644 index 0000000000..e6ebebb5e9 --- /dev/null +++ b/t/t4034/kotlin/post @@ -0,0 +1,16 @@ +println("Hello World?") +(1) (-1e10) (0xaybcdef) 'y' +[x] x->y x.y +!x x.inv() x*y x&y +x*y x/y x%y +x+y x-y +x shl y x shr y +x<y x<=y x>y x>=y +x==y x!=y x===y +x xnd y +x^y +x or y +x&&y +x||y +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y +x,y diff --git a/t/t4034/kotlin/pre b/t/t4034/kotlin/pre new file mode 100644 index 0000000000..e8a199adb0 --- /dev/null +++ b/t/t4034/kotlin/pre @@ -0,0 +1,16 @@ +println("Hello World!\n") +1 -1e10 0xabcdef 'x' +[a] a->b a.b +!a a.inv() a*b a&b +a*b a/b a%b +a+b a-b +a shl b a shr b +a<b a<=b a>b a>=b +a==b a!=b a===b +a and b +a^b +a or b +a&&b +a||b +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b +a,y diff --git a/userdiff.c b/userdiff.c index 8578cb0d12..f23f098f19 100644 --- a/userdiff.c +++ b/userdiff.c @@ -168,6 +168,13 @@ PATTERNS("java", "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" "|[-+*/<>%&^|=!]=" "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), +PATTERNS("kotlin", + "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*[ \t]*)$", + /* -- */ + "[a-zA-Z_][a-zA-Z0-9_]*" + "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" + "|[-+*/<>%&^|=!]=" + "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), PATTERNS("markdown", "^ {0,3}#{1,6}[ \t].*", /* -- */
The xfuncname pattern finds func/class declarations in diffs to display as a hunk header. The word_regex pattern finds individual tokens in Kotlin code to generate appropriate diffs. This patch adds xfuncname regex and word_regex for Kotlin language. Signed-off-by: Jaydeep P Das <jaydeepjd.8914@gmail.com> --- Documentation/gitattributes.txt | 2 ++ t/t4018/kotlin-class | 5 +++++ t/t4018/kotlin-enum-class | 5 +++++ t/t4018/kotlin-fun | 5 +++++ t/t4018/kotlin-inheritace-class | 5 +++++ t/t4018/kotlin-inline-class | 5 +++++ t/t4018/kotlin-interface | 5 +++++ t/t4018/kotlin-nested-fun | 9 +++++++++ t/t4018/kotlin-public-class | 5 +++++ t/t4018/kotlin-sealed-class | 5 +++++ t/t4034-diff-words.sh | 1 + t/t4034/kotlin/expect | 33 +++++++++++++++++++++++++++++++++ t/t4034/kotlin/post | 16 ++++++++++++++++ t/t4034/kotlin/pre | 16 ++++++++++++++++ userdiff.c | 7 +++++++ 15 files changed, 124 insertions(+) create mode 100644 t/t4018/kotlin-class create mode 100644 t/t4018/kotlin-enum-class create mode 100644 t/t4018/kotlin-fun create mode 100644 t/t4018/kotlin-inheritace-class create mode 100644 t/t4018/kotlin-inline-class create mode 100644 t/t4018/kotlin-interface create mode 100644 t/t4018/kotlin-nested-fun create mode 100644 t/t4018/kotlin-public-class create mode 100644 t/t4018/kotlin-sealed-class create mode 100644 t/t4034/kotlin/expect create mode 100644 t/t4034/kotlin/post create mode 100644 t/t4034/kotlin/pre