threads / patch / 48823

patch, 2 partsuserdiff: support new keywords in PHP hunk header

Subject: [PATCH 0/2] userdiff: support new keywords in PHP hunk header

## tl;dr

4 messages between Jul 3, 2018 and Jul 6, 2018. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Kana Natsuno· Jul 3, 2018, 13:15 UTC · lore

Recent version of PHP supports interface, trait, abstract class and final class. This patch fixes the PHP hunk header regexp to support all of these keywords.

Kana Natsuno (2):
  t4018: add missing test cases for PHP
  userdiff: support new keywords in PHP hunk header
 t/t4018/php-abstract-class | 4 ++++
 t/t4018/php-class          | 4 ++++
 t/t4018/php-final-class    | 4 ++++
 t/t4018/php-function       | 4 ++++
 t/t4018/php-interface      | 4 ++++
 t/t4018/php-method         | 7 +++++++
 t/t4018/php-trait          | 7 +++++++
 userdiff.c                 | 2 +-
 8 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 t/t4018/php-abstract-class
 create mode 100644 t/t4018/php-class
 create mode 100644 t/t4018/php-final-class
 create mode 100644 t/t4018/php-function
 create mode 100644 t/t4018/php-interface
 create mode 100644 t/t4018/php-method
 create mode 100644 t/t4018/php-trait
-- 
2.10.1 (Apple Git-78)
Kana Natsuno· Jul 3, 2018, 13:15 UTC · re: Kana Natsuno · lore

[PATCH 1/2] t4018: add missing test cases for PHP

A later patch changes the built-in PHP pattern. These test cases demonstrate aspects of the pattern that we do not want to change.

Signed-off-by: Kana Natsuno <dev@whileimautomaton.net>
---
 t/t4018/php-class    | 4 ++++
 t/t4018/php-function | 4 ++++
 t/t4018/php-method   | 7 +++++++
 3 files changed, 15 insertions(+)
 create mode 100644 t/t4018/php-class
 create mode 100644 t/t4018/php-function
 create mode 100644 t/t4018/php-method
Show changes to 3 files +15 −0

t/t4018/php-class, t/t4018/php-function, t/t4018/php-method

diff --git a/t/t4018/php-class b/t/t4018/php-class
new file mode 100644
index 0000000..7785b63
--- /dev/null
+++ b/t/t4018/php-class
@@ -0,0 +1,4 @@
+class RIGHT
+{
+    const FOO = 'ChangeMe';
+}
diff --git a/t/t4018/php-function b/t/t4018/php-function
new file mode 100644
index 0000000..35717c5
--- /dev/null
+++ b/t/t4018/php-function
@@ -0,0 +1,4 @@
+function RIGHT()
+{
+    return 'ChangeMe';
+}
diff --git a/t/t4018/php-method b/t/t4018/php-method
new file mode 100644
index 0000000..03af1a6
--- /dev/null
+++ b/t/t4018/php-method
@@ -0,0 +1,7 @@
+class Klass
+{
+    public static function RIGHT()
+    {
+        return 'ChangeMe';
+    }
+}
-- 
2.10.1 (Apple Git-78)
Junio C Hamano· Jul 6, 2018, 21:59 UTC · re: Kana Natsuno · lore

Re: [PATCH 1/2] t4018: add missing test cases for PHP

Kana Natsuno <dev@whileimautomaton.net> writes:
Show 46 quoted lines
> A later patch changes the built-in PHP pattern. These test cases
> demonstrate aspects of the pattern that we do not want to change.
>
> Signed-off-by: Kana Natsuno <dev@whileimautomaton.net>
> ---
>  t/t4018/php-class    | 4 ++++
>  t/t4018/php-function | 4 ++++
>  t/t4018/php-method   | 7 +++++++
>  3 files changed, 15 insertions(+)
>  create mode 100644 t/t4018/php-class
>  create mode 100644 t/t4018/php-function
>  create mode 100644 t/t4018/php-method
>
> diff --git a/t/t4018/php-class b/t/t4018/php-class
> new file mode 100644
> index 0000000..7785b63
> --- /dev/null
> +++ b/t/t4018/php-class
> @@ -0,0 +1,4 @@
> +class RIGHT
> +{
> +    const FOO = 'ChangeMe';
> +}
> diff --git a/t/t4018/php-function b/t/t4018/php-function
> new file mode 100644
> index 0000000..35717c5
> --- /dev/null
> +++ b/t/t4018/php-function
> @@ -0,0 +1,4 @@
> +function RIGHT()
> +{
> +    return 'ChangeMe';
> +}
> diff --git a/t/t4018/php-method b/t/t4018/php-method
> new file mode 100644
> index 0000000..03af1a6
> --- /dev/null
> +++ b/t/t4018/php-method
> @@ -0,0 +1,7 @@
> +class Klass
> +{
> +    public static function RIGHT()
> +    {
> +        return 'ChangeMe';
> +    }
> +}

I no longer speak PHP, and certainly not the modern variant, but these examples all look good to me.

Whoever invented the convetion to use RIGHT/ChangeMe in t4018 should get praised---its brilliance shines in new tests like these ;-)

Kana Natsuno· Jul 3, 2018, 13:15 UTC · re: Kana Natsuno · lore

[PATCH 2/2] userdiff: support new keywords in PHP hunk header

Recent version of PHP supports interface, trait, abstract class and final class. This patch fixes the PHP hunk header regexp to support all of these keywords.

Signed-off-by: Kana Natsuno <dev@whileimautomaton.net>
---
 t/t4018/php-abstract-class | 4 ++++
 t/t4018/php-final-class    | 4 ++++
 t/t4018/php-interface      | 4 ++++
 t/t4018/php-trait          | 7 +++++++
 userdiff.c                 | 2 +-
 5 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 t/t4018/php-abstract-class
 create mode 100644 t/t4018/php-final-class
 create mode 100644 t/t4018/php-interface
 create mode 100644 t/t4018/php-trait
Show changes to 5 files +20 −1

t/t4018/php-abstract-class, t/t4018/php-final-class, t/t4018/php-interface, t/t4018/php-trait, userdiff.c

diff --git a/t/t4018/php-abstract-class b/t/t4018/php-abstract-class
new file mode 100644
index 0000000..5213e12
--- /dev/null
+++ b/t/t4018/php-abstract-class
@@ -0,0 +1,4 @@
+abstract class RIGHT
+{
+    const FOO = 'ChangeMe';
+}
diff --git a/t/t4018/php-final-class b/t/t4018/php-final-class
new file mode 100644
index 0000000..69f5710
--- /dev/null
+++ b/t/t4018/php-final-class
@@ -0,0 +1,4 @@
+final class RIGHT
+{
+    const FOO = 'ChangeMe';
+}
diff --git a/t/t4018/php-interface b/t/t4018/php-interface
new file mode 100644
index 0000000..86b49ad
--- /dev/null
+++ b/t/t4018/php-interface
@@ -0,0 +1,4 @@
+interface RIGHT
+{
+    public function foo($ChangeMe);
+}
diff --git a/t/t4018/php-trait b/t/t4018/php-trait
new file mode 100644
index 0000000..65b8c82
--- /dev/null
+++ b/t/t4018/php-trait
@@ -0,0 +1,7 @@
+trait RIGHT
+{
+    public function foo($ChangeMe)
+    {
+        return 'foo';
+    }
+}
diff --git a/userdiff.c b/userdiff.c
index a69241b..36af25e 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -114,7 +114,7 @@ PATTERNS("perl",
 	 "|<<|<>|<=>|>>"),
 PATTERNS("php",
 	 "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
-	 "^[\t ]*(class.*)$",
+	 "^[\t ]*((((final|abstract)[\t ]+)?class|interface|trait).*)$",
 	 /* -- */
 	 "[a-zA-Z_][a-zA-Z0-9_]*"
 	 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
-- 
2.10.1 (Apple Git-78)

← back to recent threads