From 2eaffa5cfb8ad8e5d18ac1ed61b4ae6b976852ee Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 25 Mar 2024 11:57:42 +0100 Subject: Expression language: add float operations "*" and "+" Numerical values are used at some places in justbuild: as value for timeout scaling, as well as by the "range" expression that is used, e.g., to define repreated test runs. Therefore, improve support for numerical values by adding basic operations. --- .../build_engine/expression/expression.test.cpp | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'test/buildtool/build_engine/expression/expression.test.cpp') diff --git a/test/buildtool/build_engine/expression/expression.test.cpp b/test/buildtool/build_engine/expression/expression.test.cpp index 242c0f4a..83257bf8 100644 --- a/test/buildtool/build_engine/expression/expression.test.cpp +++ b/test/buildtool/build_engine/expression/expression.test.cpp @@ -744,6 +744,54 @@ TEST_CASE("Expression Evaluation", "[expression]") { // NOLINT CHECK(result == Expression::FromJson(R"(["foo", "bar", "baz"])"_json)); } + SECTION("+ expression") { + auto expr_empty = Expression::FromJson(R"( + { "type": "+" + , "$1": [] + })"_json); + REQUIRE(expr_empty); + + auto result_empty = expr_empty.Evaluate(env, fcts); + REQUIRE(result_empty); + REQUIRE(result_empty->IsNumber()); + CHECK(result_empty == Expression::FromJson(R"(0.0)"_json)); + + auto expr = Expression::FromJson(R"( + { "type": "+" + , "$1": [2, 3, 7, -1] + })"_json); + REQUIRE(expr); + + auto result = expr.Evaluate(env, fcts); + REQUIRE(result); + REQUIRE(result->IsNumber()); + CHECK(result == Expression::FromJson(R"(11.0)"_json)); + } + + SECTION("* expression") { + auto expr_empty = Expression::FromJson(R"( + { "type": "*" + , "$1": [] + })"_json); + REQUIRE(expr_empty); + + auto result_empty = expr_empty.Evaluate(env, fcts); + REQUIRE(result_empty); + REQUIRE(result_empty->IsNumber()); + CHECK(result_empty == Expression::FromJson(R"(1.0)"_json)); + + auto expr = Expression::FromJson(R"( + { "type": "*" + , "$1": [2, 3, 7, -1] + })"_json); + REQUIRE(expr); + + auto result = expr.Evaluate(env, fcts); + REQUIRE(result); + REQUIRE(result->IsNumber()); + CHECK(result == Expression::FromJson(R"(-42.0)"_json)); + } + SECTION("nub_right expression") { auto expr = Expression::FromJson(R"( {"type": "nub_right" -- cgit v1.2.3