Add test cases for `Internal\Scalar`.

This commit is contained in:
CismonX 2019-06-07 00:30:50 +08:00
parent 12d04c22db
commit bae33d2ce6
2 changed files with 51 additions and 0 deletions

22
tests/006-scalar.phpt Normal file
View File

@ -0,0 +1,22 @@
--TEST--
Test for `Internal\Scalar`.
--SKIPIF--
<?php
require_once 'includes/loaded.php';
is_php_arma_loaded();
?>
--FILE--
<?php
require_once 'includes/assert.php';
$mat = Arma\IMat::fromString('1 2; 3 4');
$mat(1, 0)->setTo(5);
$mat->at(0, 1)->setTo(7);
batch_assert('read/write access of `MapVal`',
[5, $mat->at(1, 0)->val()],
[7, $mat(0, 1)->val()]
);
?>
--EXPECT--

View File

@ -0,0 +1,29 @@
--TEST--
Test for `Internal\Scalar`.
--SKIPIF--
<?php
require_once 'includes/loaded.php';
require_once 'includes/supports.php';
if (is_php_arma_loaded()) {
supports_operator_overloading();
}
?>
--FILE--
<?php
require_once 'includes/assert.php';
$mat = Arma\IMat::fromString('1 2; 3 4');
$mapval = $mat(1, 0);
$mapval = 5;
// Unfortunately, the Zend Engine prevents us from writing something like:
// $mat(1, 0) = 5;
// because function return values are not supposed to be used in write context.
// Function `zend_ensure_writable_variable()` does that check in compile time.
batch_assert('operator overloading of `MapVal`',
[5, +$mat->at(1, 0)],
);
?>
--EXPECT--