forked from SwuduSusuwu/SubStack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassResultList.cxx
33 lines (32 loc) · 2.2 KB
/
ClassResultList.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* (C) 2024 Swudu Susuwu, dual licenses: choose [GPLv2](./LICENSE_GPLv2) or [Apache 2](./LICENSE), allows all uses. */
#ifndef INCLUDES_cxx_ClassResultList_cxx
#define INCLUDES_cxx_ClassResultList_cxx
#include "ClassResultList.hxx" /* resultList resultListDumpTo ResultListHash */
#include "Macros.hxx" /* SUSUWU_ERRSTR SUSUWU_SH_GREEN SUSUWU_NOEXCEPT SUSUWU_SH_ERROR SUSUWU_SH_RED SUSUWU_SH_WHITE SUSUWU_UNIT_TESTS */
#include <sstream> /* std::stringstream */
#include <stdexcept> /* std::runtime_error */
#include <string> /* std::string */
#if SUSUWU_UNIT_TESTS
namespace Susuwu {
namespace { /* [misc-use-anonymouse-namespace] */
static void classResultListDumpToTest(const ResultList &resultList, bool index, bool whitespace, bool pascalValues, const std::string &expectedValue) {
std::stringstream os;
resultListDumpTo(resultList, os, index, whitespace, pascalValues);
if(expectedValue != os.str()) {
throw std::runtime_error(SUSUWU_ERRSTR(SUSUWU_SH_ERROR, std::string("classResultListDumpToTest(resultList, os, ") + (index ? "true" : "false") + ", " + (whitespace ? "true" : "false") + ", " + (pascalValues ? "true" : "false") + "); \"" SUSUWU_SH_RED + os.str() + SUSUWU_SH_WHITE "\" == os.str(); \"" SUSUWU_SH_GREEN + expectedValue + SUSUWU_SH_WHITE "\" != os.str();")); /* TODO: standard macros for error/success colors, plus `SUSUWU_ERR` default color */
}
}
}; /* namespace */
const bool classResultListTests() {
ResultList resultList;
resultList.hashes.insert(ResultListHash({'\x32'})); /* `.hashes` is `std::unordered_set`, thus test just 1 value. */
resultList.signatures = {"1", "2"};
resultList.bytecodes = {"01", "02"};
classResultListDumpToTest(resultList, false, false, false, "list.hashes={0x32};list.signatures={0x31,0x32};list.bytecodes={0x3031,0x3032};");
classResultListDumpToTest(resultList, true, true, false, "list.hashes = {\n\t0 = 0x32\n};\nlist.signatures = {\n\t0 = 0x31,\n\t1 = 0x32\n};\nlist.bytecodes = {\n\t0 = 0x3031,\n\t1 = 0x3032\n};\n");
classResultListDumpToTest(resultList, false, false, true, "list.hashes={1:2};list.signatures={1:1,1:2};list.bytecodes={2:01,2:02};");
return true;
}
}; /* namespace Susuwu */
#endif /* SUSUWU_UNIT_TESTS */
#endif /* ndef INCLUDES_cxx_ClassResultList_cxx */