Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected state persistence in the json parser #2189

Merged
merged 1 commit into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/json/json_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
#include <util/json.h>

int yyjsonparse();
void yyjsonrestart(FILE *input_file);

class json_parsert:public parsert
{
Expand Down Expand Up @@ -46,6 +47,7 @@ class json_parsert:public parsert
virtual void clear() override
{
stack=stackt();
yyjsonrestart(nullptr);
}
};

Expand Down
1 change: 1 addition & 0 deletions unit/json/invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
69 changes: 69 additions & 0 deletions unit/json/json_parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*******************************************************************\

Module: Example Catch Tests

Author: Diffblue Ltd.

\*******************************************************************/

#include <json/json_parser.h>
#include <testing-utils/catch.hpp>

SCENARIO("Loading JSON files")
{
null_message_handlert message_handler;
GIVEN("A invalid JSON file and a valid JSON file")
{
const std::string valid_json_path = "./json/valid.json";
const std::string invalid_json_path = "./json/invalid.json";

WHEN("Loading the invalid JSON file")
{
jsont invalid_json;
const auto invalid_parse_error =
parse_json(invalid_json_path, message_handler, invalid_json);
THEN("An error state should be returned")
{
REQUIRE(invalid_parse_error);
REQUIRE(invalid_json.is_null());
AND_WHEN("Loading the valid JSON file")
{
jsont valid_json;
const auto valid_parse_error =
parse_json(valid_json_path, message_handler, valid_json);
THEN("The JSON file should be parsed correctly")
{
REQUIRE_FALSE(valid_parse_error);
REQUIRE(valid_json.is_object());
REQUIRE(valid_json.object.find("hello") != valid_json.object.end());
REQUIRE(valid_json.object["hello"].value == "world");
}
}
}
}
WHEN("Loading the valid JSON file")
{
jsont valid_json;
const auto valid_parse_error =
parse_json(valid_json_path, message_handler, valid_json);
THEN("The JSON file should be parsed correctly")
{
REQUIRE_FALSE(valid_parse_error);
REQUIRE(valid_json.is_object());
REQUIRE(valid_json.object.find("hello") != valid_json.object.end());
REQUIRE(valid_json.object["hello"].value == "world");
AND_WHEN("Loading the invalid JSON file")
{
jsont invalid_json;
const auto invalid_parse_error =
parse_json(invalid_json_path, message_handler, invalid_json);
THEN("An error state should be returned")
{
REQUIRE(invalid_parse_error);
REQUIRE(invalid_json.is_null());
}
}
}
}
}
}
3 changes: 3 additions & 0 deletions unit/json/valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "world"
}