aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruce Wells <brucekwells@gmail.com>2019-01-12 05:45:29 +0300
committerBruce Wells <brucekwells@gmail.com>2019-01-12 05:45:29 +0300
commit145a0a136fc41dc59a78637a8e84f1c8952ecc31 (patch)
treee65b68200d122f4c8afbf772203dc63002ad3c7f /tests
parent9684cfd1d0e61a6bfcf1a46f322f99e7b6559df5 (diff)
parent18b12aeeff34c8ac9a350165ae36f08f4138dc9c (diff)
Merge branch 'master' of https://github.com/phpfui/MathExecutor
# Conflicts: # src/NXP/Classes/Lexer.php
Diffstat (limited to 'tests')
-rw-r--r--tests/MathTest.php18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index 9acdb63..55e0799 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -32,7 +32,7 @@ class MathTest extends \PHPUnit_Framework_TestCase
/** @var float $phpResult */
eval('$phpResult = ' . $expression . ';');
- $this->assertEquals($calculator->execute($expression), $phpResult);
+ $this->assertEquals($calculator->execute($expression), $phpResult, "Expression was: ${expression}");
}
/**
@@ -138,9 +138,23 @@ class MathTest extends \PHPUnit_Framework_TestCase
{
$calculator = new MathExecutor();
- $calculator->addFunction('round', function ($arg) { return round($arg); }, 1);
+ $calculator->addFunction('round', function ($arg) {
+ return round($arg);
+ }, 1);
/** @var float $phpResult */
eval('$phpResult = round(100/30);');
$this->assertEquals($calculator->execute('round(100/30)'), $phpResult);
}
+
+ public function testQuotes()
+ {
+ $calculator = new MathExecutor();
+ $testString = "some, long. arg; with: different-separators!";
+ $calculator->addFunction('test', function ($arg) use ($testString) {
+ $this->assertEquals($arg, $testString);
+ return 0;
+ }, 1);
+ $calculator->execute('test("' . $testString . '")'); // single quotes
+ $calculator->execute("test('" . $testString . "')"); // double quotes
+ }
} \ No newline at end of file