#include <memory>
#include <stdexcept>
+#include <boost/algorithm/string.hpp>
+#include <catch2/catch.hpp>
#include <fmt/format.h>
#include "svg_analyzer.h"
}
}
+void SVGAnalyzer::re_create_and_verify_svg() {
+
+ const auto indent_size = 0;
+ auto recreated_svg = svg_string(indent_size);
+
+ // compare the recreated SVG with the original SVG
+ if (recreated_svg != m_original_svg) {
+ std::vector<std::string> original_svg_lines;
+ boost::split(original_svg_lines, m_original_svg, boost::is_any_of("\n"));
+
+ std::vector<std::string> recreated_svg_lines;
+ boost::split(recreated_svg_lines, recreated_svg, boost::is_any_of("\n"));
+
+ for (std::size_t i = 0; i < original_svg_lines.size(); i++) {
+ REQUIRE(i < recreated_svg_lines.size());
+ REQUIRE(recreated_svg_lines[i] == original_svg_lines[i]);
+ }
+
+ REQUIRE(recreated_svg_lines.size() == original_svg_lines.size());
+ }
+}
+
void SVGAnalyzer::set_cx(double cx) { current_element().attributes.cx = cx; }
void SVGAnalyzer::set_cy(double cy) { current_element().attributes.cy = cy; }
std::size_t num_titles() const { return m_num_titles; };
/// Return a view of the original SVG
std::string_view original_svg() const;
+ /// Re-create the SVG from the internal data structure and verify it against
+ /// the original SVG produced by Graphviz
+ void re_create_and_verify_svg();
void set_graphviz_version(std::string_view version);
void set_graphviz_build_date(std::string_view build_date);
std::string svg_string(std::size_t indent_size = 2) const;
-#include <boost/algorithm/string.hpp>
#include <boost/range/adaptor/indexed.hpp>
#include <catch2/catch.hpp>
#include <fmt/format.h>
CHECK(svg_analyzer.num_titles() == expected_num_titles);
CHECK(svg_analyzer.num_texts() == expected_num_texts);
- auto original_svg = svg_analyzer.original_svg();
- const auto indent_size = 0;
- auto recreated_svg = svg_analyzer.svg_string(indent_size);
-
- // compare the recreated SVG with the original SVG
- if (recreated_svg != original_svg) {
- std::vector<std::string> original_svg_lines;
- boost::split(original_svg_lines, original_svg, boost::is_any_of("\n"));
- std::vector<std::string> recreated_svg_lines;
- boost::split(recreated_svg_lines, recreated_svg, boost::is_any_of("\n"));
- for (std::size_t i = 0; i < original_svg_lines.size(); i++) {
- REQUIRE(i < recreated_svg_lines.size());
- REQUIRE(recreated_svg_lines[i] == original_svg_lines[i]);
- }
- REQUIRE(recreated_svg_lines.size() == original_svg_lines.size());
- }
+ svg_analyzer.re_create_and_verify_svg();
}
}