From 0042f0dd82c289edd59e856124d6e045137850fb Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 26 Dec 2017 17:14:16 +0800 Subject: [PATCH] IntegerType --- src/Contracts/Types/Integer.php | 49 +++++++++++++++++++++ test/unit/IntegerTypeTest.php | 75 +++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 src/Contracts/Types/Integer.php create mode 100644 test/unit/IntegerTypeTest.php diff --git a/src/Contracts/Types/Integer.php b/src/Contracts/Types/Integer.php new file mode 100644 index 0000000..e779303 --- /dev/null +++ b/src/Contracts/Types/Integer.php @@ -0,0 +1,49 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Contracts\Types; + +use Web3\Contracts\SolidityType; +use Web3\Contracts\Types\IType; + +class Integer extends SolidityType implements IType +{ + /** + * construct + * + * @return void + */ + public function __construct() + { + // + } + + /** + * isType + * + * @param string $name + * @return bool + */ + public function isType($name) + { + return (preg_match('/int([0-9]{1,})?(\[([0-9]+)\])?/', $name) === 1); + } + + /** + * isDynamicType + * + * @return bool + */ + public function isDynamicType() + { + return false; + } +} \ No newline at end of file diff --git a/test/unit/IntegerTypeTest.php b/test/unit/IntegerTypeTest.php new file mode 100644 index 0000000..595906c --- /dev/null +++ b/test/unit/IntegerTypeTest.php @@ -0,0 +1,75 @@ + 'int', + 'result' => true + ], [ + 'value' => 'int[]', + 'result' => true + ], [ + 'value' => 'int[4]', + 'result' => true + ], [ + 'value' => 'int[][]', + 'result' => true + ], [ + 'value' => 'int[3][]', + 'result' => true + ], [ + 'value' => 'int[][6][]', + 'result' => true + ], [ + 'value' => 'int32', + 'result' => true + ], [ + 'value' => 'int64[4]', + 'result' => true + ], + ]; + + /** + * solidityType + * + * @var \Web3\Contracts\SolidityType + */ + protected $solidityType; + + /** + * setUp + * + * @return void + */ + public function setUp() + { + parent::setUp(); + $this->solidityType = new Integer; + } + + /** + * testIsType + * + * @return void + */ + public function testIsType() + { + $solidityType = $this->solidityType; + + foreach ($this->testTypes as $type) { + $this->assertEquals($solidityType->isType($type['value']), $type['result']); + } + } +} \ No newline at end of file