summaryrefslogtreecommitdiff
path: root/test/format_test.cpp
diff options
context:
space:
mode:
authorYongDo-Hyun <froster12@naver.com>2025-11-26 20:10:42 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-03-27 19:57:09 +0300
commitedbbe8dcfd30fcfe84f6b62240e22dbf9138677c (patch)
tree8b9c8edb939d573d76d6390535d3eacf4342e9c4 /test/format_test.cpp
parent687e43031df0dc641984b4256bcca50d5b3f7de3 (diff)
downloadProject-Tick-edbbe8dcfd30fcfe84f6b62240e22dbf9138677c.tar.gz
Project-Tick-edbbe8dcfd30fcfe84f6b62240e22dbf9138677c.zip
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 <froster12@naver.com>
Diffstat (limited to 'test/format_test.cpp')
-rw-r--r--test/format_test.cpp21
1 files changed, 19 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>.
*/
//#include "text/json_formatter.h"
-//#include "io/stream_reader.h"
+#include "io/stream_reader.h"
+#include "io/stream_writer.h"
#include <fstream>
#include <iostream>
#include <limits>
@@ -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;
}