1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<?php
declare( strict_types = 1 );
use MediaWiki\Extensions\Translate\MessageValidator\Validators\PythonInterpolationValidator;
/**
* @license GPL-2.0-or-later
* @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\PythonInterpolationValidator
*/
class PythonInterpolationValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
public function test( ...$params ) {
$this->runValidatorTests( new PythonInterpolationValidator(), 'variable', ...$params );
}
public static function provideTestCases() {
yield [
'My name is %s',
'This is invalid',
[ 'missing' ],
'missing unnamed variable is an issue'
];
yield [
'My name is %(name)s',
'This is invalid.',
[ 'missing' ],
'missing named variable is an issue'
];
yield [
'My name is %(name)s',
'This is an invalid %(aaaa)d %(name)s variable.',
[ 'unknown' ],
'unknown named variable is an issue'
];
yield [
'My name is %s',
'This is a value: %s',
[],
'all variables are used, not an issue'
];
}
}
|