Parcourir la source

Improved coverage of JsonArray

Benoit Blanchon il y a 5 ans
Parent
commit
300323cfd7
2 fichiers modifiés avec 38 ajouts et 3 suppressions
  1. 20 1
      extras/tests/JsonArray/equals.cpp
  2. 18 2
      extras/tests/JsonArray/iterator.cpp

+ 20 - 1
extras/tests/JsonArray/equals.cpp

@@ -31,7 +31,7 @@ TEST_CASE("JsonArray::operator==()") {
     REQUIRE_FALSE(array1c == array2c);
   }
 
-  SECTION("should return false when RKS has more elements") {
+  SECTION("should return false when RHS has more elements") {
     array1.add(1);
     array2.add(1);
     array2.add(2);
@@ -47,4 +47,23 @@ TEST_CASE("JsonArray::operator==()") {
     REQUIRE(array1 == array2);
     REQUIRE(array1c == array2c);
   }
+
+  SECTION("should return false when RHS is null") {
+    JsonArray null;
+
+    REQUIRE_FALSE(array1 == null);
+  }
+
+  SECTION("should return false when LHS is null") {
+    JsonArray null;
+
+    REQUIRE_FALSE(null == array1);
+  }
+
+  SECTION("should return true when both are null") {
+    JsonArray null1;
+    JsonArray null2;
+
+    REQUIRE(null1 == null2);
+  }
 }

+ 18 - 2
extras/tests/JsonArray/iterator.cpp

@@ -28,9 +28,25 @@ static void run_iterator_test() {
 }
 
 TEST_CASE("JsonArray::begin()/end()") {
-  run_iterator_test<JsonArray>();
+  SECTION("Non null JsonArray") {
+    run_iterator_test<JsonArray>();
+  }
+
+  SECTION("Null JsonArray") {
+    JsonArray array;
+
+    REQUIRE(array.begin() == array.end());
+  }
 }
 
 TEST_CASE("JsonArrayConst::begin()/end()") {
-  run_iterator_test<JsonArrayConst>();
+  SECTION("Non null JsonArrayConst") {
+    run_iterator_test<JsonArrayConst>();
+  }
+
+  SECTION("Null JsonArrayConst") {
+    JsonArrayConst array;
+
+    REQUIRE(array.begin() == array.end());
+  }
 }