How to use Ptr method of td Package

Best Go-testdeep code snippet using td.Ptr

update_test.go

Source:update_test.go Github

copy

Full Screen

...75 mapVal := map[string]string{76 "key1": strVal1,77 "key2": strVal2,78 }79 mapPtrVal := map[string]*string{80 "key1": &strVal1,81 "key2": &strVal2,82 }83 mapMapVal := map[string]map[string]string{84 "key1": mapVal,85 "key2": mapVal,86 }87 mapPtrMapVal := map[string]*map[string]string{88 "key1": &mapVal,89 "key2": &mapVal,90 }91 sliceVal := []string{strVal1, strVal2}92 mapSliceVal := map[string][]string{93 "key1": sliceVal,94 "key2": sliceVal,95 }96 arrVal := [2]string{strVal1, strVal2}97 mapArrVal := map[string][2]string{98 "key1": arrVal,99 "key2": arrVal,100 }101 mapPtrSliceVal := map[string]*[]string{102 "key1": &sliceVal,103 "key2": &sliceVal,104 }105 td := &TypeDeep{}106 data, _ := json.Marshal(mapVal)107 err := UpdateJSON(td, []string{"mapVal"}, data, UpdateOp)108 if assert.NoError(t, err) {109 assert.EqualValues(t, mapVal, td.MapVal)110 }111 err = UpdateJSON(td, []string{"ptrMapVal"}, data, UpdateOp)112 if assert.NoError(t, err) {113 assert.EqualValues(t, &mapVal, td.PtrMapVal)114 }115 err = UpdateJSON(td, []string{"mapPtrVal"}, data, UpdateOp)116 if assert.NoError(t, err) {117 assert.EqualValues(t, mapPtrVal, td.MapPtrVal)118 }119 data, _ = json.Marshal(mapMapVal)120 err = UpdateJSON(td, []string{"mapMapVal"}, data, UpdateOp)121 if assert.NoError(t, err) {122 assert.EqualValues(t, mapMapVal, td.MapMapVal)123 }124 err = UpdateJSON(td, []string{"mapPtrMapVal"}, data, UpdateOp)125 if assert.NoError(t, err) {126 assert.EqualValues(t, mapPtrMapVal, td.MapPtrMapVal)127 }128 data, _ = json.Marshal(mapSliceVal)129 err = UpdateJSON(td, []string{"mapSliceVal"}, data, UpdateOp)130 if assert.NoError(t, err) {131 assert.EqualValues(t, mapSliceVal, td.MapSliceVal)132 }133 err = UpdateJSON(td, []string{"mapArrVal"}, data, UpdateOp)134 if assert.NoError(t, err) {135 assert.EqualValues(t, mapArrVal, td.MapArrVal)136 }137 data, _ = json.Marshal(mapPtrSliceVal)138 err = UpdateJSON(td, []string{"mapPtrSliceVal"}, data, UpdateOp)139 if assert.NoError(t, err) {140 assert.EqualValues(t, mapPtrSliceVal, td.MapPtrSliceVal)141 }142 // Second level.143 newMapVal := map[string]string{144 "key1": "newStrVal1",145 "key2": "newStrVal2",146 }147 data, _ = json.Marshal(newMapVal)148 err = UpdateJSON(td, []string{"mapMapVal", "key1"}, data, UpdateOp)149 if assert.NoError(t, err) {150 assert.EqualValues(t, newMapVal, td.MapMapVal["key1"])151 }152 err = UpdateJSON(td, []string{"mapPtrMapVal", "key1"}, data, UpdateOp)153 if assert.NoError(t, err) {154 assert.EqualValues(t, &newMapVal, td.MapPtrMapVal["key1"])155 }156}157func TestUpdateSlice(t *testing.T) {158 strVal0 := "strVal0"159 strVal1 := "strVal1"160 strVal2 := "strVal2"161 sliceVal0 := []string{strVal0}162 sliceVal := []string{strVal1, strVal2}163 arrVal := [2]string{strVal1, strVal2}164 slicePtrVal := []*string{&strVal1, &strVal2}165 mapVal := map[string]string{166 "key1": strVal1,167 "key2": strVal2,168 }169 mapSliceVal := map[string][]string{"key1": sliceVal0}170 mapPtrSliceVal := map[string]*[]string{"key1": &sliceVal0}171 sliceMapVal := []map[string]string{mapVal, mapVal}172 slicePtrMapVal := []*map[string]string{&mapVal, &mapVal}173 sliceSliceVal := [][]string{sliceVal, sliceVal}174 slicePtrSliceVal := []*[]string{&sliceVal, &sliceVal}175 td := &TypeDeep{176 MapSliceVal: mapSliceVal,177 MapPtrSliceVal: mapPtrSliceVal,178 }179 data, _ := json.Marshal(arrVal)180 err := UpdateJSON(td, []string{"arrVal"}, data, UpdateOp)181 if assert.NoError(t, err) {182 assert.EqualValues(t, arrVal, td.ArrVal)183 }184 data, _ = json.Marshal(sliceVal)185 err = UpdateJSON(td, []string{"sliceVal"}, data, UpdateOp)186 if assert.NoError(t, err) {187 assert.EqualValues(t, sliceVal, td.SliceVal)188 }189 err = UpdateJSON(td, []string{"slicePtrVal"}, data, UpdateOp)190 if assert.NoError(t, err) {191 assert.EqualValues(t, slicePtrVal, td.SlicePtrVal)192 }193 err = UpdateJSON(td, []string{"mapSliceVal", "key1"}, data, UpdateOp)194 if assert.NoError(t, err) {195 assert.EqualValues(t, sliceVal, td.MapSliceVal["key1"])196 }197 err = UpdateJSON(td, []string{"mapPtrSliceVal", "key1"}, data, UpdateOp)198 if assert.NoError(t, err) {199 assert.EqualValues(t, &sliceVal, td.MapPtrSliceVal["key1"])200 }201 data, _ = json.Marshal(sliceMapVal)202 err = UpdateJSON(td, []string{"sliceMapVal"}, data, UpdateOp)203 if assert.NoError(t, err) {204 assert.EqualValues(t, sliceMapVal, td.SliceMapVal)205 }206 err = UpdateJSON(td, []string{"slicePtrMapVal"}, data, UpdateOp)207 if assert.NoError(t, err) {208 assert.EqualValues(t, slicePtrMapVal, td.SlicePtrMapVal)209 }210 data, _ = json.Marshal(sliceSliceVal)211 err = UpdateJSON(td, []string{"sliceSliceVal"}, data, UpdateOp)212 if assert.NoError(t, err) {213 assert.EqualValues(t, sliceSliceVal, td.SliceSliceVal)214 }215 err = UpdateJSON(td, []string{"slicePtrSliceVal"}, data, UpdateOp)216 if assert.NoError(t, err) {217 assert.EqualValues(t, slicePtrSliceVal, td.SlicePtrSliceVal)218 }219}220func TestUpdateIntf(t *testing.T) {221 strVal := "strVal1"222 intVal := 5.0223 arrIntfVal := [2]interface{}{strVal, intVal}224 sliceIntfVal := []interface{}{intVal, strVal}225 mapIntfVal := map[string]interface{}{226 "key1": strVal,227 "key2": intVal,228 }229 mapArrIntfVal := map[string][2]interface{}{230 "key1": arrIntfVal,231 "key2": arrIntfVal,232 }233 mapSliceIntfVal := map[string][]interface{}{234 "key1": sliceIntfVal,235 "key2": sliceIntfVal,236 }237 mapPtrSliceIntfVal := map[string]*[]interface{}{238 "key1": &sliceIntfVal,239 "key2": &sliceIntfVal,240 }241 mapMapIntfVal := map[string]map[string]interface{}{242 "key1": mapIntfVal,243 "key2": mapIntfVal,244 }245 mapPtrMapIntfVal := map[string]*map[string]interface{}{246 "key1": &mapIntfVal,247 "key2": &mapIntfVal,248 }249 td := &TypeDeep{}250 data, _ := json.Marshal(arrIntfVal)251 err := UpdateJSON(td, []string{"arrIntfVal"}, data, UpdateOp)252 if assert.NoError(t, err) {253 assert.EqualValues(t, arrIntfVal, td.ArrIntfVal)254 }255 data, _ = json.Marshal(sliceIntfVal)256 err = UpdateJSON(td, []string{"sliceIntfVal"}, data, UpdateOp)257 if assert.NoError(t, err) {258 assert.EqualValues(t, sliceIntfVal, td.SliceIntfVal)259 }260 data, _ = json.Marshal(mapIntfVal)261 err = UpdateJSON(td, []string{"mapIntfVal"}, data, UpdateOp)262 if assert.NoError(t, err) {263 assert.EqualValues(t, mapIntfVal, td.MapIntfVal)264 }265 data, _ = json.Marshal(mapArrIntfVal)266 err = UpdateJSON(td, []string{"mapArrIntfVal"}, data, UpdateOp)267 if assert.NoError(t, err) {268 assert.EqualValues(t, mapArrIntfVal, td.MapArrIntfVal)269 }270 data, _ = json.Marshal(mapSliceIntfVal)271 err = UpdateJSON(td, []string{"mapSliceIntfVal"}, data, UpdateOp)272 if assert.NoError(t, err) {273 assert.EqualValues(t, mapSliceIntfVal, td.MapSliceIntfVal)274 }275 data, _ = json.Marshal(mapPtrSliceIntfVal)276 err = UpdateJSON(td, []string{"mapPtrSliceIntfVal"}, data, UpdateOp)277 if assert.NoError(t, err) {278 assert.EqualValues(t, mapPtrSliceIntfVal, td.MapPtrSliceIntfVal)279 }280 data, _ = json.Marshal(mapMapIntfVal)281 err = UpdateJSON(td, []string{"mapMapIntfVal"}, data, UpdateOp)282 if assert.NoError(t, err) {283 assert.EqualValues(t, mapMapIntfVal, td.MapMapIntfVal)284 }285 data, _ = json.Marshal(mapPtrMapIntfVal)286 err = UpdateJSON(td, []string{"mapPtrMapIntfVal"}, data, UpdateOp)287 if assert.NoError(t, err) {288 assert.EqualValues(t, mapPtrMapIntfVal, td.MapPtrMapIntfVal)289 }290 // Second level.291 newSliceIntfVal := []interface{}{6.0, 7.0, "newStrVal"}292 data, _ = json.Marshal(newSliceIntfVal)293 err = UpdateJSON(td, []string{"mapSliceIntfVal", "key1"}, data, UpdateOp)294 if assert.NoError(t, err) {295 assert.EqualValues(t, newSliceIntfVal, td.MapSliceIntfVal["key1"])296 }297 err = UpdateJSON(td, []string{"mapPtrSliceIntfVal", "key1"}, data, UpdateOp)298 if assert.NoError(t, err) {299 assert.EqualValues(t, &newSliceIntfVal, td.MapPtrSliceIntfVal["key1"])300 }301 newMapIntfVal := map[string]interface{}{302 "key3": 6.0,303 "key4": 7.0,304 "key5": "newStrVal",305 }306 data, _ = json.Marshal(newMapIntfVal)307 err = UpdateJSON(td, []string{"mapMapIntfVal", "key1"}, data, UpdateOp)308 if assert.NoError(t, err) {309 assert.EqualValues(t, newMapIntfVal, td.MapMapIntfVal["key1"])310 }311 err = UpdateJSON(td, []string{"mapPtrMapIntfVal", "key1"}, data, UpdateOp)312 if assert.NoError(t, err) {313 assert.EqualValues(t, &newMapIntfVal, td.MapPtrMapIntfVal["key1"])314 }315}316func TestUpdateDeep(t *testing.T) {317 strVal1 := "strVal1"318 strVal2 := "strVal2"319 intVal := 5320 mapVal := map[string]string{321 "key1": strVal1,322 "key2": strVal2,323 }324 td1 := TypeDeep{325 StrVal: strVal1,326 IntVal: intVal,327 MapVal: mapVal,328 PtrMapVal: &mapVal,329 }330 sliceDeep := []TypeDeep{td1, td1}331 arrDeep := [2]TypeDeep{td1, td1}332 slicePtrDeep := []*TypeDeep{&td1, &td1}333 arrPtrDeep := [2]*TypeDeep{&td1, &td1}334 mapDeep := map[string]TypeDeep{335 "key1": td1,336 "key2": td1,337 }338 mapPtrDeep := map[string]*TypeDeep{339 "key1": &td1,340 "key2": &td1,341 }342 mapArrDeep := map[string][2]TypeDeep{343 "key1": arrDeep,344 "key2": arrDeep,345 }346 mapSlicePtrDeep := map[string][]*TypeDeep{347 "key1": slicePtrDeep,348 "key2": slicePtrDeep,349 }350 mapMapDeep := map[string]map[string]TypeDeep{351 "key1": mapDeep,352 "key2": mapDeep,353 }354 mapPtrMapDeep := map[string]*map[string]TypeDeep{355 "key1": &mapDeep,356 "key2": &mapDeep,357 }358 mapMapPtrDeep := map[string]map[string]*TypeDeep{359 "key1": mapPtrDeep,360 "key2": mapPtrDeep,361 }362 td := &TypeDeep{363 PtrDeep: &td1,364 SliceDeep: sliceDeep,365 SlicePtrDeep: slicePtrDeep,366 ArrPtrDeep: arrPtrDeep,367 MapDeep: mapDeep,368 MapPtrDeep: mapPtrDeep,369 MapArrDeep: mapArrDeep,370 MapSlicePtrDeep: mapSlicePtrDeep,371 MapMapDeep: mapMapDeep,372 MapPtrMapDeep: mapPtrMapDeep,373 MapMapPtrDeep: mapMapPtrDeep,374 }375 // One level376 td1.StrVal = "strNew"377 data, _ := json.Marshal(td1)378 err := UpdateJSON(td, []string{"ptrDeep"}, data, UpdateOp)379 if assert.NoError(t, err) {380 assert.EqualValues(t, &td1, td.PtrDeep)381 }382 // Two levels383 sliceDeep = []TypeDeep{td1, td1}384 data, _ = json.Marshal(sliceDeep)385 err = UpdateJSON(td, []string{"ptrDeep", "sliceDeep"}, data, UpdateOp)386 if assert.NoError(t, err) {387 assert.EqualValues(t, sliceDeep, td.PtrDeep.SliceDeep)388 }389 slicePtrDeep = []*TypeDeep{&td1, &td1}390 data, _ = json.Marshal(slicePtrDeep)391 err = UpdateJSON(td, []string{"ptrDeep", "slicePtrDeep"}, data, UpdateOp)392 if assert.NoError(t, err) {393 assert.EqualValues(t, slicePtrDeep, td.PtrDeep.SlicePtrDeep)394 }395 arrPtrDeep = [2]*TypeDeep{&td1, &td1}396 data, _ = json.Marshal(arrPtrDeep)397 err = UpdateJSON(td, []string{"ptrDeep", "arrPtrDeep"}, data, UpdateOp)398 if assert.NoError(t, err) {399 assert.EqualValues(t, arrPtrDeep, td.PtrDeep.ArrPtrDeep)400 }401 mapDeep = map[string]TypeDeep{402 "key3": td1,403 "key4": td1,404 }405 data, _ = json.Marshal(mapDeep)406 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep"}, data, UpdateOp)407 if assert.NoError(t, err) {408 assert.EqualValues(t, mapDeep, td.PtrDeep.MapDeep)409 }410 mapPtrDeep = map[string]*TypeDeep{411 "key3": &td1,412 "key4": &td1,413 }414 data, _ = json.Marshal(mapPtrDeep)415 err = UpdateJSON(td, []string{"ptrDeep", "mapPtrDeep"}, data, UpdateOp)416 if assert.NoError(t, err) {417 assert.EqualValues(t, mapPtrDeep, td.PtrDeep.MapPtrDeep)418 }419 mapArrDeep = map[string][2]TypeDeep{420 "key3": arrDeep,421 "key4": arrDeep,422 }423 data, _ = json.Marshal(mapArrDeep)424 err = UpdateJSON(td, []string{"ptrDeep", "mapArrDeep"}, data, UpdateOp)425 if assert.NoError(t, err) {426 assert.EqualValues(t, mapArrDeep, td.PtrDeep.MapArrDeep)427 }428 mapSlicePtrDeep = map[string][]*TypeDeep{429 "key3": slicePtrDeep,430 "key4": slicePtrDeep,431 }432 data, _ = json.Marshal(mapSlicePtrDeep)433 err = UpdateJSON(td, []string{"ptrDeep", "mapSlicePtrDeep"}, data, UpdateOp)434 if assert.NoError(t, err) {435 assert.EqualValues(t, mapSlicePtrDeep, td.PtrDeep.MapSlicePtrDeep)436 }437 mapMapDeep = map[string]map[string]TypeDeep{438 "key3": mapDeep,439 "key4": mapDeep,440 }441 data, _ = json.Marshal(mapMapDeep)442 err = UpdateJSON(td, []string{"ptrDeep", "mapMapDeep"}, data, UpdateOp)443 if assert.NoError(t, err) {444 assert.EqualValues(t, mapMapDeep, td.PtrDeep.MapMapDeep)445 }446 mapPtrMapDeep = map[string]*map[string]TypeDeep{447 "key3": &mapDeep,448 "key4": &mapDeep,449 }450 data, _ = json.Marshal(mapPtrMapDeep)451 err = UpdateJSON(td, []string{"ptrDeep", "mapPtrMapDeep"}, data, UpdateOp)452 if assert.NoError(t, err) {453 assert.EqualValues(t, mapPtrMapDeep, td.PtrDeep.MapPtrMapDeep)454 }455 mapMapPtrDeep = map[string]map[string]*TypeDeep{456 "key3": mapPtrDeep,457 "key4": mapPtrDeep,458 }459 data, _ = json.Marshal(mapMapPtrDeep)460 err = UpdateJSON(td, []string{"ptrDeep", "mapMapPtrDeep"}, data, UpdateOp)461 if assert.NoError(t, err) {462 assert.EqualValues(t, mapMapPtrDeep, td.PtrDeep.MapMapPtrDeep)463 }464 // Three levels465 td1.StrVal = "strNewNew"466 data, _ = json.Marshal(td1)467 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3"}, data, UpdateOp)468 if assert.NoError(t, err) {469 assert.EqualValues(t, td1, td.PtrDeep.MapDeep["key3"])470 }471 err = UpdateJSON(td, []string{"ptrDeep", "mapPtrDeep", "key3"}, data, UpdateOp)472 if assert.NoError(t, err) {473 assert.EqualValues(t, &td1, td.PtrDeep.MapPtrDeep["key3"])474 }475 arrDeep = [2]TypeDeep{td1, td1}476 data, _ = json.Marshal(arrDeep)477 err = UpdateJSON(td, []string{"ptrDeep", "mapArrDeep", "key3"}, data, UpdateOp)478 if assert.NoError(t, err) {479 assert.EqualValues(t, arrDeep, td.PtrDeep.MapArrDeep["key3"])480 }481 slicePtrDeep = []*TypeDeep{&td1, &td1}482 data, _ = json.Marshal(slicePtrDeep)483 err = UpdateJSON(td, []string{"ptrDeep", "mapSlicePtrDeep", "key3"}, data, UpdateOp)484 if assert.NoError(t, err) {485 assert.EqualValues(t, slicePtrDeep, td.PtrDeep.MapSlicePtrDeep["key3"])486 }487 mapDeep = map[string]TypeDeep{488 "key3": td1,489 "key4": td1,490 }491 data, _ = json.Marshal(mapDeep)492 err = UpdateJSON(td, []string{"ptrDeep", "mapMapDeep", "key3"}, data, UpdateOp)493 if assert.NoError(t, err) {494 assert.EqualValues(t, mapDeep, td.PtrDeep.MapMapDeep["key3"])495 }496 err = UpdateJSON(td, []string{"ptrDeep", "mapPtrMapDeep", "key3"}, data, UpdateOp)497 if assert.NoError(t, err) {498 assert.EqualValues(t, &mapDeep, td.PtrDeep.MapPtrMapDeep["key3"])499 }500 mapPtrDeep = map[string]*TypeDeep{501 "key3": &td1,502 "key4": &td1,503 }504 err = UpdateJSON(td, []string{"ptrDeep", "mapMapPtrDeep", "key3"}, data, UpdateOp)505 if assert.NoError(t, err) {506 assert.EqualValues(t, mapPtrDeep, td.PtrDeep.MapMapPtrDeep["key3"])507 }508 // Four levels509 td1.StrVal = "strNewNewNew"510 data, _ = json.Marshal(td1)511 err = UpdateJSON(td, []string{"ptrDeep", "sliceDeep", "0", "ptrDeep"}, data, UpdateOp)512 if assert.NoError(t, err) {513 assert.EqualValues(t, &td1, td.PtrDeep.SliceDeep[0].PtrDeep)514 }515 err = UpdateJSON(td, []string{"ptrDeep", "slicePtrDeep", "0", "ptrDeep"}, data, UpdateOp)516 if assert.NoError(t, err) {517 assert.EqualValues(t, &td1, td.PtrDeep.SlicePtrDeep[0].PtrDeep)518 }519 err = UpdateJSON(td, []string{"ptrDeep", "arrPtrDeep", "0", "ptrDeep"}, data, UpdateOp)520 if assert.NoError(t, err) {521 assert.EqualValues(t, &td1, td.PtrDeep.ArrPtrDeep[0].PtrDeep)522 }523 data, _ = json.Marshal(td1)524 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "ptrDeep"}, data, UpdateOp)525 if assert.NoError(t, err) {526 assert.EqualValues(t, &td1, td.PtrDeep.MapDeep["key3"].PtrDeep)527 }528 err = UpdateJSON(td, []string{"ptrDeep", "mapPtrDeep", "key3", "ptrDeep"}, data, UpdateOp)529 if assert.NoError(t, err) {530 assert.EqualValues(t, &td1, td.PtrDeep.MapPtrDeep["key3"].PtrDeep)531 }532 sliceDeep = []TypeDeep{td1, td1}533 data, _ = json.Marshal(sliceDeep)534 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "sliceDeep"}, data, UpdateOp)535 if assert.NoError(t, err) {536 assert.EqualValues(t, sliceDeep, td.PtrDeep.MapDeep["key3"].SliceDeep)537 }538 slicePtrDeep = []*TypeDeep{&td1, &td1}539 data, _ = json.Marshal(slicePtrDeep)540 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "slicePtrDeep"}, data, UpdateOp)541 if assert.NoError(t, err) {542 assert.EqualValues(t, slicePtrDeep, td.PtrDeep.MapDeep["key3"].SlicePtrDeep)543 }544 arrPtrDeep = [2]*TypeDeep{&td1, &td1}545 data, _ = json.Marshal(arrPtrDeep)546 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "arrPtrDeep"}, data, UpdateOp)547 if assert.NoError(t, err) {548 assert.EqualValues(t, arrPtrDeep, td.PtrDeep.MapDeep["key3"].ArrPtrDeep)549 }550 mapDeep = map[string]TypeDeep{551 "key5": td1,552 "key6": td1,553 }554 data, _ = json.Marshal(mapDeep)555 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "mapDeep"}, data, UpdateOp)556 if assert.NoError(t, err) {557 assert.EqualValues(t, mapDeep, td.PtrDeep.MapDeep["key3"].MapDeep)558 }559 mapPtrDeep = map[string]*TypeDeep{560 "key3": &td1,561 "key4": &td1,562 }563 data, _ = json.Marshal(mapPtrDeep)564 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "mapPtrDeep"}, data, UpdateOp)565 if assert.NoError(t, err) {566 assert.EqualValues(t, mapPtrDeep, td.PtrDeep.MapDeep["key3"].MapPtrDeep)567 }568 arrDeep = [2]TypeDeep{td1, td1}569 mapArrDeep = map[string][2]TypeDeep{570 "key3": arrDeep,571 "key4": arrDeep,572 }573 data, _ = json.Marshal(mapArrDeep)574 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "mapArrDeep"}, data, UpdateOp)575 if assert.NoError(t, err) {576 assert.EqualValues(t, mapArrDeep, td.PtrDeep.MapDeep["key3"].MapArrDeep)577 }578 slicePtrDeep = []*TypeDeep{&td1, &td1}579 data, _ = json.Marshal(slicePtrDeep)580 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "slicePtrDeep"}, data, UpdateOp)581 if assert.NoError(t, err) {582 assert.EqualValues(t, slicePtrDeep, td.PtrDeep.MapDeep["key3"].SlicePtrDeep)583 }584 mapMapDeep = map[string]map[string]TypeDeep{585 "key3": mapDeep,586 "key4": mapDeep,587 }588 data, _ = json.Marshal(mapMapDeep)589 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "mapMapDeep"}, data, UpdateOp)590 if assert.NoError(t, err) {591 assert.EqualValues(t, mapMapDeep, td.PtrDeep.MapDeep["key3"].MapMapDeep)592 }593 mapPtrMapDeep = map[string]*map[string]TypeDeep{594 "key3": &mapDeep,595 "key4": &mapDeep,596 }597 data, _ = json.Marshal(mapPtrMapDeep)598 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "mapPtrMapDeep"}, data, UpdateOp)599 if assert.NoError(t, err) {600 assert.EqualValues(t, mapPtrMapDeep, td.PtrDeep.MapDeep["key3"].MapPtrMapDeep)601 }602 mapMapPtrDeep = map[string]map[string]*TypeDeep{603 "key3": mapPtrDeep,604 "key4": mapPtrDeep,605 }606 data, _ = json.Marshal(mapMapPtrDeep)607 err = UpdateJSON(td, []string{"ptrDeep", "mapDeep", "key3", "mapMapPtrDeep"}, data, UpdateOp)608 if assert.NoError(t, err) {609 assert.EqualValues(t, mapMapPtrDeep, td.PtrDeep.MapDeep["key3"].MapMapPtrDeep)610 }611 // Five levels612 td1.StrVal = "strNewNewNewNew"613 data, _ = json.Marshal(td1)614 err = UpdateJSON(td, []string{"ptrDeep", "sliceDeep", "0", "ptrDeep", "ptrDeep"}, data, UpdateOp)615 if assert.NoError(t, err) {616 assert.EqualValues(t, &td1, td.PtrDeep.SliceDeep[0].PtrDeep.PtrDeep)617 }618 err = UpdateJSON(td, []string{"ptrDeep", "mapArrDeep", "key3", "0", "ptrDeep"}, data, UpdateOp)619 if assert.NoError(t, err) {620 assert.EqualValues(t, &td1, td.PtrDeep.MapArrDeep["key3"][0].PtrDeep)621 }622 err = UpdateJSON(td, []string{"ptrDeep", "mapSlicePtrDeep", "key3", "0", "ptrDeep"}, data, UpdateOp)623 if assert.NoError(t, err) {624 assert.EqualValues(t, &td1, td.PtrDeep.MapSlicePtrDeep["key3"][0].PtrDeep)625 }626 err = UpdateJSON(td, []string{"ptrDeep", "mapMapDeep", "key3", "key4", "ptrDeep"}, data, UpdateOp)627 if assert.NoError(t, err) {628 assert.EqualValues(t, &td1, td.PtrDeep.MapMapDeep["key3"]["key4"].PtrDeep)629 }630 err = UpdateJSON(td, []string{"ptrDeep", "mapMapPtrDeep", "key3", "key4", "ptrDeep"}, data, UpdateOp)631 if assert.NoError(t, err) {632 assert.EqualValues(t, &td1, td.PtrDeep.MapMapPtrDeep["key3"]["key4"].PtrDeep)633 }634}635func TestUpdateFails(t *testing.T) {636 strVal1 := "strVal1"637 strVal2 := "strVal2"638 mapVal := map[string]string{639 "key1": strVal1,640 "key2": strVal2,641 }642 td := &TypeDeep{}643 err := UpdateJSON(td, []string{"bogus"}, nil, UpdateOp)644 if assert.Error(t, err) {645 assert.IsType(t, &KeyNotFoundError{}, err)646 }647 err = UpdateJSON(td, []string{"strVal", "bogus"}, nil, UpdateOp)648 if assert.Error(t, err) {649 assert.IsType(t, &KeyNotTraversableError{}, err)650 }651 err = UpdateJSON(td, []string{"strVal"}, json.RawMessage("strVal"), UpdateOp)652 if assert.Error(t, err) {653 assert.IsType(t, &json.SyntaxError{}, err) // TODO654 }655 err = UpdateJSON(td, []string{"sliceVal", "x"}, nil, UpdateOp)656 if assert.Error(t, err) {657 assert.IsType(t, &KeyNotFoundError{}, err)658 }659 err = UpdateJSON(td, []string{"sliceVal", "10"}, nil, UpdateOp)660 if assert.Error(t, err) {661 assert.IsType(t, &KeyNotFoundError{}, err)662 }663 // TODO: update on empty map to result in KeyNotFoundError? Currently works as Create.664 //data, _ := json.Marshal(mapVal)665 //err = UpdateJSON(td, []string{"mapVal"}, data, UpdateOp)666 //if assert.Error(t, err) {667 // assert.IsType(t, &KeyNotFoundError{}, err)668 //}669 err = UpdateJSON(td, []string{"mapVal", "bogus"}, nil, UpdateOp)670 if assert.Error(t, err) {671 assert.IsType(t, &KeyNotFoundError{}, err)672 }673 td.MapVal = mapVal674 err = UpdateJSON(td, []string{"mapVal", "key1"}, json.RawMessage("bogus"), UpdateOp)675 if assert.Error(t, err) {676 assert.IsType(t, &json.SyntaxError{}, err)677 }678}679func TestCreateFails(t *testing.T) {680 strVal0 := "strVal0"681 strVal1 := "strVal1"682 strVal2 := "strVal2"683 sliceVal0 := []string{strVal0}684 sliceSliceVal0 := [][]string{sliceVal0}685 mapVal0 := map[string]string{686 "key1": strVal1,687 "key2": strVal2,688 }689 sliceMapVal0 := []map[string]string{mapVal0}690 mapSliceVal0 := map[string][]string{"key1": sliceVal0}691 mapMapVal0 := map[string]map[string]string{692 "key0": mapVal0,693 }694 td := &TypeDeep{695 SliceSliceVal: sliceSliceVal0,696 SliceMapVal: sliceMapVal0,697 MapSliceVal: mapSliceVal0,698 MapMapVal: mapMapVal0,699 }700 err := UpdateJSON(td, []string{"bogus"}, nil, CreateOp)701 if assert.Error(t, err) {702 assert.IsType(t, &KeyNotFoundError{}, err)703 }704 err = UpdateJSON(td, []string{"strVal"}, nil, CreateOp)705 if assert.Error(t, err) {706 assert.IsType(t, &KeyExistsError{}, err)707 }708 err = UpdateJSON(td, []string{"strVal", "bogus"}, nil, CreateOp)709 if assert.Error(t, err) {710 assert.IsType(t, &KeyNotTraversableError{}, err)711 }712 err = UpdateJSON(td, []string{"mapVal", "new"}, json.RawMessage("bogus"), CreateOp)713 if assert.Error(t, err) {714 assert.IsType(t, &json.SyntaxError{}, err)715 }716 err = UpdateJSON(td, []string{"sliceVal", "x"}, nil, CreateOp)717 if assert.Error(t, err) {718 assert.IsType(t, &KeyNotFoundError{}, err)719 }720 data, _ := json.Marshal([]int{5, 6})721 err = UpdateJSON(td, []string{"sliceVal"}, data, CreateOp)722 if assert.Error(t, err) {723 assert.IsType(t, &json.UnmarshalTypeError{}, err)724 }725 err = UpdateJSON(td, []string{"sliceSliceVal", "0"}, data, CreateOp)726 if assert.Error(t, err) {727 assert.IsType(t, &json.UnmarshalTypeError{}, err)728 }729 err = UpdateJSON(td, []string{"sliceMapVal", "0"}, data, CreateOp)730 if assert.Error(t, err) {731 assert.IsType(t, &OperationForbiddenError{}, err)732 }733 err = UpdateJSON(td, []string{"mapSliceVal", "key1"}, data, CreateOp)734 if assert.Error(t, err) {735 assert.IsType(t, &json.UnmarshalTypeError{}, err)736 }737 err = UpdateJSON(td, []string{"mapMapVal", "key0"}, data, CreateOp)738 if assert.Error(t, err) {739 assert.IsType(t, &KeyExistsError{}, err)740 }741}742func TestCreateSuccessful(t *testing.T) {743 strVal0 := "strVal0"744 strVal1 := "strVal1"745 strVal2 := "strVal2"746 mapVal := map[string]string{747 "key1": strVal1,748 "key2": strVal2,749 }750 sliceVal0 := []string{strVal0}751 sliceVal := []string{strVal1, strVal2}752 slicePtrVal0 := []*string{&strVal0}753 slicePtrVal := []*string{&strVal1, &strVal2}754 arrVal := [2]string{strVal1, strVal2}755 sliceMapVal0 := []map[string]string{mapVal}756 sliceMapVal := []map[string]string{mapVal, mapVal}757 slicePtrMapVal0 := []*map[string]string{&mapVal}758 slicePtrMapVal := []*map[string]string{&mapVal, &mapVal}759 sliceSliceVal0 := [][]string{sliceVal0}760 sliceSliceVal := [][]string{sliceVal, sliceVal}761 slicePtrSliceVal0 := []*[]string{&sliceVal}762 slicePtrSliceVal := []*[]string{&sliceVal, &sliceVal}763 sliceIntfVal0 := []interface{}{strVal0, 1}764 sliceIntfVal := []interface{}{strVal1, 5.5}765 var intfVal interface{} = sliceIntfVal766 mapSliceVal0 := map[string][]string{"key1": sliceVal0}767 mapPtrSliceVal0 := map[string]*[]string{"key1": &sliceVal0}768 td := &TypeDeep{769 SliceVal: sliceVal0,770 SlicePtrVal: slicePtrVal0,771 SliceMapVal: sliceMapVal0,772 SlicePtrMapVal: slicePtrMapVal0,773 SliceSliceVal: sliceSliceVal0,774 SlicePtrSliceVal: slicePtrSliceVal0,775 SliceIntfVal: sliceIntfVal0,776 MapSliceVal: mapSliceVal0,777 MapPtrSliceVal: mapPtrSliceVal0,778 }779 // One level.780 data, _ := json.Marshal(sliceVal)781 err := UpdateJSON(td, []string{"sliceVal"}, data, CreateOp)782 if assert.NoError(t, err) {783 assert.EqualValues(t, append(sliceVal0, sliceVal...), td.SliceVal)784 }785 err = UpdateJSON(td, []string{"slicePtrVal"}, data, CreateOp)786 if assert.NoError(t, err) {787 assert.EqualValues(t, append(slicePtrVal0, slicePtrVal...), td.SlicePtrVal)788 }789 data, _ = json.Marshal(sliceMapVal)790 err = UpdateJSON(td, []string{"sliceMapVal"}, data, CreateOp)791 if assert.NoError(t, err) {792 assert.EqualValues(t, append(sliceMapVal0, sliceMapVal...), td.SliceMapVal)793 }794 err = UpdateJSON(td, []string{"slicePtrMapVal"}, data, CreateOp)795 if assert.NoError(t, err) {796 assert.EqualValues(t, append(slicePtrMapVal0, slicePtrMapVal...), td.SlicePtrMapVal)797 }798 data, _ = json.Marshal(sliceSliceVal)799 err = UpdateJSON(td, []string{"sliceSliceVal"}, data, CreateOp)800 if assert.NoError(t, err) {801 assert.EqualValues(t, append(sliceSliceVal0, sliceSliceVal...), td.SliceSliceVal)802 }803 err = UpdateJSON(td, []string{"slicePtrSliceVal"}, data, CreateOp)804 if assert.NoError(t, err) {805 assert.EqualValues(t, append(slicePtrSliceVal0, slicePtrSliceVal...), td.SlicePtrSliceVal)806 }807 data, _ = json.Marshal(sliceIntfVal)808 err = UpdateJSON(td, []string{"sliceIntfVal"}, data, CreateOp)809 if assert.NoError(t, err) {810 assert.EqualValues(t, append(sliceIntfVal0, sliceIntfVal...), td.SliceIntfVal)811 }812 // Two levels.813 data, _ = json.Marshal(sliceVal)814 err = UpdateJSON(td, []string{"sliceSliceVal", "0"}, data, CreateOp)815 if assert.NoError(t, err) {816 assert.EqualValues(t, append(sliceVal0, sliceVal...), td.SliceSliceVal[0])817 }818 /* TODO: handle pointers to slices.819 err = UpdateJSON(td, []string{"slicePtrSliceVal", "0"}, data, CreateOp)820 if assert.NoError(t, err) {821 assert.EqualValues(t, append(sliceVal0, sliceVal...), td.SlicePtrSliceVal[0])822 }823 */824 data, _ = json.Marshal(mapVal)825 err = UpdateJSON(td, []string{"mapMapVal", "new"}, data, CreateOp)826 if assert.NoError(t, err) {827 assert.EqualValues(t, mapVal, td.MapMapVal["new"])828 }829 err = UpdateJSON(td, []string{"mapPtrMapVal", "new"}, data, CreateOp)830 if assert.NoError(t, err) {831 assert.EqualValues(t, &mapVal, td.MapPtrMapVal["new"])832 }833 data, _ = json.Marshal(sliceVal)834 err = UpdateJSON(td, []string{"mapSliceVal", "key1"}, data, CreateOp)835 if assert.NoError(t, err) {836 assert.EqualValues(t, append(sliceVal0, sliceVal...), td.MapSliceVal["key1"])837 }838 /* TODO: handle pointers to slices.839 err = UpdateJSON(td, []string{"mapPtrSliceVal", "key1"}, data, CreateOp)840 if assert.NoError(t, err) {841 assert.EqualValues(t, &sliceVal, td.MapPtrSliceVal["key1"])842 }843 */844 err = UpdateJSON(td, []string{"mapArrVal", "new"}, data, CreateOp)845 if assert.NoError(t, err) {846 assert.EqualValues(t, arrVal, td.MapArrVal["new"])847 }848 data, _ = json.Marshal(intfVal)849 err = UpdateJSON(td, []string{"mapIntfVal", "new"}, data, CreateOp)850 if assert.NoError(t, err) {851 assert.EqualValues(t, intfVal, td.MapIntfVal["new"])852 }853}854func TestSetSuccessful(t *testing.T) {855 strVal0 := "strVal0"856 strVal1 := "strVal1"857 strVal2 := "strVal2"858 mapVal0 := map[string]string{859 "key0": strVal0,860 }861 mapVal := map[string]string{862 "key1": strVal1,863 "key2": strVal2,864 }865 sliceMapVal0 := []map[string]string{mapVal0}866 mapMapVal0 := map[string]map[string]string{867 "key0": mapVal0,868 }869 td := &TypeDeep{870 MapVal: mapVal0,871 SliceMapVal: sliceMapVal0,872 MapMapVal: mapMapVal0,873 }874 data, _ := json.Marshal(mapVal)875 err := UpdateJSON(td, []string{"mapVal"}, data, SetOp)876 if assert.NoError(t, err) && assert.Equal(t, 3, len(td.MapVal)) {877 assert.Equal(t, mapVal0["key0"], td.MapVal["key0"])878 assert.Equal(t, mapVal["key1"], td.MapVal["key1"])879 assert.Equal(t, mapVal["key2"], td.MapVal["key2"])880 }881 err = UpdateJSON(td, []string{"sliceMapVal", "0"}, data, SetOp)882 if assert.NoError(t, err) && assert.Equal(t, 3, len(td.SliceMapVal[0])) {883 assert.Equal(t, mapVal0["key0"], td.SliceMapVal[0]["key0"])884 assert.Equal(t, mapVal["key1"], td.SliceMapVal[0]["key1"])885 assert.Equal(t, mapVal["key2"], td.SliceMapVal[0]["key2"])886 }887 err = UpdateJSON(td, []string{"mapMapVal", "key0"}, data, SetOp)888 if assert.NoError(t, err) && assert.Equal(t, 3, len(td.MapMapVal["key0"])) {889 assert.Equal(t, mapVal0["key0"], td.MapMapVal["key0"]["key0"])890 assert.Equal(t, mapVal["key1"], td.MapMapVal["key0"]["key1"])891 assert.Equal(t, mapVal["key2"], td.MapMapVal["key0"]["key2"])892 }893}894func TestSetFails(t *testing.T) {895 strVal1 := "strVal1"896 strVal2 := "strVal2"897 mapVal := map[string]string{898 "key1": strVal1,899 "key2": strVal2,900 }901 sliceMapVal0 := []map[string]string{mapVal}902 mapMapVal0 := map[string]map[string]string{903 "key0": mapVal,904 }905 td := &TypeDeep{906 MapVal: mapVal,907 SliceMapVal: sliceMapVal0,908 MapMapVal: mapMapVal0,909 }910 data, _ := json.Marshal([]int{5, 6})911 err := UpdateJSON(td, []string{"mapVal"}, data, SetOp)912 if assert.Error(t, err) {913 assert.IsType(t, &json.UnmarshalTypeError{}, err)914 }915 err = UpdateJSON(td, []string{"sliceMapVal", "0"}, data, SetOp)916 if assert.Error(t, err) {917 assert.IsType(t, &json.UnmarshalTypeError{}, err)918 }919 err = UpdateJSON(td, []string{"mapMapVal", "key0"}, data, SetOp)920 if assert.Error(t, err) {921 assert.IsType(t, &json.UnmarshalTypeError{}, err)922 }923}924func TestDeleteFails(t *testing.T) {925 strVal1 := "strVal1"926 strVal2 := "strVal2"927 intVal := 5928 mapVal := map[string]string{929 "key1": strVal1,930 "key2": strVal2,931 }932 sliceVal := []string{strVal1, strVal2}933 mapSliceIntfVal := map[string][]interface{}{934 "key1": []interface{}{strVal1, intVal},935 "key2": []interface{}{strVal2, intVal},936 }937 mapMapIntfVal := map[string]map[string]interface{}{938 "key1": map[string]interface{}{939 "key2": strVal1,940 "key3": sliceVal,941 },942 }943 td1 := TypeDeep{}944 mapDeep := map[string]TypeDeep{945 "key1": td1,946 "key2": td1,947 }948 td := &TypeDeep{949 StrVal: strVal1,950 IntVal: intVal,951 MapVal: mapVal,952 PtrMapVal: &mapVal,953 SliceVal: sliceVal,954 MapSliceIntfVal: mapSliceIntfVal,955 MapMapIntfVal: mapMapIntfVal,956 MapDeep: mapDeep,957 }958 err := UpdateJSON(td, []string{"bogus"}, nil, DeleteOp)959 if assert.Error(t, err) {960 assert.IsType(t, &KeyNotFoundError{}, err)961 }962 err = UpdateJSON(td, []string{"strVal"}, nil, DeleteOp)963 if assert.Error(t, err) {964 assert.IsType(t, &OperationForbiddenError{}, err)965 assert.EqualError(t, err, "forbidden operation Delete on key strVal of type optikon.TypeDeep")966 assert.Equal(t, "strVal", err.(*OperationForbiddenError).Key())967 assert.Equal(t, "optikon.TypeDeep", err.(*OperationForbiddenError).KeyType().String())968 assert.Equal(t, DeleteOp, err.(*OperationForbiddenError).Operation())969 }970 err = UpdateJSON(td, []string{"strVal", "bogus"}, nil, DeleteOp)971 if assert.Error(t, err) {972 assert.IsType(t, &KeyNotTraversableError{}, err)973 }974 err = UpdateJSON(td, []string{"sliceVal"}, nil, DeleteOp)975 if assert.Error(t, err) {976 assert.IsType(t, &OperationForbiddenError{}, err)977 }978 err = UpdateJSON(td, []string{"sliceVal", "x"}, nil, DeleteOp)979 if assert.Error(t, err) {980 assert.IsType(t, &KeyNotFoundError{}, err)981 }982 err = UpdateJSON(td, []string{"sliceVal", "10"}, nil, DeleteOp)983 if assert.Error(t, err) {984 assert.IsType(t, &KeyNotFoundError{}, err)985 }986 err = UpdateJSON(td, []string{"sliceVal", "0"}, nil, DeleteOp)987 if assert.Error(t, err) {988 assert.IsType(t, &OperationForbiddenError{}, err)989 }990 err = UpdateJSON(td, []string{"mapVal", "bogus"}, nil, DeleteOp)991 if assert.Error(t, err) {992 assert.IsType(t, &KeyNotFoundError{}, err)993 }994 err = UpdateJSON(td, []string{"ptrDeep"}, nil, DeleteOp)995 if assert.Error(t, err) {996 assert.IsType(t, &OperationForbiddenError{}, err)997 }998 err = UpdateJSON(td, []string{"mapDeep"}, nil, DeleteOp)999 if assert.Error(t, err) {1000 assert.IsType(t, &OperationForbiddenError{}, err)1001 }1002 err = UpdateJSON(td, []string{"mapDeep", "key1", "bogus"}, nil, DeleteOp)1003 if assert.Error(t, err) {1004 assert.IsType(t, &KeyNotFoundError{}, err)1005 }1006 err = UpdateJSON(td, []string{"mapDeep", "key1", "strVal"}, nil, DeleteOp)1007 if assert.Error(t, err) {1008 assert.IsType(t, &OperationForbiddenError{}, err)1009 }1010 err = UpdateJSON(td, []string{"mapDeep", "key1", "sliceVal"}, nil, DeleteOp)1011 if assert.Error(t, err) {1012 assert.IsType(t, &OperationForbiddenError{}, err)1013 }1014 err = UpdateJSON(td, []string{"mapDeep", "key1", "sliceVal", "0"}, nil, DeleteOp)1015 if assert.Error(t, err) {1016 assert.IsType(t, &KeyNotFoundError{}, err)1017 }1018 // TODO: IntfVal - check delete if actual data permits it?1019 err = UpdateJSON(td, []string{"mapSliceIntfVal", "key1", "0"}, nil, DeleteOp)1020 if assert.Error(t, err) {1021 assert.IsType(t, &OperationForbiddenError{}, err)1022 }1023 err = UpdateJSON(td, []string{"mapMapIntfVal", "key1", "key3", "0"}, nil, DeleteOp)1024 if assert.Error(t, err) {1025 assert.IsType(t, &OperationForbiddenError{}, err)1026 }1027 err = UpdateJSON(td, []string{"mapMapIntfVal", "key1", "key3", "3"}, nil, DeleteOp)1028 if assert.Error(t, err) {1029 assert.IsType(t, &KeyNotFoundError{}, err)1030 }1031}1032func TestDeleteSuccessful(t *testing.T) {1033 strVal1 := "strVal1"1034 strVal2 := "strVal2"1035 intVal := 51036 mapVal := map[string]string{1037 "key1": strVal1,1038 "key2": strVal2,1039 }1040 mapPtrVal := map[string]*string{1041 "key1": &strVal1,1042 "key2": &strVal2,1043 }1044 mapMapVal := map[string]map[string]string{1045 "key1": mapVal,1046 "key2": mapVal,1047 }1048 mapPtrMapVal := map[string]*map[string]string{1049 "key1": &mapVal,1050 "key2": &mapVal,1051 }1052 sliceVal := []string{strVal1, strVal2}1053 mapSliceVal := map[string][]string{1054 "key1": sliceVal,1055 "key2": sliceVal,1056 }1057 mapPtrSliceVal := map[string]*[]string{1058 "key1": &sliceVal,1059 "key2": &sliceVal,1060 }1061 slicePtrVal := []*string{&strVal1, &strVal2}1062 sliceMapVal := []map[string]string{mapVal, mapVal}1063 slicePtrMapVal := []*map[string]string{&mapVal, &mapVal}1064 sliceSliceVal := [][]string{sliceVal, sliceVal}1065 slicePtrSliceVal := []*[]string{&sliceVal, &sliceVal}1066 sliceIntfVal := []interface{}{strVal1, &mapSliceVal}1067 td1 := TypeDeep{1068 MapVal: mapVal,1069 PtrMapVal: &mapVal,1070 MapPtrVal: mapPtrVal,1071 MapMapVal: mapMapVal,1072 }1073 mapDeep := map[string]TypeDeep{1074 "key1": td1,1075 "key2": td1,1076 }1077 mapPtrDeep := map[string]*TypeDeep{1078 "key1": &td1,1079 "key2": &td1,1080 }1081 td := &TypeDeep{1082 StrVal: strVal1,1083 IntVal: intVal,1084 MapVal: mapVal,1085 PtrMapVal: &mapVal,1086 MapPtrVal: mapPtrVal,1087 MapMapVal: mapMapVal,1088 MapPtrMapVal: mapPtrMapVal,1089 MapSliceVal: mapSliceVal,1090 MapPtrSliceVal: mapPtrSliceVal,1091 SliceVal: sliceVal,1092 SlicePtrVal: slicePtrVal,1093 SliceMapVal: sliceMapVal,1094 SlicePtrMapVal: slicePtrMapVal,1095 SliceSliceVal: sliceSliceVal,1096 SlicePtrSliceVal: slicePtrSliceVal,1097 SliceIntfVal: sliceIntfVal,1098 //MapIntfVal1099 //PtrMapIntfVal1100 //MapSliceIntfVal1101 //MapPtrSliceIntfVal1102 //MapMapIntfVal1103 //MapPtrMapIntfVal1104 PtrDeep: &td1,1105 //SliceDeep1106 //SlicePtrDeep1107 MapDeep: mapDeep,1108 MapPtrDeep: mapPtrDeep,1109 //MapSlicePtrDeep1110 //MapMapDeep1111 //MapPtrMapDeep1112 //MapMapPtrDeep1113 }1114 // One level.1115 err := UpdateJSON(td, []string{"mapVal", "key1"}, nil, DeleteOp)1116 if assert.NoError(t, err) {1117 _, ok := td.MapVal["key1"]1118 assert.False(t, ok)1119 }1120 err = UpdateJSON(td, []string{"ptrMapVal", "key2"}, nil, DeleteOp)1121 if assert.NoError(t, err) {1122 _, ok := (*td.PtrMapVal)["key2"]1123 assert.False(t, ok)1124 }1125 mapVal["key1"] = strVal11126 mapVal["key2"] = strVal21127 err = UpdateJSON(td, []string{"mapPtrVal", "key1"}, nil, DeleteOp)1128 if assert.NoError(t, err) {1129 _, ok := td.MapPtrVal["key1"]1130 assert.False(t, ok)1131 }1132 err = UpdateJSON(td, []string{"mapMapVal", "key1"}, nil, DeleteOp)1133 if assert.NoError(t, err) {1134 _, ok := td.MapMapVal["key1"]1135 assert.False(t, ok)1136 }1137 err = UpdateJSON(td, []string{"mapPtrMapVal", "key1"}, nil, DeleteOp)1138 if assert.NoError(t, err) {1139 _, ok := td.MapPtrMapVal["key1"]1140 assert.False(t, ok)1141 }1142 // Two levels.1143 // TODO: can actually handle deleting indexed elements in the slice, but the1144 // delete should probably be done by value and not by index.1145 //err = UpdateJSON(td, []string{"sliceIntfVal", "0"}, nil, DeleteOp)1146 //if assert.NoError(t, err) {1147 // assert.Equal(t, 1, len(td.SliceIntfVal))1148 //}1149 err = UpdateJSON(td, []string{"mapDeep", "key1"}, nil, DeleteOp)1150 if assert.NoError(t, err) {1151 _, ok := td.MapDeep["key1"]1152 assert.False(t, ok)1153 }1154 err = UpdateJSON(td, []string{"mapPtrDeep", "key1"}, nil, DeleteOp)1155 if assert.NoError(t, err) {1156 _, ok := td.MapPtrDeep["key1"]1157 assert.False(t, ok)1158 }1159 // Three levels.1160 err = UpdateJSON(td, []string{"ptrDeep", "mapPtrVal", "key2"}, nil, DeleteOp)1161 if assert.NoError(t, err) {1162 _, ok := td.PtrDeep.MapPtrVal["key2"]1163 assert.False(t, ok)1164 }1165 err = UpdateJSON(td, []string{"mapMapVal", "key2", "key1"}, nil, DeleteOp)1166 if assert.NoError(t, err) {1167 _, ok := td.MapMapVal["key2"]["key1"]1168 assert.False(t, ok)1169 }1170 err = UpdateJSON(td, []string{"mapPtrMapVal", "key2", "key2"}, nil, DeleteOp)1171 if assert.NoError(t, err) {1172 _, ok := (*td.MapPtrMapVal["key2"])["key2"]1173 assert.False(t, ok)1174 }1175 // Four levels.1176 mapVal["key1"] = strVal11177 mapVal["key2"] = strVal21178 err = UpdateJSON(td, []string{"mapDeep", "key2", "mapVal", "key1"}, nil, DeleteOp)1179 if assert.NoError(t, err) {1180 _, ok := td.MapDeep["key2"].MapVal["key1"]1181 assert.False(t, ok)1182 }1183 err = UpdateJSON(td, []string{"mapPtrDeep", "key2", "mapVal", "key2"}, nil, DeleteOp)1184 if assert.NoError(t, err) {1185 _, ok := td.MapPtrDeep["key2"].MapVal["key2"]1186 assert.False(t, ok)1187 }1188}...

