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