Debian Codegraph @

tests/binarize/binarize_tests.cpp

raw symbols SCIP
1 #include <catch2/catch_test_macros.hpp>
2
3 #include "binarize/binarize.hpp"
4 #include "binarize/meatpack.hpp"
5
6 #include <string>
7 #include <vector>
8
9 using namespace MeatPack;
10
11 // Binarize lines via MeatPack and unbinarize back to verify round-trip.
12 static std::string roundtrip(const std::vector<std::string> &lines, uint8_t flags) {
13 MPBinarizer mp_binarizer(flags);
14 std::vector<uint8_t> binary;
15 mp_binarizer.initialize(binary);
16 for (const std::string &line: lines) {
17 mp_binarizer.binarize_line(line, binary);
18 }
19
20 mp_binarizer.finalize(binary);
21
22 std::string unbinarize_result;
23 unbinarize(binary, unbinarize_result);
24
25 return unbinarize_result;
26 }
27
28 TEST_CASE("MeatPackComments preserves indented comments", "[Binarize][MeatPack]") {
29 const std::vector<std::string> lines = {
30 ";FLUSH_START\n",
31 " G1 E1 F6000\n",
32 " ;FLUSH_END\n",
33 "\t;TAB_COMMENT\n",
34 };
35
36 const std::string roundtrip_result = roundtrip(lines, Flag_OmitWhitespaces);
37 REQUIRE(roundtrip_result.find(";FLUSH_START") != std::string::npos);
38 REQUIRE(roundtrip_result.find(";FLUSH_END") != std::string::npos);
39 REQUIRE(roundtrip_result.find(";TAB_COMMENT") != std::string::npos);
40 REQUIRE(roundtrip_result.find("G1") != std::string::npos);
41 }
42
43 TEST_CASE("MeatPack removes indented comments when Flag_RemoveComments set", "[Binarize][MeatPack]") {
44 const std::vector<std::string> lines = {
45 ";FLUSH_START\n",
46 " G1 E1 F6000\n",
47 " ;FLUSH_END\n",
48 "\t;TAB_COMMENT\n",
49 };
50
51 const std::string roundtrip_result = roundtrip(lines, Flag_OmitWhitespaces | Flag_RemoveComments);
52 REQUIRE(roundtrip_result.find(";FLUSH_START") == std::string::npos);
53 REQUIRE(roundtrip_result.find(";FLUSH_END") == std::string::npos);
54 REQUIRE(roundtrip_result.find(";TAB_COMMENT") == std::string::npos);
55 REQUIRE(roundtrip_result.find("G1") != std::string::npos);
56 }