diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 4bd2a1c..a3c4577 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -121,6 +121,24 @@ do
! grep fatal msg &&
! grep error msg
'
+
+ for f in "$TEST_DIRECTORY"/t4018/*.$p; do
+ test -f "$f" || continue
+ name=`basename "$f" .$p`
+ test_expect_which=test_expect_success
+ if test "$name" != "${name#broken_}"; then
+ name=${name#broken_}
+ test_expect_which=test_expect_failure
+ fi
+ $test_expect_which \
+ "builtin $p pattern works correctly for $name case" "
+ echo \"*.$p diff=$p\" >.gitattributes &&
+ sed -e 's/ChangeMe/IWasChanged/' < \"$f\" > \"$name.$p\" &&
+ test_expect_code 1 git diff -U1 --no-index \"$f\" \
+ \"$name.$p\" >actual &&
+ egrep '^@@ .* @@ .*RIGHT' actual
+ "
+ done
done
test_expect_success 'default behaviour' 'diff --git a/t/t4018/broken_class_constructor.cpp b/t/t4018/broken_class_constructor.cpp
new file mode 100644
index 0000000..774c7f9
--- /dev/null
+++ b/t/t4018/broken_class_constructor.cpp
@@ -0,0 +1,16 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+RIGHT_function_hunk_header::RIGHT_function_hunk_header (void)
+{
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/broken_class_destructor.cpp b/t/t4018/broken_class_destructor.cpp
new file mode 100644
index 0000000..3045fd1
--- /dev/null
+++ b/t/t4018/broken_class_destructor.cpp
@@ -0,0 +1,16 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+RIGHT_function_hunk_header::~RIGHT_function_hunk_header (void)
+{
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/broken_gnu_style.cpp b/t/t4018/broken_gnu_style.cpp
new file mode 100644
index 0000000..58e574a
--- /dev/null
+++ b/t/t4018/broken_gnu_style.cpp
@@ -0,0 +1,17 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+int
+RIGHT_function_hunk_header (void)
+{
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/broken_reference.cpp b/t/t4018/broken_reference.cpp
new file mode 100644
index 0000000..4d4549f
--- /dev/null
+++ b/t/t4018/broken_reference.cpp
@@ -0,0 +1,16 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+int& RIGHT_function_hunk_header (void)
+{
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/broken_template.cpp b/t/t4018/broken_template.cpp
new file mode 100644
index 0000000..5c62e73
--- /dev/null
+++ b/t/t4018/broken_template.cpp
@@ -0,0 +1,16 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+template <class T> int RIGHT_function_hunk_header (T unused)
+{
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/class_method.cpp b/t/t4018/class_method.cpp
new file mode 100644
index 0000000..fe53620
--- /dev/null
+++ b/t/t4018/class_method.cpp
@@ -0,0 +1,16 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+int test_class::RIGHT_function_hunk_header (void)
+{
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/ignore_declaration.cpp b/t/t4018/ignore_declaration.cpp
new file mode 100644
index 0000000..ce7a0f6
--- /dev/null
+++ b/t/t4018/ignore_declaration.cpp
@@ -0,0 +1,17 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+int RIGHT_function_hunk_header (void)
+{
+ void WRONG_function_declaration_within_body (void);
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/ignore_global.cpp b/t/t4018/ignore_global.cpp
new file mode 100644
index 0000000..95e23bc
--- /dev/null
+++ b/t/t4018/ignore_global.cpp
@@ -0,0 +1,19 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+int RIGHT_function_hunk_header (void)
+{
+ printf("Hello, world\n");
+ return 0;
+}
+
+int WRONG_global_variable;
+
+int ChangeMe;
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/ignore_label.cpp b/t/t4018/ignore_label.cpp
new file mode 100644
index 0000000..a8f407d
--- /dev/null
+++ b/t/t4018/ignore_label.cpp
@@ -0,0 +1,17 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+int RIGHT_function_hunk_header (void)
+{
+WRONG_should_not_match_label:
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/pointer_return.cpp b/t/t4018/pointer_return.cpp
new file mode 100644
index 0000000..ea30d2d
--- /dev/null
+++ b/t/t4018/pointer_return.cpp
@@ -0,0 +1,16 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+static int *RIGHT_function_hunk_header (void)
+{
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/simple.cpp b/t/t4018/simple.cpp
new file mode 100644
index 0000000..c96ad87
--- /dev/null
+++ b/t/t4018/simple.cpp
@@ -0,0 +1,32 @@
+/*
+ * Test file for testing the internal hunk header patterns
+ *
+ * The "RIGHT" hunk header function, the one that should appear on the
+ * hunk header line, should be named "RIGHT_function_hunk_header" and
+ * the body of this function should have an assignment that looks like
+ *
+ * answer = 0
+ *
+ * within it, deep enough so the lines of context do not include the
+ * function name.
+ *
+ * If the name of this file begins with "broken_", then it will be
+ * interpreted as a pattern which does not work, but which should.
+ */
+
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+int RIGHT_function_hunk_header (void)
+{
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}diff --git a/t/t4018/static.cpp b/t/t4018/static.cpp
new file mode 100644
index 0000000..f6ee0f3
--- /dev/null
+++ b/t/t4018/static.cpp
@@ -0,0 +1,16 @@
+int WRONG_function_hunk_header_preceding_the_right_one (void)
+{
+ return 0;
+}
+
+static int RIGHT_function_hunk_header (void)
+{
+ const char *msg = "ChangeMe";
+ printf("Hello, world, %s\n", msg);
+ return 0;
+}
+
+int WRONG_function_hunk_header_following_the_right_one (void)
+{
+ return 0;
+}--
1.7.8