From 1b427bcb901dfbc2abc01b9bf301734893f7d4c3 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Wed, 7 Feb 2018 16:57:39 +0800 Subject: [PATCH] Fix HexFormatter and add HexFormatter test. --- src/Formatters/HexFormatter.php | 2 -- test/unit/HexFormatterTest.php | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test/unit/HexFormatterTest.php diff --git a/src/Formatters/HexFormatter.php b/src/Formatters/HexFormatter.php index 03ac30b..b0a3b27 100644 --- a/src/Formatters/HexFormatter.php +++ b/src/Formatters/HexFormatter.php @@ -30,8 +30,6 @@ class HexFormatter implements IFormatter if (Utils::isZeroPrefixed($value)) { return $value; - } elseif (Utils::isHex($value)) { - $value = '0x' . $value; } else { $value = Utils::toHex($value, true); } diff --git a/test/unit/HexFormatterTest.php b/test/unit/HexFormatterTest.php new file mode 100644 index 0000000..5be7ecc --- /dev/null +++ b/test/unit/HexFormatterTest.php @@ -0,0 +1,49 @@ +formatter = new HexFormatter; + } + + /** + * testFormat + * + * @return void + */ + public function testFormat() + { + $formatter = $this->formatter; + + $hex = $formatter->format('ae'); + $this->assertEquals($hex, '0x6165'); + + $hex = $formatter->format('0xabce'); + $this->assertEquals($hex, '0xabce'); + + $hex = $formatter->format('123'); + $this->assertEquals($hex, '0x7b'); + + $hex = $formatter->format(12); + $this->assertEquals($hex, '0xc'); + } +} \ No newline at end of file