Adds optional type argument accepted by str_pad()#120
Adds optional type argument accepted by str_pad()#120gitlost merged 4 commits intowp-cli:masterfrom urlund:master
str_pad()#120Conversation
|
@urlund Before submitting a pull request, could you create an issue first describing the problem you're trying to solve? See the Handbook section about pull requests for more details about our processes. |
|
@schlessera Done :) |
|
Thanks for the PR @urlund. I think it would be better (simpler at least) to only support Also could you add phpunit tests please? (See https://github.com/wp-cli/php-cli-tools/blob/master/tests/test-cli.php#L41). (Just to note: #122 will have to be merged once it's approved for the tests to pass on Travis.) |
|
Done? |
| $this->assertEquals( 6, strlen( \cli\Colors::pad( 'hello', 6, false, false, STR_PAD_RIGHT ) ) ); | ||
| $this->assertEquals( 7, strlen( \cli\Colors::pad( 'óra', 6, false, false, STR_PAD_LEFT ) ) ); // special characters take one byte | ||
| $this->assertEquals( 9, strlen( \cli\Colors::pad( '日本語', 6, false, false, STR_PAD_BOTH ) ) ); // each character takes two bytes | ||
| } |
There was a problem hiding this comment.
That's cool. Could you also add some tests to exercise the new functionality, eg
$this->assertSame( 5, strpos( \cli\Colors::pad( 'hello', 7, false, false, STR_PAD_RIGHT ), ' ' ) );
$this->assertSame( 6, strrpos( \cli\Colors::pad( 'hello', 7, false, false, STR_PAD_RIGHT ), ' ' ) );
$this->assertSame( 0, strpos( \cli\Colors::pad( 'hello', 7, false, false, STR_PAD_LEFT ), ' ' ) );
$this->assertSame( 1, strrpos( \cli\Colors::pad( 'hello', 7, false, false, STR_PAD_LEFT ), ' ' ) );
$this->assertSame( 0, strpos( \cli\Colors::pad( 'hello', 7, false, false, STR_PAD_BOTH ), ' ' ) );
$this->assertSame( 6, strrpos( \cli\Colors::pad( 'hello', 7, false, false, STR_PAD_BOTH ), ' ' ) );
$this->assertSame( \cli\Colors::pad( 'hello', 7 ), \cli\Colors::pad( 'hello', 7, false, false, STR_PAD_RIGHT ) );|
@gitlost better? ;) |
|
@urlund Oh yes! |
str_pad()
|
Tagged v0.11.7: https://github.com/wp-cli/php-cli-tools/releases/tag/v0.11.7 |
str_pad()str_pad()
Issue #121