diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-03-25 11:57:42 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-03-26 10:56:30 +0100 |
commit | 2eaffa5cfb8ad8e5d18ac1ed61b4ae6b976852ee (patch) | |
tree | 032cddb636d94ff6ce8f245becaf7055d9045b5b /test/buildtool/build_engine/expression/expression.test.cpp | |
parent | d58620bcf328a500b964fd9190f712c96d6a136e (diff) | |
download | justbuild-2eaffa5cfb8ad8e5d18ac1ed61b4ae6b976852ee.tar.gz |
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.
Diffstat (limited to 'test/buildtool/build_engine/expression/expression.test.cpp')
-rw-r--r-- | test/buildtool/build_engine/expression/expression.test.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
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" |