Skip to content

Commit

Permalink
add short json support (#2335)
Browse files Browse the repository at this point in the history
* add short json support

* logic is done

* bug fixes

* fix crash on passing paramenters

* enhance code complexity, few bug fixes

* bug fixes

* update documentation

* fix typo

* fix json crash when passing array of objects

* update documentation

* add unit tests

* fix naming

* bug fixes, add more tests, and improve SOG

* bug fixes, more tests

* add space removal system

* add space removal system

* bug fixes, more tests

* bug fixes

* finalizing tests, bug fixes

* more tests

* fix double quotes read/write

* bug fixes

* update adding missing keys call for better readability

* add tests for JSON readers and parsers

* fix short JSON tests name

* last commit

* add deleted files

* readd deleted files

* few improvements

* improve tests

---------

Co-authored-by: saifkandil <saifsaalaheldeen2002@gmail.com>
  • Loading branch information
k0T0z and saifkandil committed Aug 9, 2023
1 parent 9adc96c commit c571874
Show file tree
Hide file tree
Showing 14 changed files with 1,338 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
/CompilerSource/stupidity-buffer/obj
/ENIGMAsystem/SHELL/.vs/*
/ENIGMAsystem/SHELL/.vscode/*
/.vscode/*
/CMakeFiles/*
/ENIGMAsystem/SHELL/.build/*
CMakeCache
.DS_Store

enigma-launch.bat
Expand Down
106 changes: 106 additions & 0 deletions CommandLine/emake-tests/Extensions/Json/json-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#if !defined(JSON_READER_TEST_CPP)
#define JSON_READER_TEST_CPP
#endif // JSON_READER_TEST_CPP

#include "Universal_System/Extensions/Json/json_reader.cpp"
#include "Universal_System/Extensions/Json/json_value.cpp"
#include "Universal_System/Extensions/Json/json_writer.cpp"
#include "Universal_System/Extensions/Json/reader.h"
#include "Universal_System/Extensions/Json/value.h"

#include <gtest/gtest.h>

#include <string>

TEST(JSONTest, TestSpaces) {
std::string data{
" { \"0\":\t{ \"0\": \" s \ttr\n \", \"1\": \n8 } , \"1\"\r\n:{\"0\":true,\"1\" : -4 } ,\r\"2\":\nfalse}"};
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse(std::string(data), root);

EXPECT_TRUE(root.isObject());
ASSERT_EQ(parsingSuccessful, true);
}

TEST(JSONTest, TestPassingArrayOfJSONObjects) {
std::string data{
"[{\"0\":{\"0\":{\"0\":1,\"1\":4},\"1\":[{\"0\":1,\"1\":4},{\"0\":1,\"1\":4}],\"2\":{\"0\":1,\"1\":4},"
"\"3\":7,\"4\":{\"0\":1,\"1\":4},\"5\":[{\"0\":1,\"1\":4},{\"0\":1,\"1\":4},{\"0\":1,\"1\":4}]},\"1\":{"
"\"0\":1,\"1\":4},\"2\":5},{\"0\":1,\"1\":4}]"};
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse(std::string(data), root);

EXPECT_TRUE(root.isArray());
ASSERT_EQ(parsingSuccessful, true);
}

TEST(JSONTest, TestPassingSingleJSONObject) {
std::string data{
"{\"0\":{\"0\":{\"0\":1,\"1\":4},\"1\":[{\"0\":1,\"1\":4},{\"0\":1,\"1\":4}],\"2\":{\"0\":1,\"1\":4},\"3\":"
"7,\"4\":{\"0\":1,\"1\":4},\"5\":[{\"0\":1,\"1\":4},{\"0\":1,\"1\":4},{\"0\":1,\"1\":4}]},\"1\":{\"0\":1,"
"\"1\":4},\"2\":5}"};
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse(std::string(data), root);

EXPECT_TRUE(root.isObject());
ASSERT_EQ(parsingSuccessful, true);
}

TEST(JSONTest, TestPassingExtensiveGeneralInput) {
std::string data{
"{"
"\"0\":{"
"\"0\":{"
"\"0\":\"] ][dm895vmfv_,,\","
"\"1\":true"
"},"
"\"1\":["
"{"
"\"0\":false,"
"\"1\":-46.8"
"},"
"{"
"\"0\":\"dsjdjk\","
"\"1\":65890.3"
"}"
"],"
"\"2\":{"
"\"0\":-77777777777,"
"\"1\":44444444"
"},"
"\"3\":true,"
"\"4\":{"
"\"0\":\"\","
"\"1\":4567.1"
"},"
"\"5\":["
"{"
"\"0\":13,"
"\"1\":0"
"},"
"{"
"\"0\":\"ty \","
"\"1\":true"
"},"
"{"
"\"0\":133,"
"\"1\":\"fghkll::\""
"}"
"]"
"},"
"\"1\":{"
"\"0\":1.6678,"
"\"1\":4"
"},"
"\"2\":5"
"}"};
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse(std::string(data), root);

EXPECT_TRUE(root.isObject());
ASSERT_EQ(parsingSuccessful, true);
}

0 comments on commit c571874

Please sign in to comment.