TEST_F(JsonParser_Object_Test, TwoIntergers) {
  whenInputIs("{\"key1\":42,\"key2\":-42}");
  parseMustSucceed();
  sizeMustBe(2);
  keyMustHaveValue("key1", 42);
  keyMustHaveValue("key2", -42);
}
TEST_F(JsonParser_Object_Test, TwoDoubles) {
  whenInputIs("{\"key1\":12.345,\"key2\":-7E89}");
  parseMustSucceed();
  sizeMustBe(2);
  keyMustHaveValue("key1", 12.345);
  keyMustHaveValue("key2", -7E89);
}
TEST_F(JsonParser_Object_Test, TwoStringsSpaceAfterComma) {
  whenInputIs("{\"key1\":\"value1\" ,\"key2\":\"value2\"}");
  parseMustSucceed();
  sizeMustBe(2);
  keyMustHaveValue("key1", "value1");
  keyMustHaveValue("key2", "value2");
}
TEST_F(StaticJsonBuffer_ParseObject_Tests,
       BufferOfTheRightSizeForObjectWithNestedObject) {
  StaticJsonBuffer<JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(0)> bufferOfRightSize;
  with(bufferOfRightSize);
  whenInputIs("{\"a\":[]}");
  parseMustSucceed();
}
TEST_F(StaticJsonBuffer_ParseObject_Tests,
       TooSmallBufferForObjectWithNestedObject) {
  StaticJsonBuffer<JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(0) - 1> bufferTooSmall;
  with(bufferTooSmall);
  whenInputIs("{\"a\":[]}");
  parseMustFail();
}
TEST_F(JsonParser_Object_Test, TwoBooleans) {
  whenInputIs("{\"key1\":true,\"key2\":false}");
  parseMustSucceed();
  sizeMustBe(2);
  keyMustHaveValue("key1", true);
  keyMustHaveValue("key2", false);
}
TEST_F(StaticJsonBuffer_ParseArray_Tests,
       BufferOfTheRightSizeForArrayWithNestedObject) {
  StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0)> bufferOfRightSize;
  with(bufferOfRightSize);
  whenInputIs("[{}]");
  parseMustSucceed();
}
TEST_F(StaticJsonBuffer_ParseObject_Tests,
       TooSmallBufferForObjectWithOneValue) {
  StaticJsonBuffer<JSON_OBJECT_SIZE(1) - 1> bufferTooSmall;
  with(bufferTooSmall);
  whenInputIs("{\"a\":1}");
  parseMustFail();
}
TEST_F(JsonParser_Array_Tests, StringWithEscapedChars) {
  whenInputIs("[\"1\\\"2\\\\3\\/4\\b5\\f6\\n7\\r8\\t9\"]");

  parseMustSucceed();
  sizeMustBe(1);
  firstElementMustBe("1\"2\\3/4\b5\f6\n7\r8\t9");
}
TEST_F(JsonParser_Array_Tests, OneIntegerWithSpacesBefore) {
  whenInputIs("[ \t\r\n42]");

  parseMustSucceed();
  sizeMustBe(1);
  firstElementMustBe(42);
}
TEST_F(JsonParser_Array_Tests, CCommentBeforeClosingBracket) {
  whenInputIs("[\"hello\"/*COMMENT*/]");

  parseMustSucceed();
  sizeMustBe(1);
  firstElementMustBe("hello");
}
TEST_F(JsonParser_Array_Tests, CppCommentBeforeOpeningBracket) {
  whenInputIs("//COMMENT\n\t[\"hello\"]");

  parseMustSucceed();
  sizeMustBe(1);
  firstElementMustBe("hello");
}
TEST_F(JsonParser_Array_Tests, OneInteger) {
  whenInputIs("[42]");

  parseMustSucceed();
  sizeMustBe(1);
  firstElementMustBe(42);
}
TEST_F(JsonParser_Array_Tests, CppCommentAfterClosingBracket) {
  whenInputIs("[\"hello\"]//COMMENT\n");

  parseMustSucceed();
  sizeMustBe(1);
  firstElementMustBe("hello");
}
TEST_F(StaticJsonBuffer_ParseArray_Tests,
       BufferOfTheRightSizeForArrayWithOneValue) {
  StaticJsonBuffer<JSON_ARRAY_SIZE(1)> bufferOfRightSize;
  with(bufferOfRightSize);
  whenInputIs("[1]");
  parseMustSucceed();
}
TEST_F(JsonParser_Array_Tests, CCommentAfterOpeningBracket) {
  whenInputIs("[/*COMMENT*/ \"hello\"]");

  parseMustSucceed();
  sizeMustBe(1);
  firstElementMustBe("hello");
}
TEST_F(StaticJsonBuffer_ParseObject_Tests,
       BufferOfTheRightSizeForObjectWithOneValue) {
  StaticJsonBuffer<JSON_OBJECT_SIZE(1)> bufferOfRightSize;
  with(bufferOfRightSize);
  whenInputIs("{\"a\":1}");
  parseMustSucceed();
}
TEST_F(StaticJsonBuffer_ParseArray_Tests,
       TooSmallBufferForArrayWithNestedObject) {
  StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0) - 1> bufferTooSmall;
  with(bufferTooSmall);
  whenInputIs("[{}]");
  parseMustFail();
}
TEST_F(JsonParser_Array_Tests, UnsignedLong) {
  whenInputIs("[4294967295]");

  parseMustSucceed();
  sizeMustBe(1);
  firstElementMustBe(4294967295UL);
}
TEST_F(JsonParser_Array_Tests, CppCommentAfterComma) {
  whenInputIs("[\"hello\",//COMMENT\n\"world\"]");

  parseMustSucceed();
  sizeMustBe(2);
  firstElementMustBe("hello");
  secondElementMustBe("world");
}
TEST_F(JsonParser_Array_Tests, CCommentBeforeComma) {
  whenInputIs("[\"hello\"/*COMMENT*/,\"world\"]");

  parseMustSucceed();
  sizeMustBe(2);
  firstElementMustBe("hello");
  secondElementMustBe("world");
}
TEST_F(JsonParser_Array_Tests, TwoIntegers) {
  whenInputIs("[42,84]");

  parseMustSucceed();
  sizeMustBe(2);
  firstElementMustBe(42);
  secondElementMustBe(84);
}
TEST_F(JsonParser_Array_Tests, EmptyStringNoQuotes) {
  whenInputIs("[,]");

  parseMustSucceed();
  sizeMustBe(2);
  firstElementMustBe("");
  secondElementMustBe("");
}
TEST_F(JsonParser_Array_Tests, TwoStringsDoubleQuotes) {
  whenInputIs("[ \"hello\" , \"world\" ]");

  parseMustSucceed();
  sizeMustBe(2);
  firstElementMustBe("hello");
  secondElementMustBe("world");
}
TEST_F(JsonParser_Array_Tests, TwoBooleans) {
  whenInputIs("[true,false]");

  parseMustSucceed();
  sizeMustBe(2);
  firstElementMustBe(true);
  secondElementMustBe(false);
}
TEST_F(JsonParser_Array_Tests, TwoDoubles) {
  whenInputIs("[4.2,1e2]");

  parseMustSucceed();
  sizeMustBe(2);
  firstElementMustBe(4.2);
  secondElementMustBe(1e2);
}
TEST_F(JsonParser_Array_Tests, TwoStringsNoQuotes) {
  whenInputIs("[ hello , world ]");

  parseMustSucceed();
  sizeMustBe(2);
  firstElementMustBe("hello");
  secondElementMustBe("world");
}
TEST_F(JsonParser_Object_Test, TwoNulls) {
  const char *const nullstr = 0;

  whenInputIs("{\"key1\":null,\"key2\":null}");
  parseMustSucceed();
  sizeMustBe(2);
  keyMustHaveValue("key1", nullstr);
  keyMustHaveValue("key2", nullstr);
}
TEST_F(JsonParser_Array_Tests, TwoNulls) {
  const char *const nullCharPtr = 0;

  whenInputIs("[null,null]");

  parseMustSucceed();
  sizeMustBe(2);
  firstElementMustBe(nullCharPtr);
  secondElementMustBe(nullCharPtr);
}
TEST_F(StaticJsonBuffer_ParseArray_Tests, TooSmallBufferForArrayWithOneValue) {
  StaticJsonBuffer<JSON_ARRAY_SIZE(1) - 1> bufferTooSmall;
  with(bufferTooSmall);
  whenInputIs("[1]");
  parseMustFail();
}