diff OrthancFramework/UnitTestsSources/ToolboxTests.cpp @ 4397:3aeb5171fbd4

new function Toolbox::ReadJsonWithoutComments()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Dec 2020 08:59:23 +0100
parents f7104e9d044c
children d9473bd5ed43
line wrap: on
line diff
--- a/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Tue Dec 22 08:16:08 2020 +0100
+++ b/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Tue Dec 22 08:59:23 2020 +0100
@@ -64,6 +64,21 @@
   ASSERT_EQ(Toolbox::StripSpaces(f), "{\n   \"hello\" : \"world\"\n}");
 }
 
+TEST(Toolbox, JsonComments)
+{
+  std::string a = "/* a */ { /* b */ \"hello\" : /* c */ \"world\" /* d */ } // e";
+
+  Json::Value b;
+  ASSERT_TRUE(Toolbox::ReadJsonWithoutComments(b, a));
+
+  std::string c;
+  Toolbox::WriteFastJson(c, b);
+  ASSERT_EQ(Toolbox::StripSpaces(c), "{\"hello\":\"world\"}");
+  
+  Toolbox::WriteStyledJson(c, b);
+  ASSERT_EQ(Toolbox::StripSpaces(c), "{\n   \"hello\" : \"world\"\n}");
+}
+
 TEST(Toolbox, Base64_allByteValues)
 {
   std::string toEncode;