From 3ea040efdcf308f22c18599bdd90277c2512ca9f Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Sat, 10 Feb 2018 18:38:02 +0000 Subject: [PATCH] Add some tests for multibyte character support --- tests/Argument/ManagerTest.php | 49 ++++++++++++++++++++++++++++++++++ tests/PaddingTest.php | 32 ++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tests/Argument/ManagerTest.php diff --git a/tests/Argument/ManagerTest.php b/tests/Argument/ManagerTest.php new file mode 100644 index 00000000..ecdfb35b --- /dev/null +++ b/tests/Argument/ManagerTest.php @@ -0,0 +1,49 @@ +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); + } +} diff --git a/tests/PaddingTest.php b/tests/PaddingTest.php index 84a5fc2e..d0aa6bc0 100644 --- a/tests/PaddingTest.php +++ b/tests/PaddingTest.php @@ -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'); + } + }