MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ConvertMacroCallsToString

Function ConvertMacroCallsToString

parser/parser_test.cc:1446–1469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1444}
1445
1446std::string ConvertMacroCallsToString(
1447 const cel::expr::SourceInfo& source_info) {
1448 KindAndIdAdorner macro_calls_adorner(source_info);
1449 ExprPrinter w(macro_calls_adorner);
1450 // Use a list so we can sort the macro calls ensuring order for appending
1451 std::vector<std::pair<int64_t, cel::expr::Expr>> macro_calls;
1452 for (auto pair : source_info.macro_calls()) {
1453 // Set ID to the map key for the adorner
1454 pair.second.set_id(pair.first);
1455 macro_calls.push_back(pair);
1456 }
1457 // Sort in reverse because the first macro will have the highest id
1458 absl::c_sort(macro_calls,
1459 [](const std::pair<int64_t, cel::expr::Expr>& p1,
1460 const std::pair<int64_t, cel::expr::Expr>& p2) {
1461 return p1.first > p2.first;
1462 });
1463 std::string result = "";
1464 for (const auto& pair : macro_calls) {
1465 result += w.PrintProto(pair.second) += ",\n";
1466 }
1467 // substring last ",\n"
1468 return result.substr(0, result.size() - 3);
1469}
1470
1471class ExpressionTest : public testing::TestWithParam<TestInfo> {};
1472

Callers 1

TEST_PFunction · 0.85

Calls 3

PrintProtoMethod · 0.80
set_idMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected