Skip to content

Commit

Permalink
Add calculate() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorcorcos committed Nov 30, 2023
1 parent 8eb3b1b commit d9956b9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/test_parsec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,23 @@ def test_weekyear
assert_equal(52, parsec.eval_equation('weekyear("2027-12-31")'))
assert_equal(53, parsec.eval_equation('weekyear("2028-01-01")'))
end

def test_calculate
parsec = Parsec::Parsec
assert_equal('World', parsec.eval_equation('regex("Hello World", "Hello (.*)")'))
assert_equal('12', parsec.eval_equation('calculate("2+2+2*4")'))
assert_equal('16', parsec.eval_equation('calculate("(2+2)*4")'))
assert_equal('16', parsec.eval_equation('calculate("2^4")'))
assert_equal('3', parsec.eval_equation('calculate("sqrt(9)")'))
assert_equal('50', parsec.eval_equation('calculate("abs(-50)")'))
assert_equal('1', parsec.eval_equation('calculate("round(1.123)")'))
assert_equal('2019-01-04', parsec.eval_equation('calculate("add_days(\"2019-01-01\", 3)")'))
assert_equal('1', parsec.eval_equation('calculate("daysdiff(\"2019-01-01\", \"2019-01-02\")")'))
assert_equal('24', parsec.eval_equation('calculate("hoursdiff(\"2019-01-01\", \"2019-01-02\")")'))
assert_equal('higher', parsec.eval_equation('calculate("3 > 2 ? \"higher\" : \"lower\"")'))
assert_equal('lower', parsec.eval_equation('calculate("3 < 2 ? \"higher\" : \"lower\"")'))
assert_equal('One Two Three', parsec.eval_equation('calculate("concat(\"One \", concat(\"Two\", \" Three\"))")'))
assert_equal('One Two Three', parsec.eval_equation('calculate("\"One\" // \" \" // \"Two\" // \" \" // \"Three\"")'))
assert_equal('3', parsec.eval_equation('calculate("number(calculate(\"1 + 1\")) + 1")'))
end
end

0 comments on commit d9956b9

Please sign in to comment.