Repository: Behat/Gherkin (php)

Issue:
Whitespace around language stops detection
We do things slightly differently to cucumber, removing this line will cause a failing test

https://github.com/Behat/Gherkin/blob/efdbe73e590320b9fab535ef3a7c28319b3a063a/tests/Cucumber/CompatibilityTest.php#L55

Pull request description:
feat: Support language tags with whitespace in `gherkin-32` mode
Matches cucumber/gherkin behaviour by allowing language tags with additional whitespace either side of the keyword e.g.

```
 #  language  :   en-lol
```

Fixes #206

Patch:
diff --git a/src/GherkinCompatibilityMode.php b/src/GherkinCompatibilityMode.php
index 6ed5a33..ab80399 100644
--- a/src/GherkinCompatibilityMode.php
+++ b/src/GherkinCompatibilityMode.php
@@ -42,4 +42,15 @@ enum GherkinCompatibilityMode: string
             default => false,
         };
     }
+
+    /**
+     * @internal
+     */
+    public function allowWhitespaceInLanguageTag(): bool
+    {
+        return match ($this) {
+            self::LEGACY => false,
+            default => true,
+        };
+    }
 }
diff --git a/src/Lexer.php b/src/Lexer.php
index 73244f4..20c13fa 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -789,7 +789,11 @@ class Lexer
             return null;
         }
 
-        $token = $this->scanInput('/^\s*#\s*language:\s*([\w_\-]+)\s*$/', 'Language');
+        $pattern = $this->compatibilityMode->allowWhitespaceInLanguageTag()
+            ? '/^\s*#\s*language\s*:\s*([\w_\-]+)\s*$/u'
+            : '/^\s*#\s*language:\s*([\w_\-]+)\s*$/';
+
+        $token = $this->scanInput($pattern, 'Language');
 
         if ($token) {
             \assert(\is_string($token['value']));


Test patch:
diff --git a/tests/Cucumber/CompatibilityTest.php b/tests/Cucumber/CompatibilityTest.php
index c181944..33ac5d5 100644
--- a/tests/Cucumber/CompatibilityTest.php
+++ b/tests/Cucumber/CompatibilityTest.php
@@ -68,7 +68,6 @@ class CompatibilityTest extends TestCase
             'descriptions_with_comments.feature' => 'Examples table descriptions not supported',
             'feature_keyword_in_scenario_description.feature' => 'Scenario descriptions not supported',
             'padded_example.feature' => 'Table padding is not trimmed as aggressively',
-            'spaces_in_language.feature' => 'Whitespace not supported around language selector',
             'rule_without_name_and_description.feature' => 'Rule is wrongly parsed as Description',
             'incomplete_background_2.feature' => 'Background descriptions not supported',
         ],