Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Conversation

@sparkprime
Copy link
Contributor

No description provided.

@sparkprime
Copy link
Contributor Author

@igorpeshansky

-10.0, -10.0e+0, -10.0e-0, -10.0e0, -10.0E+0, -10.0E-0, -10.0E0,
-123, -123.456, -789, -1.05, -1.999e-99,
}));
// TODO(igorp): This first one looks spurious.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, which first one? Do you mean -0 transforming to 0.0? That's because with int, there is no separate representation for -0, so it gets converted to static_cast<double>(0). Nothing to do here.

Copy link
Contributor Author

@sparkprime sparkprime Mar 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't explain json::Parser::FromString("-0")->ToString() == "0"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, true. Ok, warrants further investigation. Let's remove the username from the TODO, though, and add what you just said...

// String edge cases

/*
* TODO(igorp): Seems that yajl does not support valid JSON.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already an issue for this. Let's just change this to:
// TODO: yajl doesn't support newlines in strings (https://github.com/lloyd/yajl/issues/180).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.

format_unittest \
health_checker_unittest \
resource_unittest \
json_unittest \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to keep these in alphabetical order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#include "../src/json.h"
#include "gtest/gtest.h"

#define EXPECT_TO_STRING(v, s) EXPECT_EQ(v->ToString(), s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EXPECT_TOSTRING_EQ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,385 @@
#include <functional>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have this after the first two includes (for consistency).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a blank line before this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

TEST(TrivialParseTest, Null) {
GuardJsonException([](){
std::unique_ptr<json::Value> v = json::Parser::FromString("null");
EXPECT_EQ(v->type(), json::NullType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention seems to be EXPECT_EQ(expected, actual).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#include "../src/json.h"
#include "gtest/gtest.h"

#define EXPECT_TO_STRING(v, s) EXPECT_EQ(v->ToString(), s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention seems to be EXPECT_EQ(expected, actual).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

TEST(EdgeTest, StringWithUnicodeEscape) {
GuardJsonException([](){
std::unique_ptr<json::Value> v = json::Parser::FromString("\"foo\\u000abar\"");
//EXPECT_EQ(v->As<json::String>()->value(), "foo\nbar");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover debugging code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

TEST(EdgeTest, StringWithUTF8) {
GuardJsonException([](){
// This is Korean for "Hello World!".
std::unique_ptr<json::Value> v = json::Parser::FromString("\"안녕 세상아!\"");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My heartfelt thanks for not using the poop emoji. 😄


// Number edge cases

TEST(EdgeTest, PositiveNumbers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a parse/ToString test? Would it make sense to also test JSON construction:

    json::value v = json::array({
      0, 0e+0, 0e-0, 0e0, 0E+0, 0E-0, 0E0,
      0.0, 0.0e+0, 0.0e-0, 0.0e0, 0.0E+0, 0.0E-0, 0.0E0,
      10, 10e+0, 10e-0, 10e0, 10E+0, 10E-0, 10E0,
      10.0, 10.0e+0, 10.0e-0, 10.0e0, 10.0E+0, 10.0E-0, 10.0E0,
      123, 123.456, 789, 1.05, 1.999e-99,
    });

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's testing the C++ parser though. I could have split it into two parts, but since we do a lot of that already (and therefore ensure good coverage) I figured an end-to-end test is enough here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also testing the contract provided by those functions and constructors... Let's do this in the RealisticConstruction tests.

});
}

TEST(BigTest, LotsOfNesting) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested objects, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// Big tests.

TEST(BigTest, Realistic) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also check construction:

    json::value v = json::object({
      {"foo", json::array({json::number(1), json::number(2), json::number(3)})},
      {"bar", json::object({{"x", json::number(0)}, {"y", json::null()}})},
      {"baz", json::boolean(true)},
      {"str", json::string("asdfasdf")},
    });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@igorpeshansky
Copy link
Contributor

@sparkprime Did you mean to push another commit?

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments.

@@ -0,0 +1,385 @@
#include <functional>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a blank line before this one.

}


// Trival Null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json::value v = json::Parser::FromString("{\"f\":2}");
const auto& obj = v->As<json::Object>();
EXPECT_EQ(1, obj->size());
EXPECT_EQ(2.0, obj->Get<json::Number>("f"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add this here or in a separate test:

    EXPECT_TRUE(v->As<json::Object>()->Has("f"));
    EXPECT_FALSE(v->As<json::Object>()->Has("g"));


// Number edge cases

TEST(EdgeTest, PositiveNumbers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also testing the contract provided by those functions and constructors... Let's do this in the RealisticConstruction tests.

-10.0, -10.0e+0, -10.0e-0, -10.0e0, -10.0E+0, -10.0E-0, -10.0E0,
-123, -123.456, -789, -1.05, -1.999e-99,
}));
// TODO(igorp): This first one looks spurious.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, true. Ok, warrants further investigation. Let's remove the username from the TODO, though, and add what you just said...

"123.0,123.45600000000000307,789.0,"
"1.0500000000000000444,1.9989999999999998999e-99"
"]",
v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well close the parenthesis on this line. Also in other EXPECT_TOSTRING_EQ calls below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor stuff.

TEST(TrivialToStringTest, ObjectOneField) {
GuardJsonException([](){
json::value v = json::object({
{"f", json::number(2.0)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a trailing comma, to indicate our preference to that style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

ASSERT_THROW(json::Parser::FromString("{\"x\":}"), json::Exception);
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove one of these two blank lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
LGTM :shipit:

Let's squash-and-merge this!

Copy link
Contributor

@bmoyles0117 bmoyles0117 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@igorpeshansky igorpeshansky merged commit 2aecc4d into master Mar 27, 2018
@igorpeshansky igorpeshansky deleted the dcunnin-json-tests branch March 27, 2018 23:10
dhrupadb pushed a commit that referenced this pull request Mar 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants