tests,json: Fix match if the first child differs
authorAndre Heinecke <aheinecke@intevation.de>
Wed, 14 Nov 2018 14:17:18 +0000 (15:17 +0100)
committerAndre Heinecke <aheinecke@intevation.de>
Wed, 14 Nov 2018 14:17:18 +0000 (15:17 +0100)
* tests/json/t-json.c (test_contains): Try all siblings of
the haystack child.

--
This fixes the case where we don't match against the
first child because the order might have changed or
a new element was inserted at the top. Then we
have to try out also all the siblings.

tests/json/t-json.c

index 1f45feb..7a4d906 100644 (file)
@@ -154,7 +154,19 @@ test_contains (cjson_t needle, cjson_t hay)
         }
       if (test_contains (needle->child, hay->child))
         {
-          return 1;
+          int found = 0;
+          for (cjson_t hit = hay->child; hit; hit = hit->next)
+            {
+              found |= !test_contains (needle->child, hit);
+              if (found)
+                {
+                  break;
+                }
+            }
+          if (!found)
+            {
+              return 1;
+            }
         }
     }