Skip to content

Commit

Permalink
Add some tests for multibyte character support
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan3dc committed Feb 10, 2018
1 parent 11beecf commit 3ea040e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/Argument/ManagerTest.php
@@ -0,0 +1,49 @@
<?php

namespace League\CLImate\Tests\Argument;

use League\CLImate\Argument\Argument;
use League\CLImate\Argument\Manager;
use PHPUnit\Framework\TestCase;

class ManagerTest extends TestCase
{
private $manager;

public function setUp()
{
$this->manager = new Manager;
}


public function testDefined1()
{
$argument = Argument::createFromArray("test", [
"prefix" => "t",
"longPrefix" => "test",
]);
$this->manager->add($argument);

$result = $this->manager->defined("test", ["command", "--test"]);

$this->assertTrue($result);
}
public function testDefined2()
{
$result = $this->manager->defined("test");

$this->assertFalse($result);
}
public function testDefined3()
{
$argument = Argument::createFromArray("lorem", [
"prefix" => "l",
"longPrefix" => "Лорем",
]);
$this->manager->add($argument);

$result = $this->manager->defined("lorem", ["command", "--Лорем"]);

$this->assertTrue($result);
}
}
32 changes: 32 additions & 0 deletions tests/PaddingTest.php
Expand Up @@ -56,4 +56,36 @@ public function it_can_pad_with_multiple_characters_odd()

$padding->label('Pad odd')->result('extra');
}


/** @test */
public function it_can_pad_with_multibyte_characters()
{
$padding = $this->cli->padding(10);

$this->output->shouldReceive("sameLine");
$this->shouldWrite("\e[mЛорем.....\e[0m");
$this->shouldWrite("\e[m END\e[0m");

$padding->label("Лорем")->result("END");
}


/** @test */
public function it_can_wrap_a_multibyte_line()
{
$max_width = $this->util->width();
$padding = $this->cli->padding();

$content = "Лорем" . str_repeat('a', $max_width * 2);
$content = mb_substr($content, 0, ($max_width * 2) - 5);

$this->output->shouldReceive('sameLine');
$this->shouldWrite("\e[m" . mb_substr($content, 0, $max_width) . "\e[0m");
$this->shouldWrite("\e[m" . mb_substr($content, $max_width) . ".....\e[0m");
$this->shouldWrite("\e[m result\e[0m");

$padding->label($content)->result('result');
}

}

0 comments on commit 3ea040e

Please sign in to comment.