From 1143094e4cb7252eaf9b16ab537c83d0e1f44356 Mon Sep 17 00:00:00 2001
From: Niels <niels.lohmann@gmail.com>
Date: Sun, 3 May 2015 20:07:31 +0200
Subject: [PATCH] testing the callback function

---
 test/unit.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/test/unit.cpp b/test/unit.cpp
index 16973673..eb8af129 100644
--- a/test/unit.cpp
+++ b/test/unit.cpp
@@ -7682,6 +7682,54 @@ TEST_CASE("parser class")
         CHECK_THROWS_AS(json::parse("\"\\uD80C\\u0000\""), std::invalid_argument);
         CHECK_THROWS_AS(json::parse("\"\\uD80C\\uFFFF\""), std::invalid_argument);
     }
+
+    SECTION("callback function")
+    {
+        auto s_object = R"(
+            {
+                "foo": true,
+                "bar": false
+            }
+        )";
+
+        auto s_array = R"(
+            [1,2,3,4,5]
+        )";
+
+        SECTION("true-filter")
+        {
+            json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&)
+            {
+                return true;
+            });
+
+            CHECK (j_object == json({{"foo", true}, {"bar", false}}));
+
+            json j_array = json::parse(s_array, [](int, json::parse_event_t, const json&)
+            {
+                return true;
+            });
+
+            CHECK (j_array == json({1, 2, 3, 4, 5}));
+        }
+
+        SECTION("false-filter")
+        {
+            json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&)
+            {
+                return false;
+            });
+
+            CHECK (j_object.is_discarded());
+
+            json j_array = json::parse(s_array, [](int, json::parse_event_t, const json&)
+            {
+                return false;
+            });
+
+            CHECK (j_array.is_discarded());
+        }
+    }
 }
 
 TEST_CASE("README", "[hide]")