Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function(num1 + num2, num3) seems to run as if it is function(num1, num2 + num3) #246

Closed
kubo opened this issue Jun 22, 2022 · 3 comments · Fixed by #247
Closed

function(num1 + num2, num3) seems to run as if it is function(num1, num2 + num3) #246

kubo opened this issue Jun 22, 2022 · 3 comments · Fixed by #247

Comments

@kubo
Copy link
Contributor

kubo commented Jun 22, 2022

I inserted the following three lines here and ran tests.

  CHECK(env.render("{{ multiply(3, 3) }}", data) == "9.0");
  CHECK(env.render("{{ multiply(3, 1 + 2) }}", data) == "9.0");
  CHECK(env.render("{{ multiply(1 + 2, 3) }}", data) == "9.0");

The first two lines passed tests as expected. However, the last one failed as follows.

$ make test
Running tests...
Test project /home/kubo/inja/build
    Start 1: inja_test
1/2 Test #1: inja_test ........................***Failed    0.02 sec
    Start 2: single_inja_test
2/2 Test #2: single_inja_test .................***Failed    0.02 sec

0% tests passed, 2 tests failed out of 2

Total Test time (real) =   0.04 sec

The following tests FAILED:
	  1 - inja_test (Failed)
	  2 - single_inja_test (Failed)
Errors while running CTest
make: *** [Makefile:85: test] Error  8
$ ./inja_test 
[doctest] doctest version is "2.4.6"
[doctest] run with "--help" for options
===============================================================================
/home/kubo/inja/test/test-functions.cpp:218:
TEST CASE:  callbacks

/home/kubo/inja/test/test-functions.cpp:273: ERROR: CHECK( env.render("{{ multiply(1 + 2, 3) }}", data) == "9.0" ) is NOT correct!
  values: CHECK( 5.0 == 9.0 )

===============================================================================
[doctest] test cases:  15 |  14 passed | 1 failed | 0 skipped
[doctest] assertions: 246 | 245 passed | 1 failed |
[doctest] Status: FAILURE!

The result of multiply(1 + 2, 3) is 5.0. It seems the result of multiply(1, 2 + 3).

@kubo
Copy link
Contributor Author

kubo commented Jun 26, 2022

@pantor Are you going to fix this issue? If no, may I do it?

@pantor
Copy link
Owner

pantor commented Jun 26, 2022

Please go ahead!

kubo added a commit to kubo/inja that referenced this issue Jun 27, 2022
kubo added a commit to kubo/inja that referenced this issue Jun 27, 2022
kubo added a commit to kubo/inja that referenced this issue Jun 27, 2022
@kubo kubo mentioned this issue Jun 28, 2022
@terrakuh
Copy link

Thanks @kubo for the patch! Can this please be merged into the main repository @pantor ?

pantor pushed a commit that referenced this issue Dec 4, 2022
* Add `parse_expression` with one argument in preparation to fix #246.

* Fix issue #246: `func(n1 + n2, n3)` runs as if `func(n1, n2 + n3)`

* Simplify parser for an expression enclosed by parentheses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants