Add FacadeTest

This commit is contained in:
2024-05-14 14:41:12 -07:00
parent 82dcaf45e0
commit 607aea3213
3 changed files with 238 additions and 0 deletions

65
FacadeTest.cpp Normal file
View File

@@ -0,0 +1,65 @@
#include "Facade.h"
#include "VersionedMap.h"
#include <inttypes.h>
inline weaselab::VersionedMap::Key operator"" _k(const char *str, size_t size) {
return {reinterpret_cast<const uint8_t *>(str), int(size)};
}
inline String operator"" _s(const char *str, size_t size) {
return String{reinterpret_cast<const uint8_t *>(str), size};
}
weaselab::VersionedMap::Mutation set(weaselab::VersionedMap::Key k,
weaselab::VersionedMap::Key v) {
return {k.p, v.p, k.len, v.len, weaselab::VersionedMap::Set};
}
weaselab::VersionedMap::Mutation clear(weaselab::VersionedMap::Key k) {
return {k.p, nullptr, k.len, 0, weaselab::VersionedMap::Clear};
}
weaselab::VersionedMap::Mutation clear(weaselab::VersionedMap::Key begin,
weaselab::VersionedMap::Key end) {
return {begin.p, end.p, begin.len, end.len, weaselab::VersionedMap::Clear};
}
int main() {
Facade f(0);
int64_t version = 1;
{
weaselab::VersionedMap::Mutation m[] = {
set("a"_k, "a"_k), set("b"_k, "b"_k), set("c"_k, "c"_k),
set("d"_k, "d"_k), set("e"_k, "e"_k),
};
f.addMutations(m, sizeof(m) / sizeof(m[0]), version++);
}
{
weaselab::VersionedMap::Mutation m[] = {
clear("b"_k, "d"_k),
};
f.addMutations(m, sizeof(m) / sizeof(m[0]), version++);
}
for (int64_t i = 0; i < version; ++i) {
printf("--- version %" PRId64 " ---\n", i);
auto result = f.viewAt(i).rangeRead("a"_s, "d"_s, 10, false);
for (const auto &[k, v] : result) {
for (auto c : k) {
if (isprint(c)) {
printf("%c", c);
} else {
printf("0x%02x", c);
}
}
printf(" -> ");
for (auto c : v) {
if (isprint(c)) {
printf("%c", c);
} else {
printf("0x%02x", c);
}
}
printf("\n");
}
}
}