File tree Expand file tree Collapse file tree 4 files changed +25
-0
lines changed
src/nicoSWD/Rules/Core/Functions Expand file tree Collapse file tree 4 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 1111
1212use nicoSWD \Rules \Core \CallableFunction ;
1313use nicoSWD \Rules \Tokens \TokenFloat ;
14+ use nicoSWD \Rules \Tokens \TokenInteger ;
1415
1516final class ParseFloat extends CallableFunction
1617{
18+ /**
19+ * {@inheritdoc}
20+ */
1721 public function call ($ value = null ) : TokenFloat
1822 {
23+ if ($ value === null ) {
24+ return new TokenFloat (NAN );
25+ }
26+
1927 return new TokenFloat (
2028 (float ) $ value ->getValue (),
2129 $ this ->token ->getOffset (),
Original file line number Diff line number Diff line change 1414
1515final class ParseInt extends CallableFunction
1616{
17+ /**
18+ * {@inheritdoc}
19+ */
1720 public function call ($ value = null ) : TokenInteger
1821 {
22+ if ($ value === null ) {
23+ return new TokenInteger (NAN );
24+ }
25+
1926 return new TokenInteger (
2027 (int ) $ value ->getValue (),
2128 $ this ->token ->getOffset (),
Original file line number Diff line number Diff line change @@ -31,4 +31,9 @@ public function testOnUserDefinedVariable()
3131 $ this ->assertTrue ($ this ->evaluate ('parseFloat(foo) === 3.4 ' , ['foo ' => '3.4 ' ]));
3232 $ this ->assertFalse ($ this ->evaluate ('parseFloat(foo) === "3.5" ' , ['foo ' => 3.5 ]));
3333 }
34+
35+ public function testCallWithoutArgsShouldReturnNaN ()
36+ {
37+ $ this ->assertFalse ($ this ->evaluate ('parseFloat() === 1 ' ));
38+ }
3439}
Original file line number Diff line number Diff line change @@ -31,4 +31,9 @@ public function testOnUserDefinedVariable()
3131 $ this ->assertTrue ($ this ->evaluate ('parseInt(foo) === 3 ' , ['foo ' => '3 ' ]));
3232 $ this ->assertFalse ($ this ->evaluate ('parseInt(foo) === "3" ' , ['foo ' => 3 ]));
3333 }
34+
35+ public function testCallWithoutArgsShouldReturnNan ()
36+ {
37+ $ this ->assertFalse ($ this ->evaluate ('parseInt() === 1 ' ));
38+ }
3439}
You can’t perform that action at this time.
0 commit comments