From edbbe8dcfd30fcfe84f6b62240e22dbf9138677c Mon Sep 17 00:00:00 2001 From: YongDo-Hyun Date: Wed, 26 Nov 2025 20:10:42 +0300 Subject: feat: add local test executable and improve JSON string escaping - Added option to build a local test executable for value assignments. - Enhanced JSON string formatting by escaping special characters. - Updated README with build instructions and prerequisites. - Modified .gitignore to include .vscode directory. - Added file read/write tests in format_test.cpp. - Refactored value assignment logic to reduce code duplication. Signed-off-by: YongDo-Hyun --- test/format_test.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'test/format_test.cpp') diff --git a/test/format_test.cpp b/test/format_test.cpp index 559af11299..1a689ed3f2 100644 --- a/test/format_test.cpp +++ b/test/format_test.cpp @@ -22,7 +22,8 @@ * along with libnbt++. If not, see . */ //#include "text/json_formatter.h" -//#include "io/stream_reader.h" +#include "io/stream_reader.h" +#include "io/stream_writer.h" #include #include #include @@ -32,7 +33,7 @@ using namespace nbt; int main() { - //TODO: Write that into a file + // Write that into a file and read back for testing tag_compound comp{ {"byte", tag_byte(-128)}, {"short", tag_short(-32768)}, @@ -83,4 +84,20 @@ int main() std::cout << "----- default operator<<:\n"; std::cout << comp; std::cout << "\n-----" << std::endl; + + // Write to file and read back + { + std::ofstream out("test_output.nbt", std::ios::binary); + nbt::io::write_compound(out, comp); + } + + { + std::ifstream in("test_output.nbt", std::ios::binary); + auto [read_comp, name] = nbt::io::read_compound(in); + std::cout << "----- read back from file:\n"; + std::cout << read_comp; + std::cout << "\n-----" << std::endl; + } + + return 0; } -- cgit 0.0.5-2-1-g0f52