@@ -804,7 +804,22 @@ struct JSONValue
804
804
assert (j[" author" ].str == " Walter" );
805
805
}
806
806
807
- // /
807
+ /**
808
+ * Compare two JSONValues for equality
809
+ *
810
+ * JSON arrays an objects are compared deeply. The order of object keys does not matter.
811
+ *
812
+ * Floating point numbers are compared for exact equality, not approximal equality.
813
+ *
814
+ * Different number types (unsigned, signed, and floating) will be compared by converting
815
+ * them to a common type, in the same way that comparison of built-in D `int`, `uint` and
816
+ * `float` works.
817
+ *
818
+ * Other than that, types must match exactly.
819
+ * Empty arrays are not equal to empty objects, and booleans are never equal to integers.
820
+ *
821
+ * Returns: whether this `JSONValue` is equal to `rhs`
822
+ */
808
823
bool opEquals (const JSONValue rhs) const @nogc nothrow pure @safe
809
824
{
810
825
return opEquals (rhs);
@@ -871,9 +886,13 @@ struct JSONValue
871
886
// /
872
887
@safe unittest
873
888
{
874
- assert (JSONValue(0u ) == JSONValue(0 ));
875
- assert (JSONValue(0u ) == JSONValue(0.0 ));
876
- assert (JSONValue(0 ) == JSONValue(0.0 ));
889
+ assert (JSONValue(10 ).opEquals (JSONValue(10.0 )));
890
+ assert (JSONValue(10 ) != (JSONValue(10.5 )));
891
+
892
+ assert (JSONValue(1 ) != JSONValue(true ));
893
+ assert (JSONValue.emptyArray != JSONValue.emptyObject);
894
+
895
+ assert (parseJSON(` {"a": 1, "b": 2}` ).opEquals (parseJSON(` {"b": 2, "a": 1}` )));
877
896
}
878
897
879
898
// / Implements the foreach `opApply` interface for json arrays.
0 commit comments