initial commit (compound / primitive - list)
This commit is contained in:
13
test/CMakeLists.txt
Normal file
13
test/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.8.1
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
add_executable(tests test.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain nbtpp)
|
||||
|
||||
BIN
test/data/bigtest.nbt
Normal file
BIN
test/data/bigtest.nbt
Normal file
Binary file not shown.
BIN
test/data/hello_world.nbt
Normal file
BIN
test/data/hello_world.nbt
Normal file
Binary file not shown.
BIN
test/data/random_nbt.nbt
Normal file
BIN
test/data/random_nbt.nbt
Normal file
Binary file not shown.
34
test/test.cpp
Normal file
34
test/test.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#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'
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user