summaryrefslogtreecommitdiff
path: root/test/main.cpp
diff options
context:
space:
mode:
authorDylan <boss@tehbox.org>2026-06-06 19:36:41 +1200
committerDylan <boss@tehbox.org>2026-06-06 19:36:41 +1200
commit1d379a5cf34475f66f2ab9359f77dac162c0a40e (patch)
tree395d54815331fbcad053001bf5cb28fafb69e9d4 /test/main.cpp
parent46c896bcd78d31130321562b0659e28230261b8e (diff)
downloadtehjson-1d379a5cf34475f66f2ab9359f77dac162c0a40e.tar.gz
tehjson-1d379a5cf34475f66f2ab9359f77dac162c0a40e.zip
feat: JSON reading
- Implemented a tokenizer for json - Implemented a method which will read json from a string using the tokenizer
Diffstat (limited to 'test/main.cpp')
-rw-r--r--test/main.cpp44
1 files changed, 24 insertions, 20 deletions
diff --git a/test/main.cpp b/test/main.cpp
index 9430503..e86ec06 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -1,4 +1,5 @@
#include <json.hpp>
+#include <tokenizer.h>
#include <iostream>
#include <memory>
@@ -85,26 +86,29 @@ template <> std::string TehJSON::JSON::serializeData<std::string>(std::shared_pt
int main()
{
- TehJSON::JSON json;
+ TehJSON::JSON jsonWriter;
// TestClass test1;
// json["test1"].set(test1);
- json["test_string"].set<std::string>("stringy");
- json["test_int"].set<int>(123);
- json["test_float"].set<float>(51.8);
- json["test_object"]["test_int"].set<int>(100);
- json["test_object"]["test_float"].set<float>(100);
-
- cout << json.getSerialized() << endl;
-
- // std::shared_ptr<void> test;
- // test = std::make_shared<TestClass>(1);
- // test = std::make_shared<TestClass>(2);
- // test = std::make_shared<std::string>(std::string("test"));
- // std::string& testRef = *(std::string*)test.get();
- // cout << *(std::string*)test.get() << endl;
- // testRef += " test2";
- // cout << *(std::string*)test.get() << endl;
-
-
- cout << "abc" << endl;
+ jsonWriter["test_string"].set<std::string>("stringy");
+ jsonWriter["test_int"].set<int>(123);
+ jsonWriter["test_float"].set<float>(51.8);
+ jsonWriter["test_object"]["test_int"].set<int>(100);
+ jsonWriter["test_object"]["test_float"].set<float>(100);
+
+ std::string jsonString = jsonWriter.getSerialized();
+ cout << jsonString << endl;
+
+ // TehJSON::Tokenizer tokenizer;
+ // tokenizer.appendInput(jsonString);
+ // std::vector<TehJSON::Token> tokens = tokenizer.tokenize();
+
+ // for(const auto& token : tokens)
+ // {
+ // cout << TehJSON::getTokenName(token.type) << ": " << token.content << endl;
+ // }
+
+ TehJSON::JSON jsonReader;
+ cout << "Reading: " << endl;
+ jsonReader.readFromString(jsonString);
+ cout << jsonReader.getSerialized() << endl;
}