summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/concepts/expressions.org10
-rw-r--r--src/buildtool/build_engine/expression/evaluator.cpp2
-rw-r--r--test/buildtool/build_engine/expression/expression.test.cpp6
3 files changed, 11 insertions, 7 deletions
diff --git a/doc/concepts/expressions.org b/doc/concepts/expressions.org
index 895b5e0a..5b7e2f2c 100644
--- a/doc/concepts/expressions.org
+++ b/doc/concepts/expressions.org
@@ -212,9 +212,13 @@ those) argument(s) to obtain the final result.
"$1": "3"}~ evaluates to ~["0", "1", "2"]~.
- ~"enumerate"~ The argument has to be a list. The result is a map
- containing one entry for each element of the list; the key is the
- decimal representation of the position in the list (starting from
- ~0~) and the value is the element.
+ containing one entry for each element of the list. The key is
+ the decimal representation of the position in the list (starting
+ from ~0~), padded with leading zeros to length at least 10. The
+ value is the element. The padding is chosen in such a way that
+ iterating over the resulting map (which happens in lexicographic
+ order of the keys) has the same iteration order as the list for
+ all lists indexable by 32-bit integers.
- ~"++"~ The argument has to be a list of lists. The result is the
concatenation of those lists.
diff --git a/src/buildtool/build_engine/expression/evaluator.cpp b/src/buildtool/build_engine/expression/evaluator.cpp
index 76ad3076..ed6c6014 100644
--- a/src/buildtool/build_engine/expression/evaluator.cpp
+++ b/src/buildtool/build_engine/expression/evaluator.cpp
@@ -147,7 +147,7 @@ auto Enumerate(ExpressionPtr const& expr) -> ExpressionPtr {
auto result = Expression::map_t::underlying_map_t{};
size_t count = 0;
for (auto const& entry : expr->List()) {
- result[fmt::format("{}", count)] = entry;
+ result[fmt::format("{:010d}", count)] = entry;
count++;
}
return ExpressionPtr{Expression::map_t{result}};
diff --git a/test/buildtool/build_engine/expression/expression.test.cpp b/test/buildtool/build_engine/expression/expression.test.cpp
index 11ff7a43..6929fa33 100644
--- a/test/buildtool/build_engine/expression/expression.test.cpp
+++ b/test/buildtool/build_engine/expression/expression.test.cpp
@@ -901,9 +901,9 @@ TEST_CASE("Expression Evaluation", "[expression]") { // NOLINT
auto result = expr.Evaluate(env, fcts);
REQUIRE(result);
CHECK(result == Expression::FromJson(R"(
- { "0": "foo"
- , "1": "bar"
- , "2": "baz"
+ { "0000000000": "foo"
+ , "0000000001": "bar"
+ , "0000000002": "baz"
}
)"_json));
}