From 05aa9fd8169597064ac86a64f48c05cc638e6851 Mon Sep 17 00:00:00 2001 From: sehe Date: Wed, 8 May 2024 15:35:10 +0200 Subject: [PATCH] Include test for subgraph nesting limit Eliminating need for manual re-test after review updates PR #376 --- test/graphviz_test.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/test/graphviz_test.cpp b/test/graphviz_test.cpp index a9339a99c..c29b05f70 100644 --- a/test/graphviz_test.cpp +++ b/test/graphviz_test.cpp @@ -440,9 +440,11 @@ void test_basic_csr_directed_graph_ext_props() edge_weight); } -void test_subgraphs() { +void test_subgraphs() +{ // on the BGL side, the new parser doesn't support subgraphs - // however, the docs promise to support reading them on the input side as "syntactic sugar". + // however, the docs promise to support reading them on the input side as + // "syntactic sugar". for (auto gv : { Fixture { "digraph {}" }, Fixture { "digraph { 1 -> {} }", 1 }, @@ -454,13 +456,33 @@ void test_subgraphs() { Fixture { "digraph { 1 -> subgraph hello { 2; 3; } }", 3 }, Fixture { "digraph { 1 -> subgraph clust_Hello { 2; 3; } }", 3 }, Fixture { "digraph { 1 -> subgraph \"hello\" { 2; 3; } }", 3 }, - Fixture { "digraph { {2} -> subgraph \"hello\" {{{{{{{{{{{{{{{{{{{{{{{{ 2; 3; }}}}}}}}}}}}}}}}}}}}}}}} }", 2 }, + Fixture { + "digraph { {2} -> subgraph \"hello\" {{{{ 2; 3; }}}} }", 2 }, }) { TEST_GRAPH(Models::DiGraph, gv); } } +void test_subgraph_nesting_limit() // issue #364 +{ + auto independent_nests = [=](unsigned level) + { + auto sg = std::string(level, '{') + " 2; 3; " + std::string(level, '}'); + ComparisonDriver::test_graph< Models::DiGraph >( + { "digraph{1->" + sg + "}", 3 }); + ComparisonDriver::test_graph< Models::DiGraph >( + { "digraph{1->" + sg + ";4->" + sg + "}", 4 }); + }; + + constexpr unsigned limit = 255; + independent_nests(1); + independent_nests(limit / 2); + independent_nests(limit - 1); + independent_nests(limit); // edge-case + BOOST_TEST_THROWS(independent_nests(limit + 1), boost::bad_graphviz_syntax); +} + int main() { test_basic_directed_graph_1(); @@ -479,5 +501,6 @@ int main() test_basic_csr_directed_graph_ext_props(); test_basic_csr_directed_graph(); test_subgraphs(); + test_subgraph_nesting_limit(); return boost::report_errors(); }