Full Screen

Full Screen

diff_test.go

Source:diff_test.go Github

copy

Full Screen

...18 {19 Name: "test1",20 Size: 3,21 Align: 1,22 Ptr: 1,23 },24 {25 Name: "test2",26 Type: "float64",27 Size: 8,28 Align: 8,29 Ptr: 6,30 },31 {32 Name: "test3",33 Size: 3,34 Align: 1,35 Ptr: 1,36 },37 },38 })39 rh.Push("test", "test", gopium.Struct{40 Name: "test",41 Fields: []gopium.Field{42 {43 Name: "test2",44 Type: "float64",45 Size: 8,46 Align: 8,47 Ptr: 6,48 },49 {50 Name: "test1",51 Size: 3,52 Align: 1,53 Ptr: 1,54 },55 {56 Name: "test3",57 Size: 3,58 Align: 1,59 Ptr: 1,60 },61 },62 })63 rhb.Push("test", "test", gopium.Struct{64 Name: "test",65 Fields: []gopium.Field{66 {67 Name: "test2",68 Type: "float64",69 Size: 8,70 Align: 8,71 Ptr: 6,72 },73 {74 Name: "test2",75 Type: "float64",76 Size: 8,77 Align: 8,78 Ptr: 6,79 },80 {81 Name: "test2",82 Type: "float64",83 Size: 8,84 Align: 8,85 Ptr: 6,86 },87 {88 Name: "test2",89 Type: "float64",90 Size: 8,91 Align: 8,92 Ptr: 6,93 },94 },95 })96 rhb.Push("test1", "test1", gopium.Struct{97 Name: "test",98 Fields: []gopium.Field{99 {100 Name: "test2",101 Type: "float64",102 Size: 8,103 Align: 8,104 Ptr: 6,105 },106 },107 })108 table := map[string]struct {109 fmt gopium.Diff110 o gopium.Categorized111 r gopium.Categorized112 b []byte113 err error114 }{115 "size align md table should return expected result for empty collections": {116 fmt: SizeAlignMdt,117 o: collections.NewHierarchic(""),118 r: collections.NewHierarchic(""),119 b: []byte(`120| Struct Name | Original Size with Pad | Current Size with Pad | Absolute Size Difference | Relative Size Difference | Original Ptr Size with Pad | Current Ptr Size with Pad | Absolute Ptr Size Difference | Relative Ptr Size Difference |121| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |122`),123 },124 "size align md table should return expected result for non empty collections": {125 fmt: SizeAlignMdt,126 o: oh,127 r: rh,128 b: []byte(`129| Struct Name | Original Size with Pad | Current Size with Pad | Absolute Size Difference | Relative Size Difference | Original Ptr Size with Pad | Current Ptr Size with Pad | Absolute Ptr Size Difference | Relative Ptr Size Difference |130| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |131| test | 24 bytes | 16 bytes | -8 bytes | -33.33% | 17 bytes | 12 bytes | -5 bytes | -29.41% |132| Total | 24 bytes | 16 bytes | -8 bytes | -33.33% | 17 bytes | 12 bytes | -5 bytes | -29.41% |133`),134 },135 "size align md table should return expected result for non empty overlapping collections": {136 fmt: SizeAlignMdt,137 o: oh,138 r: rhb,139 b: []byte(`140| Struct Name | Original Size with Pad | Current Size with Pad | Absolute Size Difference | Relative Size Difference | Original Ptr Size with Pad | Current Ptr Size with Pad | Absolute Ptr Size Difference | Relative Ptr Size Difference |141| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |142| test | 24 bytes | 32 bytes | +8 bytes | +33.33% | 17 bytes | 30 bytes | +13 bytes | +76.47% |143| Total | 24 bytes | 32 bytes | +8 bytes | +33.33% | 17 bytes | 30 bytes | +13 bytes | +76.47% |144`),145 },146 "fields html table should return expected result for empty collections": {147 fmt: FieldsHtmlt,148 o: collections.NewHierarchic(""),149 r: collections.NewHierarchic(""),150 b: []byte(`151<html>152 <head>153 <link154 href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"155 rel="stylesheet"156 integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk"157 crossorigin="anonymous"158 >159 <script160 src="http://code.jquery.com/jquery-3.5.1.min.js"161 integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="162 crossorigin="anonymous"163 ></script>164 <script165 src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"166 integrity="sha384-1CmrxMRARb6aLqgBO7yyAxTOQE2AKb9GfXnEo760AUcUmFx3ibVJJAzGytlQcNXd"167 crossorigin="anonymous"168 ></script>169 <style>170 .add{ background: green; }171 .del{ background: red; }172 .diff{ background: white; }173 </style>174 </head>175 <body>176 <div class="accordion" id="structs">177 </div>178 <body>179</html>180`),181 },182 "fields html table should return expected result for non empty collections": {183 fmt: FieldsHtmlt,184 o: oh,185 r: rh,186 b: []byte(`187<html>188 <head>189 <link190 href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"191 rel="stylesheet"192 integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk"193 crossorigin="anonymous"194 >195 <script196 src="http://code.jquery.com/jquery-3.5.1.min.js"197 integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="198 crossorigin="anonymous"199 ></script>200 <script201 src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"202 integrity="sha384-1CmrxMRARb6aLqgBO7yyAxTOQE2AKb9GfXnEo760AUcUmFx3ibVJJAzGytlQcNXd"203 crossorigin="anonymous"204 ></script>205 <style>206 .add{ background: green; }207 .del{ background: red; }208 .diff{ background: white; }209 </style>210 </head>211 <body>212 <div class="accordion" id="structs">213 <div class="card">214 <div class="card-header" id="headingtest">215 <h2 class="mb-0">216 <button217 class="btn btn-link btn-block"218 type="button"219 data-toggle="collapse"220 data-target="#collapsetest"221 aria-expanded="true"222 aria-controls="collapsetest"223 >224 test225 </button>226 </h2>227 </div>228 <div id="collapsetest" class="collapse" aria-labelledby="headingtest" data-parent="#structs">229 <table class="table">230 <thead>231 <tr>232 <th scope="col">#</th>233 <th scope="col">Name</th>234 <th scope="col">Type</th>235 <th scope="col">Size</th>236 <th scope="col">Align</th>237 <th scope="col">Ptr</th>238 <th scope="col">Tag</th>239 <th scope="col">Exported</th>240 <th scope="col">Embedded</th>241 <th scope="col">Doc</th>242 <th scope="col">Comment</th>243 </tr>244 </thead>245 <tbody>246 <tr class="diff">247 <th scope="row">1</th>248 <td>test1 -> test2</td>249 <td> -> float64</td>250 <td>3 -> 8</td>251 <td>1 -> 8</td>252 <td>1 -> 6</td>253 <td>"" -> ""</td>254 <td>false -> false</td>255 <td>false -> false</td>256 <td>"" -> ""</td>257 <td>"" -> ""</td>258 </tr>259 <tr class="diff">260 <th scope="row">2</th>261 <td>test2 -> test1</td>262 <td>float64 -> </td>263 <td>8 -> 3</td>264 <td>8 -> 1</td>265 <td>6 -> 1</td>266 <td>"" -> ""</td>267 <td>false -> false</td>268 <td>false -> false</td>269 <td>"" -> ""</td>270 <td>"" -> ""</td>271 </tr>272 <tr class="diff">273 <th scope="row">3</th>274 <td>test3 -> test3</td>275 <td> -> </td>276 <td>3 -> 3</td>277 <td>1 -> 1</td>278 <td>1 -> 1</td>279 <td>"" -> ""</td>280 <td>false -> false</td>281 <td>false -> false</td>282 <td>"" -> ""</td>283 <td>"" -> ""</td>284 </tr>285 </tbody>286 </table>287 </div>288 </div>289 </div>290 <body>291</html>292`),293 },294 "fields html table return expected result for non empty overlapping collections": {295 fmt: FieldsHtmlt,296 o: oh,297 r: rhb,298 b: []byte(`299<html>300 <head>301 <link302 href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"303 rel="stylesheet"304 integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk"305 crossorigin="anonymous"306 >307 <script308 src="http://code.jquery.com/jquery-3.5.1.min.js"309 integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="310 crossorigin="anonymous"311 ></script>312 <script313 src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"314 integrity="sha384-1CmrxMRARb6aLqgBO7yyAxTOQE2AKb9GfXnEo760AUcUmFx3ibVJJAzGytlQcNXd"315 crossorigin="anonymous"316 ></script>317 <style>318 .add{ background: green; }319 .del{ background: red; }320 .diff{ background: white; }321 </style>322 </head>323 <body>324 <div class="accordion" id="structs">325 <div class="card">326 <div class="card-header" id="headingtest">327 <h2 class="mb-0">328 <button329 class="btn btn-link btn-block"330 type="button"331 data-toggle="collapse"332 data-target="#collapsetest"333 aria-expanded="true"334 aria-controls="collapsetest"335 >336 test337 </button>338 </h2>339 </div>340 <div id="collapsetest" class="collapse" aria-labelledby="headingtest" data-parent="#structs">341 <table class="table">342 <thead>343 <tr>344 <th scope="col">#</th>345 <th scope="col">Name</th>346 <th scope="col">Type</th>347 <th scope="col">Size</th>348 <th scope="col">Align</th>349 <th scope="col">Ptr</th>350 <th scope="col">Tag</th>351 <th scope="col">Exported</th>352 <th scope="col">Embedded</th>353 <th scope="col">Doc</th>354 <th scope="col">Comment</th>355 </tr>356 </thead>357 <tbody>358 <tr class="diff">359 <th scope="row">1</th>360 <td>test1 -> test2</td>361 <td> -> float64</td>362 <td>3 -> 8</td>363 <td>1 -> 8</td>...

Full Screen

Full Screen

templates.go

Source:templates.go Github

copy

Full Screen

...11{{if hasShape .}}<TR><TD>Shape</TD><TD>{{ getShape .}}</TD></TR>{{end}}12<TR><TD>Overwrites Input {{overwritesInput . }}</TD><TD>Data On: {{.Device}}</TD></TR>13{{if hasGrad .}}<TR><TD>Value</TD><TD>Grad</TD></TR>14<TR><TD>{{printf "%+3.3s" .Value | dotEscape}}</TD><TD>{{getGrad . | dotEscape }} </TD></TR>15<TR><TD>Ptr: {{getValPtr . | dotEscape}} </TD><TD>Ptr: {{getGradPtr . | dotEscape}} </TD></TR>16{{else}}17<TR><TD>Value</TD><TD>{{printf "%+3.3s" .Value | dotEscape}}</TD></TR>18{{end}}19</TABLE>20>`21func dotEscape(s string) string {22 s = strings.Replace(s, "\n", "<BR />", -1)23 s = strings.Replace(s, "<nil>", "NIL", -1)24 return s25}26func printOp(n *Node) bool { return n.op != nil && !n.isStmt }27func isLeaf(n *Node) bool { return len(n.children) == 0 }28func isInput(n *Node) bool { return n.isInput() }29func isMarked(n *Node) bool { return n.ofInterest }30func isRoot(n *Node) bool { return n.isRoot() }31func isStmt(n *Node) bool { return n.isStmt }32func hasShape(n *Node) bool { return n.shape != nil }33func hasGrad(n *Node) bool { _, err := n.Grad(); return err == nil }34func opStr(n *Node) string { return n.op.String() }35func opType(n *Node) string { return n.op.Type().String() }36func nodeType(n *Node) string {37 if n.t == nil {38 return "NIL"39 }40 return n.t.String()41}42func overwritesInput(n *Node) int {43 if n.op == nil {44 return -145 }46 return n.op.OverwritesInput()47}48func getShape(n *Node) string {49 if !n.inferredShape {50 return fmt.Sprintf("%v", n.shape)51 }52 return fmt.Sprintf("<U>%v</U>", n.shape) // graphviz 2.38+ only supports <O>53}54func getGrad(n *Node) string {55 grad, err := n.Grad()56 if err == nil {57 return fmt.Sprintf("%+3.3s", grad)58 }59 return ""60}61func getGradPtr(n *Node) string {62 grad, err := n.Grad()63 if err == nil && grad != nil {64 return fmt.Sprintf("0x%x", grad.Uintptr())65 }66 return ""67}68func getValPtr(n *Node) string {69 if n.Value() == nil {70 return "<nil>"71 }72 return fmt.Sprintf("0x%dx", n.Value().Uintptr())73}74var funcMap = template.FuncMap{75 "dotEscape": dotEscape,76 "printOp": printOp,77 "isRoot": isRoot,78 "isLeaf": isLeaf,79 "isInput": isInput,80 "isStmt": isStmt,81 "isMarked": isMarked,82 "hasShape": hasShape,83 "hasGrad": hasGrad,84 "getShape": getShape,85 "getValPtr": getValPtr,86 "getGrad": getGrad,87 "getGradPtr": getGradPtr,88 "overwritesInput": overwritesInput,89 "opStr": opStr,90 "opType": opType,91 "nodeType": nodeType,92}93var (94 exprNodeTempl *template.Template95 exprNodeJSONTempl *template.Template96)97func init() {98 exprNodeTempl = template.Must(template.New("node").Funcs(funcMap).Parse(exprNodeTemplText))99}...

Full Screen

Full Screen

Ptr

Using AI Code Generation

copy

Full Screen

1import (2type td struct {3}4func (t td) Ptr() uintptr {5 return uintptr(unsafe.Pointer(&t))6}7func main() {8 t := td{1, 2}9 fmt.Println(t.Ptr())10}11But, this is not the correct way to use the unsafe.Pointer() function. The correct way to use this function is as follows:12import (13type td struct {14}15func (t td) Ptr() uintptr {16 return uintptr(unsafe.Pointer(&t))17}18func main() {19 t := td{1, 2}20 fmt.Println(t.Ptr())21}22But, this is not the correct way to use the unsafe.Pointer() function. The correct way to use this function is as follows:23import (24type td struct {25}26func (t td) Ptr() uintptr {27 return uintptr(unsafe.Pointer(&t))28}29func main() {30 t := td{1, 2}31 fmt.Println(t.Ptr())32}33But, this is not the correct way to use the unsafe.Pointer() function. The correct way to use this function is as follows:34import (35type td struct {36}37func (t td) Ptr() uintptr {38 return uintptr(unsafe.Pointer(&t))39}40func main() {41 t := td{1, 2}42 fmt.Println(t.Ptr())43}

Full Screen

Full Screen

Ptr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println(*p)4 fmt.Println(i)5}6import "fmt"7func main() {8 var p *int = new(int)9 fmt.Println(*p)10 fmt.Println(*p)11}12import "fmt"13func main() {14 p := new(int)15 fmt.Println(*p)16 fmt.Println(*p)17}18import "fmt"19func main() {20 p := new(int)21 fmt.Println(p)22 fmt.Println(*p)23 fmt.Println(*p)24}25import "fmt"26func main() {27 p := new(int)28 fmt.Println(p)29 fmt.Println(*p)30 fmt.Println(*p)31 fmt.Println(&p)32}33import "fmt"34func main() {35 p := new(int)36 fmt.Println(p)37 fmt.Println(*p)38 fmt.Println(*p)39 fmt.Println(&p)40 fmt.Println(&*p)41}42import "fmt"43func main() {44 p := new(int)45 fmt.Println(p)46 fmt.Println(*p)47 fmt.Println(*p)48 fmt.Println(&p)49 fmt.Println(&*p)50 fmt.Println(&p == &*p)51}52import "fmt"53func main() {54 var p *int = new(int)55 fmt.Println(p)56 fmt.Println(*p)57 fmt.Println(*p)

Full Screen

Full Screen

Ptr

Using AI Code Generation

copy

Full Screen

1import (2type td struct {3}4func main() {5 fmt.Println("t.a=", t.a)6 fmt.Println("t.b=", t.b)7 fmt.Println("t=", t)8 fmt.Println("t=", &t)9 fmt.Println("p=", p)10 fmt.Println("p=", &p)11 fmt.Println("p.a=", p.Ptr().a)12 fmt.Println("p.b=", p.Ptr().b)13 fmt.Println("p.a=", p.Ptr().a)14 fmt.Println("p.b=", p.Ptr().b)15}16import (17type td struct {18}19func main() {20 fmt.Println("t.a=", t.a)21 fmt.Println("t.b=", t.b)22 fmt.Println("t=", t)23 fmt.Println("t=", &t)24 fmt.Println("p=", p)25 fmt.Println("p=", &p)26 fmt.Println("p.a=", p.Ptr().a)27 fmt.Println("p.b=", p.Ptr().b)28 fmt.Println("p.a=", p.Ptr().a)29 fmt.Println("p.b=", p.Ptr().b)30}31import (32type td struct {33}34func main() {35 fmt.Println("t.a=", t.a)36 fmt.Println("t.b=", t.b)37 fmt.Println("t=", t)38 fmt.Println("t=", &t)39 fmt.Println("p=", p)40 fmt.Println("p=", &p)41 fmt.Println("p.a=", p.Ptr().a)42 fmt.Println("p.b=", p.Ptr().b)43 fmt.Println("p.a=", p.Ptr().a

Full Screen

Full Screen

Ptr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 x := td.NewT(1)4 y := x.Ptr()5 fmt.Println(*y)6}7import (8func main() {9 x := td.NewT(1)10 y := x.Ptr()11 fmt.Println(*y)12}13type T struct {14}15func NewT(x int) *T {16 return &T{x}17}18func (t *T) Ptr() *int {19}20type T struct {21}22func NewT(x int) *T {23 return &T{x}24}25func (t *T) Ptr() *int {26}27type T struct {28}29func NewT(x int) *T {30 return &T{x}31}32func (t *T) Ptr() *int {33}34type T struct {35}36func NewT(x int) *T {37 return &T{x}38}39func (t *T) Ptr() *int {40}41type T struct {42}43func NewT(x int) *T {44 return &T{x}45}46func (t *T) Ptr() *int {47}48type T struct {49}50func NewT(x int) *T {51 return &T{x}52}53func (t *T) Ptr() *int {54}55type T struct {56}57func NewT(x int) *T {58 return &T{x}59}60func (t *T) Ptr() *int {61}

Full Screen

Full Screen

Ptr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a.Set(3, 4)4 b := a.Ptr()5 fmt.Println("b=", *b)6 b.Set(5, 6)7 fmt.Println("a=", a)8}9import (10func main() {11 a.Set(3, 4)12 b := a.Ptr()13 fmt.Println("b=", *b)14 b.Set(5, 6)15 fmt.Println("a=", a)16}17import (18func main() {19 a.Set(3, 4)20 b := a.Ptr()21 fmt.Println("b=", *b)22 b.Set(5, 6)23 fmt.Println("a=", a)24}25import (26func main() {27 a.Set(3, 4)28 b := a.Ptr()29 fmt.Println("b=", *b)30 b.Set(5, 6)31 fmt.Println("a=", a)32}33import (34func main() {35 a.Set(3, 4)36 b := a.Ptr()37 fmt.Println("b=", *b)38 b.Set(5, 6)39 fmt.Println("a=", a)40}41import (42func main() {43 a.Set(3, 4)44 b := a.Ptr()45 fmt.Println("b=", *b)46 b.Set(5, 6)47 fmt.Println("a=", a)48}

Full Screen

Full Screen

Ptr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td.Set(10)4 fmt.Println(td.Get())5}6import (7type Testdata struct {8}9func (td *Testdata) Set(d int) {10 fmt.Println(td.data)11}12func (td *Testdata) Get() int {13}

Full Screen

Full Screen

Ptr

Using AI Code Generation

copy

Full Screen

1import (2type td struct {3}4func main() {5fmt.Println("before", t.a, t.b)6p := unsafe.Pointer(&t)7fmt.Println("pointer", p)8p = unsafe.Pointer(t.Ptr())9fmt.Println("pointer", p)10*(**int)(p) = new(int)11**(int)(unsafe.Pointer(uintptr(p) + unsafe.Offsetof(t.b))) = new(int)12fmt.Println("after", t.a, t.b)13}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Go-testdeep automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful