userdiff: add tests for Fortran xfuncname regex
The Fortran userdiff patterns, introduced in 909a5494f8 (userdiff.c: add builtin fortran regex patterns, 2010-09-10), predate the test infrastructure for xfuncname patterns, introduced in bfa7d01413 (t4018: an infrastructure to test hunk headers, 2014-03-21). Add tests for the Fortran xfuncname patterns. The test 't/t4018/fortran-comment-keyword' documents a shortcoming of the regex that is fixed in a subsequent commit. While at it, add descriptive comments for the different parts of the regex. Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Philippe Blain committed
Aug 12, 2020 at 22:30 UTC
b79e6925f0ff8ae0afa6554224a5a2e1c41a4605
11 files changed
+100
t/t4018/fortran-block-data
new
+5
@@ -0,0 +1,5 @@
1
+ BLOCK DATA RIGHT
2
+
3
+ COMMON /B/ C, ChangeMe
4
+ DATA C, ChangeMe / 2.0, 6.0 /
5
+ END
t/t4018/fortran-comment
new
+13
@@ -0,0 +1,13 @@
1
+ module a
2
+
3
+ contains
4
+
5
+ ! subroutine wrong
6
+ subroutine RIGHT
7
+ ! subroutine wrong
8
+
9
+ real ChangeMe
10
+
11
+ end subroutine RIGHT
12
+
13
+ end module a
t/t4018/fortran-comment-keyword
new
+15
@@ -0,0 +1,15 @@
1
+ module a
2
+
3
+ contains
4
+
5
+ subroutine RIGHT (funcA, funcB)
6
+
7
+ real funcA ! grid function a
8
+ real funcB ! grid function b
9
+
10
+ real ChangeMe
11
+ integer broken
12
+
13
+ end subroutine RIGHT
14
+
15
+ end module a
t/t4018/fortran-comment-legacy
new
+13
@@ -0,0 +1,13 @@
1
+ module a
2
+
3
+ contains
4
+
5
+C subroutine wrong
6
+ subroutine RIGHT
7
+C subroutine wrong
8
+
9
+ real ChangeMe
10
+
11
+ end subroutine RIGHT
12
+
13
+ end module a
t/t4018/fortran-comment-legacy-star
new
+13
@@ -0,0 +1,13 @@
1
+ module a
2
+
3
+ contains
4
+
5
+* subroutine wrong
6
+ subroutine RIGHT
7
+* subroutine wrong
8
+
9
+ real ChangeMe
10
+
11
+ end subroutine RIGHT
12
+
13
+ end module a
t/t4018/fortran-external-function
new
+9
@@ -0,0 +1,9 @@
1
+function RIGHT(a, b) result(c)
2
+
3
+integer, intent(in) :: ChangeMe
4
+integer, intent(in) :: b
5
+integer, intent(out) :: c
6
+
7
+c = a+b
8
+
9
+end function RIGHT
t/t4018/fortran-external-subroutine
new
+5
@@ -0,0 +1,5 @@
1
+subroutine RIGHT
2
+
3
+real ChangeMe
4
+
5
+end subroutine RIGHT
t/t4018/fortran-module
new
+5
@@ -0,0 +1,5 @@
1
+module RIGHT
2
+
3
+use ChangeMe
4
+
5
+end module RIGHT
t/t4018/fortran-module-procedure
new
+13
@@ -0,0 +1,13 @@
1
+ module RIGHT
2
+
3
+ implicit none
4
+ private
5
+
6
+ interface letters ! generic interface
7
+ module procedure aaaa, &
8
+ bbbb, &
9
+ ChangeMe, &
10
+ dddd
11
+ end interface
12
+
13
+end module RIGHT
t/t4018/fortran-program
new
+5
@@ -0,0 +1,5 @@
1
+program RIGHT
2
+
3
+call ChangeMe
4
+
5
+end program RIGHT
userdiff.c
+4
@@ -46,9 +46,13 @@ PATTERNS("elixir",
46
/* Not real operators, but should be grouped */
47
"|:?%[A-Za-z0-9_.]\\{\\}?"),
48
IPATTERN("fortran",
49
+ /* Don't match comment lines */
50
"!^([C*]|[ \t]*!)\n"
51
+ /* Don't match 'module procedure' lines */
52
"!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
53
+ /* Program, module, block data */
54
"^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA"
55
+ /* Subroutines and functions */
56
"|([^'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
57
/* -- */
58
"[a-zA-Z][a-zA-Z0-9_]*"