Răsfoiți Sursa

Test that doubles in JsonValue are copied

Benoit Blanchon 11 ani în urmă
părinte
comite
d549070fd3
2 a modificat fișierele cu 16 adăugiri și 2 ștergeri
  1. 6 0
      srcs/JsonValue.cpp
  2. 10 2
      tests/JsonValueTests.cpp

+ 6 - 0
srcs/JsonValue.cpp

@@ -61,10 +61,16 @@ void JsonValue::operator=(JsonValue const& value)
         _node->content.asInteger = value._node->content.asInteger;
         break;
 
+    case JSON_DOUBLE_0_DECIMALS:
+
     case JSON_OBJECT:
     case JSON_ARRAY:
     case JSON_PROXY:
         setAsProxyTo(value._node);
+
+    default:
+        *_node = *value._node;
+        break;
     }
 }
 

+ 10 - 2
tests/JsonValueTests.cpp

@@ -59,12 +59,20 @@ TEST_F(JsonValueTests, CanStoreObject)
     EXPECT_EQ(innerObject1, (JsonObject) jsonValue1);
 }
 
-TEST_F(JsonValueTests, CanCopyInteger)
+TEST_F(JsonValueTests, IntegerValuesAreCopied)
 {
     jsonValue1 = 123;
     jsonValue2 = jsonValue1;
     jsonValue1 = 456;
 
-    EXPECT_EQ(456, (int) jsonValue1);
     EXPECT_EQ(123, (int) jsonValue2);
+}
+
+TEST_F(JsonValueTests, DoubleValuesAreCopied)
+{
+    jsonValue1 = 123.45;
+    jsonValue2 = jsonValue1;
+    jsonValue1 = 456.78;
+
+    EXPECT_EQ(123.45, (double) jsonValue2);
 }