Skip to content

Commit

Permalink
add whitespace surrounding param to regex, add test (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmiller42ce authored Aug 30, 2022
1 parent 7015d2a commit e10786b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public function findTranslations()
'(?<!->)'. // Must not start with ->
'('.implode('|', $this->translationMethods).')'. // Must start with one of the functions
"\(". // Match opening parentheses
"\s*". // Whitespace before param
"[\'\"]". // Match " or '
'('. // Start a new group to match:
'.+'. // Must start with group
')'. // Close group
"[\'\"]". // Closing quote
"\s*". // Whitespace after param
"[\),]"; // Close parentheses or new parameter

foreach ($this->disk->allFiles($this->scanPaths) as $file) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function it_finds_all_translations()
$this->scanner = app()->make(Scanner::class);
$matches = $this->scanner->findTranslations();

$this->assertEquals($matches, ['single' => ['single' => ['This will go in the JSON array' => '', 'trans' => '']], 'group' => ['lang' => ['first_match' => ''], 'lang_get' => ['first' => '', 'second' => ''], 'trans' => ['first_match' => '', 'third_match' => ''], 'trans_choice' => ['with_params' => '']]]);
$this->assertEquals($matches, ['single' => ['single' => ['This will go in the JSON array' => '', 'This will also go in the JSON array' => '', 'trans' => '']], 'group' => ['lang' => ['first_match' => ''], 'lang_get' => ['first' => '', 'second' => ''], 'trans' => ['first_match' => '', 'third_match' => ''], 'trans_choice' => ['with_params' => '']]]);
$this->assertCount(2, $matches);
}
}
6 changes: 5 additions & 1 deletion tests/fixtures/scan-tests/__.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@

__('This will go in the JSON array')
__('This will go in the JSON array')

__(
'This will also go in the JSON array'
)

0 comments on commit e10786b

Please sign in to comment.