Files
nbtpp/test/test.cpp

35 lines
923 B
C++

#include <catch2/catch_all.hpp>
#include <filesystem>
#include <fstream>
import nbtpp;
[[nodiscard]] std::vector<std::byte> load_binary(std::filesystem::path path) {
auto stream = std::ifstream(path, std::ios::binary);
const auto file_size = std::filesystem::file_size(path);
auto buffer = std::vector<std::byte>(file_size);
stream.read(reinterpret_cast<char *>(buffer.data()), file_size);
return buffer;
}
TEST_CASE("hello world", "[nbt.read]") {
const auto data = ::load_binary("test/data/hello_world.nbt");
const auto nodes = nbtpp::parse(data);
REQUIRE(nodes.size() == 2);
REQUIRE(nodes[0].type == nbtpp::tag::compound);
REQUIRE(nodes[0].name == "hello world");
REQUIRE(nodes[1].type == nbtpp::tag::string);
REQUIRE(nodes[1].name == "name");
REQUIRE(nodes[1].as<std::string>() == "Bananrama");
}
/*
TAG_Compound('hello world'): 1 entry
{
TAG_String('name'): 'Bananrama'
}
*/