@@ -1025,3 +1025,36 @@ func TestQuoMut(t *testing.T) {
1025
1025
})
1026
1026
}
1027
1027
}
1028
+
1029
+ func Test_DocumentLegacyAsymmetry (t * testing.T ) {
1030
+ zeroDec := math .LegacyZeroDec ()
1031
+ emptyDec := math.LegacyDec {}
1032
+
1033
+ zeroDecBz , err := zeroDec .Marshal ()
1034
+ require .NoError (t , err )
1035
+ zeroDecJSON := zeroDec .String ()
1036
+
1037
+ emptyDecBz , err := emptyDec .Marshal ()
1038
+ require .NoError (t , err )
1039
+ emptyDecJSON := emptyDec .String ()
1040
+
1041
+ // makes sense, zero and empty are semantically different and render differently
1042
+ require .NotEqual (t , zeroDecJSON , emptyDecJSON )
1043
+ // but on the proto wire they encode to the same bytes
1044
+ require .Equal (t , zeroDecBz , emptyDecBz )
1045
+
1046
+ // zero values are symmetrical
1047
+ zeroDecRoundTrip := math.LegacyDec {}
1048
+ err = zeroDecRoundTrip .Unmarshal (zeroDecBz )
1049
+ require .NoError (t , err )
1050
+ require .Equal (t , zeroDec .String (), zeroDecRoundTrip .String ())
1051
+ require .Equal (t , zeroDec , zeroDecRoundTrip )
1052
+
1053
+ // empty values are not
1054
+ emptyDecRoundTrip := math.LegacyDec {}
1055
+ err = emptyDecRoundTrip .Unmarshal (emptyDecBz )
1056
+ require .NoError (t , err )
1057
+ // !!! this is the key point, they are not equal, it looks like a bug
1058
+ require .NotEqual (t , emptyDec .String (), emptyDecRoundTrip .String ())
1059
+ require .NotEqual (t , emptyDec , emptyDecRoundTrip )
1060
+ }
0 commit comments