From 68d4f5bb1d2dc953c1bccad96d7c6707159e0790 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 5 Aug 2024 11:16:16 +0200 Subject: Expression language: add expression from_subdir ... allowing to select only the keys in a specific subdir, and move the them to top-level. --- .../build_engine/expression/expression.test.cpp | 66 ++++++++++++++++++++-- 1 file changed, 60 insertions(+), 6 deletions(-) (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 40f19e88..938bd63f 100644 --- a/test/buildtool/build_engine/expression/expression.test.cpp +++ b/test/buildtool/build_engine/expression/expression.test.cpp @@ -1335,14 +1335,14 @@ TEST_CASE("Expression Evaluation", "[expression]") { // NOLINT , "$1": "PLACEHOLDER" })"_json); REQUIRE(expr); - auto literal_foo = Expression::FromJson( - R"({"type": "'", "$1": {"foo":true}})"_json); + auto literal_foo = + Expression::FromJson(R"({"type": "'", "$1": {"foo":true}})"_json); REQUIRE(literal_foo); - auto literal_foo_false = Expression::FromJson( - R"({"type": "'", "$1": {"foo":false}})"_json); + auto literal_foo_false = + Expression::FromJson(R"({"type": "'", "$1": {"foo":false}})"_json); REQUIRE(literal_foo_false); - auto literal_bar = Expression::FromJson( - R"({"type": "'", "$1": {"bar":false}})"_json); + auto literal_bar = + Expression::FromJson(R"({"type": "'", "$1": {"bar":false}})"_json); REQUIRE(literal_bar); expr = Replace(expr, "$1", list_t{literal_foo, literal_bar}); @@ -1460,6 +1460,60 @@ TEST_CASE("Expression Evaluation", "[expression]") { // NOLINT CHECK_FALSE(expr.Evaluate(env, fcts)); } + SECTION("from_subdir") { + auto expr = Expression::FromJson(R"( + {"type": "from_subdir", "subdir": "foo" + , "$1": {"type": "'", "$1": + { "foo/a/b/c": "abc.txt" + , "foo/a/other": "other.txt" + , "foo/top": "top.xt" + , "foo/a/b/../d/e": "make canonical" + , "bar/a/b/c": "ignore bar/a/b/c" + , "bar/a/b/../b/c": "also ingnore other path" + }}} + )"_json); + REQUIRE(expr); + + auto result = expr.Evaluate(env, fcts); + REQUIRE(result); + CHECK(result == Expression::FromJson(R"( + { "a/b/c": "abc.txt" + , "a/other": "other.txt" + , "top": "top.xt" + , "a/d/e": "make canonical" + } + )"_json)); + } + + SECTION("from_subdir trivial conflict") { + auto expr = Expression::FromJson(R"( + {"type": "from_subdir", "subdir": "foo" + , "$1": {"type": "'", "$1": + { "foo/a/b/c": "abc.txt" + , "foo/a/b/../b/c": "abc.txt" + }}} + )"_json); + REQUIRE(expr); + + auto result = expr.Evaluate(env, fcts); + REQUIRE(result); + CHECK(result == Expression::FromJson(R"( + {"a/b/c": "abc.txt"} + )"_json)); + } + + SECTION("from_subdir conflict") { + auto expr = Expression::FromJson(R"( + {"type": "from_subdir", "subdir": "foo" + , "$1": {"type": "'", "$1": + { "foo/a/b/c": "one value" + , "foo/a/b/../b/c": "different value" + }}} + )"_json); + REQUIRE(expr); + CHECK_FALSE(expr.Evaluate(env, fcts)); + } + fcts = FunctionMap::MakePtr( fcts, "concat", [](auto&& eval, auto const& expr, auto const& env) { auto p1 = eval(expr->Get("$1", ""s), env); -- cgit v1.2.3