Subject: [PATCH v3 33/35] userdiff golang: match multi-line "const" and "import"

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Wed, 24 Feb 2021 20:51:27 +0100

Add matching rules for the very common pattern of having a multi-line
"import" or "const" declaration near the start of the "package"
line. Before this change we'd skip this and match whatever came before
it, e.g. the "package" line.

Signed-off-by: Ævar Arnfjörð Bjarmason <[email-masked]>
---
 t/t4018/golang | 26 ++++++++++++++++++++++++++
 userdiff.c     |  2 ++
 2 files changed, 28 insertions(+)

diff --git a/t/t4018/golang b/t/t4018/golang
index 38f254cd269..7f51fa02203 100644
--- a/t/t4018/golang
+++ b/t/t4018/golang
@@ -47,6 +47,32 @@ package camelCase
 import "fmt"
 // ChangeMe
 
+t4018 description: import (
+t4018 header: import (
+package somePackage
+
+import (
+	"os"
+	ChangeMe
+)
+
+t4018 description: const (
+t4018 header: const (
+package somePackage
+
+const (
+	Foo = 1
+	Bar = ChangeMe
+)
+
+t4018 description: const rule is selective
+t4018 header: package main
+package main
+
+const Foo = "Bar"
+
+// ChangeMe
+
 t4018 description: complex function
 t4018 header: func (t *Test) RIGHT(a Type) (Type, error) {
 type Test struct {
diff --git a/userdiff.c b/userdiff.c
index bbbbfa33e0a..c4a2bfaed70 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -132,6 +132,8 @@ PATTERNS("golang",
 	 "^(package[ \t][a-z][A-Za-z0-9_]+)[ \t]*\n"
 	 /* Functions */
 	 "^(func[ \t].*)\n"
+	 /* const & import */
+	 "^((import|const)[ \t]*\\([ \t]*)\n"
 	 /* Structs and interfaces */
 	 "^(type[ \t].*[ \t](struct|interface)[ \t].*)",
 	 /* -- */
-- 
2.30.0.284.gd98b1dd5eaa7