diff options
Diffstat (limited to 'MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PrintfValidatorTest.php')
-rw-r--r-- | MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PrintfValidatorTest.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PrintfValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PrintfValidatorTest.php new file mode 100644 index 00000000..6ea13a10 --- /dev/null +++ b/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PrintfValidatorTest.php @@ -0,0 +1,62 @@ +<?php +declare( strict_types = 1 ); + +use MediaWiki\Extensions\Translate\MessageValidator\Validators\PrintfValidator; + +/** + * @license GPL-2.0-or-later + * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\PrintfValidator + */ +class PrintfValidatorTest extends BaseValidatorTestCase { + /** @dataProvider provideTestCases */ + public function test( ...$params ) { + $this->runValidatorTests( new PrintfValidator(), 'variable', ...$params ); + } + + public static function provideTestCases() { + $key = 'key'; + $code = 'en'; + + yield [ + '%2$f', + 'a', + [ 'missing' ], + 'missing positional variable is an issue' + ]; + + yield [ + '%2$f', + '%3$d', + [ 'missing', 'unknown' ], + 'typoed variable is two issues' + ]; + + yield [ + 'abc', + '%4$d', + [ 'unknown' ], + 'unknown positional variable is an issue' + ]; + + yield [ + '%2$f', + '%2$f', + [], + 'all variables are used, no issues' + ]; + + yield [ + '%2$.2f', + '%2$f', + [ 'missing', 'unknown' ], + 'changing precision is not supported' + ]; + + yield [ + '%.2f', + '%2$f', + [ 'missing', 'unknown' ], + 'changing precision and position is not supported' + ]; + } +} |