]> git.ipfire.org Git - thirdparty/git.git/commitdiff
userdiff: add tests for Fortran xfuncname regex
authorPhilippe Blain <levraiphilippeblain@gmail.com>
Wed, 12 Aug 2020 22:30:28 +0000 (22:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 13 Aug 2020 18:21:17 +0000 (11:21 -0700)
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>
t/t4018/fortran-block-data [new file with mode: 0644]
t/t4018/fortran-comment [new file with mode: 0644]
t/t4018/fortran-comment-keyword [new file with mode: 0644]
t/t4018/fortran-comment-legacy [new file with mode: 0644]
t/t4018/fortran-comment-legacy-star [new file with mode: 0644]
t/t4018/fortran-external-function [new file with mode: 0644]
t/t4018/fortran-external-subroutine [new file with mode: 0644]
t/t4018/fortran-module [new file with mode: 0644]
t/t4018/fortran-module-procedure [new file with mode: 0644]
t/t4018/fortran-program [new file with mode: 0644]
userdiff.c

diff --git a/t/t4018/fortran-block-data b/t/t4018/fortran-block-data
new file mode 100644 (file)
index 0000000..63d4e21
--- /dev/null
@@ -0,0 +1,5 @@
+       BLOCK DATA RIGHT
+       
+       COMMON /B/ C, ChangeMe
+       DATA C, ChangeMe  / 2.0, 6.0 / 
+       END 
diff --git a/t/t4018/fortran-comment b/t/t4018/fortran-comment
new file mode 100644 (file)
index 0000000..7b10d17
--- /dev/null
@@ -0,0 +1,13 @@
+      module a
+
+      contains
+
+      ! subroutine wrong
+      subroutine RIGHT
+      ! subroutine wrong
+
+      real ChangeMe
+
+      end subroutine RIGHT
+
+      end module a
diff --git a/t/t4018/fortran-comment-keyword b/t/t4018/fortran-comment-keyword
new file mode 100644 (file)
index 0000000..c5dbdb4
--- /dev/null
@@ -0,0 +1,15 @@
+      module a
+
+      contains
+
+      subroutine RIGHT (funcA, funcB)
+
+      real funcA  ! grid function a
+      real funcB  ! grid function b
+
+      real ChangeMe
+      integer broken
+
+      end subroutine RIGHT
+
+      end module a
diff --git a/t/t4018/fortran-comment-legacy b/t/t4018/fortran-comment-legacy
new file mode 100644 (file)
index 0000000..53cd062
--- /dev/null
@@ -0,0 +1,13 @@
+      module a
+
+      contains
+
+C subroutine wrong
+      subroutine RIGHT
+C subroutine wrong
+
+      real ChangeMe
+
+      end subroutine RIGHT
+
+      end module a
diff --git a/t/t4018/fortran-comment-legacy-star b/t/t4018/fortran-comment-legacy-star
new file mode 100644 (file)
index 0000000..2cbcdc3
--- /dev/null
@@ -0,0 +1,13 @@
+      module a
+
+      contains
+
+* subroutine wrong
+      subroutine RIGHT
+* subroutine wrong
+
+      real ChangeMe
+
+      end subroutine RIGHT
+
+      end module a
diff --git a/t/t4018/fortran-external-function b/t/t4018/fortran-external-function
new file mode 100644 (file)
index 0000000..5a2d85d
--- /dev/null
@@ -0,0 +1,9 @@
+function RIGHT(a, b) result(c)
+
+integer, intent(in) :: ChangeMe
+integer, intent(in) :: b
+integer, intent(out) :: c
+
+c = a+b
+
+end function RIGHT
diff --git a/t/t4018/fortran-external-subroutine b/t/t4018/fortran-external-subroutine
new file mode 100644 (file)
index 0000000..4ce85fe
--- /dev/null
@@ -0,0 +1,5 @@
+subroutine RIGHT
+
+real ChangeMe
+
+end subroutine RIGHT
diff --git a/t/t4018/fortran-module b/t/t4018/fortran-module
new file mode 100644 (file)
index 0000000..c4b737d
--- /dev/null
@@ -0,0 +1,5 @@
+module RIGHT
+
+use ChangeMe
+
+end module RIGHT
diff --git a/t/t4018/fortran-module-procedure b/t/t4018/fortran-module-procedure
new file mode 100644 (file)
index 0000000..1ce6d85
--- /dev/null
@@ -0,0 +1,13 @@
+ module RIGHT
+
+   implicit none
+   private
+
+   interface letters  ! generic interface
+      module procedure aaaa, &
+                       bbbb, &
+                       ChangeMe, &
+                       dddd
+   end interface
+   
+end module RIGHT
diff --git a/t/t4018/fortran-program b/t/t4018/fortran-program
new file mode 100644 (file)
index 0000000..4616895
--- /dev/null
@@ -0,0 +1,5 @@
+program RIGHT
+
+call ChangeMe
+
+end program RIGHT
index 1df884ef0bbfbba5a751eafc1922369ad818fce5..707d82435ae285fd327af829dd24246bdbeb0a47 100644 (file)
@@ -46,9 +46,13 @@ PATTERNS("elixir",
         /* Not real operators, but should be grouped */
         "|:?%[A-Za-z0-9_.]\\{\\}?"),
 IPATTERN("fortran",
+        /* Don't match comment lines */
         "!^([C*]|[ \t]*!)\n"
+        /* Don't match 'module procedure' lines */
         "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
+        /* Program, module, block data */
         "^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA"
+               /* Subroutines and functions */
                "|([^'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
         /* -- */
         "[a-zA-Z][a-zA-Z0-9_]*"