| 1 |
#include <format> |
| 2 |
#include <string_view> |
| 3 |
|
| 4 |
#include <catch2/catch_all.hpp> |
| 5 |
|
| 6 |
#include "svg_analyzer.h" |
| 7 |
#include "test_utilities.h" |
| 8 |
|
| 9 |
TEST_CASE("Edge color", |
| 10 |
"Test that the Graphviz `color` attribute is used to set the " |
| 11 |
"`stroke` and `stroke-opacity` attributes correctly for edges in the " |
| 12 |
"generated SVG") { |
| 13 |
|
| 14 |
const auto primitive_arrow_shape = |
| 15 |
GENERATE(from_range(all_primitive_arrow_shapes)); |
| 16 |
INFO("Primitive arrow shape: " << primitive_arrow_shape); |
| 17 |
|
| 18 |
const auto edge_rgb_fillcolor = GENERATE("#000000", "#ffffff", "#5580aa"); |
| 19 |
const auto opacity = GENERATE(0, 100, 255); |
| 20 |
const auto edge_rgba_fillcolor = |
| 21 |
std::format("{}{:02x}", edge_rgb_fillcolor, opacity); |
| 22 |
INFO("Edge fillcolor: " << edge_rgba_fillcolor); |
| 23 |
|
| 24 |
auto dot = |
| 25 |
std::format("digraph g1 {{edge [arrowhead={} fillcolor=\"{}\"]; a -> b}}", |
| 26 |
primitive_arrow_shape, edge_rgba_fillcolor); |
| 27 |
|
| 28 |
const auto engine = "dot"; |
| 29 |
auto svg_analyzer = SVGAnalyzer::make_from_dot(dot, engine); |
| 30 |
|
| 31 |
const auto expected_edge_fillcolor = [&]() -> const std::string { |
| 32 |
if (primitive_arrow_shapes_without_closed_svg_shape.contains( |
| 33 |
primitive_arrow_shape)) { |
| 34 |
return ""; |
| 35 |
} |
| 36 |
if (opacity == 255) { |
| 37 |
return edge_rgb_fillcolor; |
| 38 |
} |
| 39 |
if (opacity == 0) { |
| 40 |
return "#00000000"; // transparent/none |
| 41 |
} |
| 42 |
return edge_rgba_fillcolor; |
| 43 |
}(); |
| 44 |
|
| 45 |
for (const auto &graph : svg_analyzer.graphs()) { |
| 46 |
for (const auto &edge : graph.edges()) { |
| 47 |
CHECK(edge.fillcolor() == expected_edge_fillcolor); |
| 48 |
} |
| 49 |
} |
| 50 |
} |