Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ArgumentLexeme.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ArgumentLexeme extends Lexeme {
public const T_INT_HEX = 'x';
/** @var string the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters). */
public const T_INT_HEX_CAP = 'X';
/** @var string a percent-sign type specifier (e.g. `%4%`). Unlike `%%`, an argument must be supplied even though it is not used. */
public const T_PERCENT = '%';

public const VALID_T_TYPES = [
self::T_INT_AS_BINARY,
Expand All @@ -61,6 +63,7 @@ class ArgumentLexeme extends Lexeme {
self::T_INT_UNSIGNED,
self::T_INT_HEX,
self::T_INT_HEX_CAP,
self::T_PERCENT,
];

public const ARG_TYPE_MISSING = '';
Expand Down
39 changes: 39 additions & 0 deletions test/Integration/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ public static function parseStringProvider() : array {
'[=ll:1|||pos:|||left:||l][!=s:3]',
false,
],

'percent type with width' => [
'%4%',
'[%=4%:1|||pos:||4|left:|]',
true,
],

'percent type with long modifier' => [
'%l%',
'[%=l%:1|||pos:|||left:||l]',
true,
],

'percent type with flags and precision' => [
'%+5.5%',
'[%=+5.5%:1|||pos:1||5|left:|5]',
true,
],
];
}

Expand Down Expand Up @@ -377,6 +395,27 @@ public static function printfWithTypeProvider() : array {
[ 1 => ArgumentLexeme::ARG_TYPE_DOUBLE, ArgumentLexeme::ARG_TYPE_INT ],
true,
],

'percent type with width consumes one argument' => [
'%4%',
[ [ ArgumentLexeme::ARG_TYPE_MISSING ] ],
[ 1 => ArgumentLexeme::ARG_TYPE_MISSING ],
true,
],

'percent type with long modifier consumes one argument' => [
'%l%',
[ [ ArgumentLexeme::ARG_TYPE_MISSING ] ],
[ 1 => ArgumentLexeme::ARG_TYPE_MISSING ],
true,
],

'percent type with flags and precision consumes one argument' => [
'%+5.5%',
[ [ ArgumentLexeme::ARG_TYPE_MISSING ] ],
[ 1 => ArgumentLexeme::ARG_TYPE_MISSING ],
true,
],
];
}

Expand Down