@@ -435,11 +435,11 @@ func TestEmptyKeyAndValue(t *testing.T) {
435
435
// ("quick keys") as well as long keys.
436
436
func TestSingleBucketMapStringKeys_DupLen (t * testing.T ) {
437
437
testMapLookups (t , map [string ]string {
438
- "x" : "x1val" ,
439
- "xx" : "x2val" ,
440
- "foo" : "fooval" ,
441
- "bar" : "barval" , // same key length as "foo"
442
- "xxxx" : "x4val" ,
438
+ "x" : "x1val" ,
439
+ "xx" : "x2val" ,
440
+ "foo" : "fooval" ,
441
+ "bar" : "barval" , // same key length as "foo"
442
+ "xxxx" : "x4val" ,
443
443
strings .Repeat ("x" , 128 ): "longval1" ,
444
444
strings .Repeat ("y" , 128 ): "longval2" ,
445
445
})
@@ -1045,3 +1045,89 @@ func TestDeferDeleteSlow(t *testing.T) {
1045
1045
t .Errorf ("want 0 elements, got %d" , len (m ))
1046
1046
}
1047
1047
}
1048
+
1049
+ // TestIncrementAfterDeleteValueInt and other test Issue 25936.
1050
+ // Value types int, int32, int64 are affected. Value type string
1051
+ // works as expected.
1052
+ func TestIncrementAfterDeleteValueInt (t * testing.T ) {
1053
+ const key1 = 12
1054
+ const key2 = 13
1055
+
1056
+ m := make (map [int ]int )
1057
+ m [key1 ] = 99
1058
+ delete (m , key1 )
1059
+ m [key2 ]++
1060
+ if n2 := m [key2 ]; n2 != 1 {
1061
+ t .Errorf ("incremented 0 to %d" , n2 )
1062
+ }
1063
+ }
1064
+
1065
+ func TestIncrementAfterDeleteValueInt32 (t * testing.T ) {
1066
+ const key1 = 12
1067
+ const key2 = 13
1068
+
1069
+ m := make (map [int ]int32 )
1070
+ m [key1 ] = 99
1071
+ delete (m , key1 )
1072
+ m [key2 ]++
1073
+ if n2 := m [key2 ]; n2 != 1 {
1074
+ t .Errorf ("incremented 0 to %d" , n2 )
1075
+ }
1076
+ }
1077
+
1078
+ func TestIncrementAfterDeleteValueInt64 (t * testing.T ) {
1079
+ const key1 = 12
1080
+ const key2 = 13
1081
+
1082
+ m := make (map [int ]int64 )
1083
+ m [key1 ] = 99
1084
+ delete (m , key1 )
1085
+ m [key2 ]++
1086
+ if n2 := m [key2 ]; n2 != 1 {
1087
+ t .Errorf ("incremented 0 to %d" , n2 )
1088
+ }
1089
+ }
1090
+
1091
+ func TestIncrementAfterDeleteKeyStringValueInt (t * testing.T ) {
1092
+ const key1 = ""
1093
+ const key2 = "x"
1094
+
1095
+ m := make (map [string ]int )
1096
+ m [key1 ] = 99
1097
+ delete (m , key1 )
1098
+ m [key2 ] += 1
1099
+ if n2 := m [key2 ]; n2 != 1 {
1100
+ t .Errorf ("incremented 0 to %d" , n2 )
1101
+ }
1102
+ }
1103
+
1104
+ func TestIncrementAfterDeleteKeyValueString (t * testing.T ) {
1105
+ const key1 = ""
1106
+ const key2 = "x"
1107
+
1108
+ m := make (map [string ]string )
1109
+ m [key1 ] = "99"
1110
+ delete (m , key1 )
1111
+ m [key2 ] += "1"
1112
+ if n2 := m [key2 ]; n2 != "1" {
1113
+ t .Errorf ("appended '1' to empty (nil) string, got %s" , n2 )
1114
+ }
1115
+ }
1116
+
1117
+ // TestIncrementAfterBulkClearKeyStringValueInt tests that map bulk
1118
+ // deletion (mapclear) still works as expected. Note that it was not
1119
+ // affected by Issue 25936.
1120
+ func TestIncrementAfterBulkClearKeyStringValueInt (t * testing.T ) {
1121
+ const key1 = ""
1122
+ const key2 = "x"
1123
+
1124
+ m := make (map [string ]int )
1125
+ m [key1 ] = 99
1126
+ for k := range m {
1127
+ delete (m , k )
1128
+ }
1129
+ m [key2 ]++
1130
+ if n2 := m [key2 ]; n2 != 1 {
1131
+ t .Errorf ("incremented 0 to %d" , n2 )
1132
+ }
1133
+ }
0 commit comments