@@ -49,7 +49,7 @@ func TestFromTypedStructPointerZeroFields(t *testing.T) {
4949 require .NoError (t , err )
5050 assert .Equal (t , dyn .NilValue , nv )
5151
52- // For an initialized pointer with a nil reference we expect an empty map .
52+ // For an initialized pointer with a nil reference we expect a nil .
5353 src = & Tmp {}
5454 nv , err = FromTyped (src , dyn .NilValue )
5555 require .NoError (t , err )
@@ -103,7 +103,7 @@ func TestFromTypedStructSetFields(t *testing.T) {
103103 }), nv )
104104}
105105
106- func TestFromTypedStructSetFieldsRetainLocation (t * testing.T ) {
106+ func TestFromTypedStructSetFieldsRetainLocationIfUnchanged (t * testing.T ) {
107107 type Tmp struct {
108108 Foo string `json:"foo"`
109109 Bar string `json:"bar"`
@@ -122,9 +122,11 @@ func TestFromTypedStructSetFieldsRetainLocation(t *testing.T) {
122122 nv , err := FromTyped (src , ref )
123123 require .NoError (t , err )
124124
125- // Assert foo and bar have retained their location.
125+ // Assert foo has retained its location.
126126 assert .Equal (t , dyn .NewValue ("bar" , dyn.Location {File : "foo" }), nv .Get ("foo" ))
127- assert .Equal (t , dyn .NewValue ("qux" , dyn.Location {File : "bar" }), nv .Get ("bar" ))
127+
128+ // Assert bar lost its location (because it was overwritten).
129+ assert .Equal (t , dyn .NewValue ("qux" , dyn.Location {}), nv .Get ("bar" ))
128130}
129131
130132func TestFromTypedStringMapWithZeroValue (t * testing.T ) {
@@ -352,7 +354,7 @@ func TestFromTypedMapNonEmpty(t *testing.T) {
352354 }), nv )
353355}
354356
355- func TestFromTypedMapNonEmptyRetainLocation (t * testing.T ) {
357+ func TestFromTypedMapNonEmptyRetainLocationIfUnchanged (t * testing.T ) {
356358 var src = map [string ]string {
357359 "foo" : "bar" ,
358360 "bar" : "qux" ,
@@ -366,9 +368,11 @@ func TestFromTypedMapNonEmptyRetainLocation(t *testing.T) {
366368 nv , err := FromTyped (src , ref )
367369 require .NoError (t , err )
368370
369- // Assert foo and bar have retained their locations .
371+ // Assert foo has retained its location .
370372 assert .Equal (t , dyn .NewValue ("bar" , dyn.Location {File : "foo" }), nv .Get ("foo" ))
371- assert .Equal (t , dyn .NewValue ("qux" , dyn.Location {File : "bar" }), nv .Get ("bar" ))
373+
374+ // Assert bar lost its location (because it was overwritten).
375+ assert .Equal (t , dyn .NewValue ("qux" , dyn.Location {}), nv .Get ("bar" ))
372376}
373377
374378func TestFromTypedMapFieldWithZeroValue (t * testing.T ) {
@@ -425,23 +429,25 @@ func TestFromTypedSliceNonEmpty(t *testing.T) {
425429 }), nv )
426430}
427431
428- func TestFromTypedSliceNonEmptyRetainLocation (t * testing.T ) {
432+ func TestFromTypedSliceNonEmptyRetainLocationIfUnchanged (t * testing.T ) {
429433 var src = []string {
430434 "foo" ,
431435 "bar" ,
432436 }
433437
434438 ref := dyn .V ([]dyn.Value {
435439 dyn .NewValue ("foo" , dyn.Location {File : "foo" }),
436- dyn .NewValue ("bar " , dyn.Location {File : "bar " }),
440+ dyn .NewValue ("baz " , dyn.Location {File : "baz " }),
437441 })
438442
439443 nv , err := FromTyped (src , ref )
440444 require .NoError (t , err )
441445
442- // Assert foo and bar have retained their locations .
446+ // Assert foo has retained its location .
443447 assert .Equal (t , dyn .NewValue ("foo" , dyn.Location {File : "foo" }), nv .Index (0 ))
444- assert .Equal (t , dyn .NewValue ("bar" , dyn.Location {File : "bar" }), nv .Index (1 ))
448+
449+ // Assert bar lost its location (because it was overwritten).
450+ assert .Equal (t , dyn .NewValue ("bar" , dyn.Location {}), nv .Index (1 ))
445451}
446452
447453func TestFromTypedStringEmpty (t * testing.T ) {
@@ -476,20 +482,12 @@ func TestFromTypedStringNonEmptyOverwrite(t *testing.T) {
476482 assert .Equal (t , dyn .V ("new" ), nv )
477483}
478484
479- func TestFromTypedStringRetainsLocations (t * testing.T ) {
480- var ref = dyn .NewValue ("foo" , dyn.Location {File : "foo" })
481-
482- // case: value has not been changed
485+ func TestFromTypedStringRetainsLocationsIfUnchanged (t * testing.T ) {
483486 var src string = "foo"
487+ var ref = dyn .NewValue ("foo" , dyn.Location {File : "foo" })
484488 nv , err := FromTyped (src , ref )
485489 require .NoError (t , err )
486490 assert .Equal (t , dyn .NewValue ("foo" , dyn.Location {File : "foo" }), nv )
487-
488- // case: value has been changed
489- src = "bar"
490- nv , err = FromTyped (src , ref )
491- require .NoError (t , err )
492- assert .Equal (t , dyn .NewValue ("bar" , dyn.Location {File : "foo" }), nv )
493491}
494492
495493func TestFromTypedStringTypeError (t * testing.T ) {
@@ -531,20 +529,12 @@ func TestFromTypedBoolNonEmptyOverwrite(t *testing.T) {
531529 assert .Equal (t , dyn .V (true ), nv )
532530}
533531
534- func TestFromTypedBoolRetainsLocations (t * testing.T ) {
535- var ref = dyn .NewValue (true , dyn.Location {File : "foo" })
536-
537- // case: value has not been changed
532+ func TestFromTypedBoolRetainsLocationsIfUnchanged (t * testing.T ) {
538533 var src bool = true
534+ var ref = dyn .NewValue (true , dyn.Location {File : "foo" })
539535 nv , err := FromTyped (src , ref )
540536 require .NoError (t , err )
541537 assert .Equal (t , dyn .NewValue (true , dyn.Location {File : "foo" }), nv )
542-
543- // case: value has been changed
544- src = false
545- nv , err = FromTyped (src , ref )
546- require .NoError (t , err )
547- assert .Equal (t , dyn .NewValue (false , dyn.Location {File : "foo" }), nv )
548538}
549539
550540func TestFromTypedBoolVariableReference (t * testing.T ) {
@@ -594,20 +584,12 @@ func TestFromTypedIntNonEmptyOverwrite(t *testing.T) {
594584 assert .Equal (t , dyn .V (int64 (1234 )), nv )
595585}
596586
597- func TestFromTypedIntRetainsLocations (t * testing.T ) {
598- var ref = dyn .NewValue (1234 , dyn.Location {File : "foo" })
599-
600- // case: value has not been changed
587+ func TestFromTypedIntRetainsLocationsIfUnchanged (t * testing.T ) {
601588 var src int = 1234
589+ var ref = dyn .NewValue (1234 , dyn.Location {File : "foo" })
602590 nv , err := FromTyped (src , ref )
603591 require .NoError (t , err )
604592 assert .Equal (t , dyn .NewValue (1234 , dyn.Location {File : "foo" }), nv )
605-
606- // case: value has been changed
607- src = 1235
608- nv , err = FromTyped (src , ref )
609- require .NoError (t , err )
610- assert .Equal (t , dyn .NewValue (int64 (1235 ), dyn.Location {File : "foo" }), nv )
611593}
612594
613595func TestFromTypedIntVariableReference (t * testing.T ) {
@@ -657,21 +639,12 @@ func TestFromTypedFloatNonEmptyOverwrite(t *testing.T) {
657639 assert .Equal (t , dyn .V (1.23 ), nv )
658640}
659641
660- func TestFromTypedFloatRetainsLocations (t * testing.T ) {
661- var src float64
642+ func TestFromTypedFloatRetainsLocationsIfUnchanged (t * testing.T ) {
643+ var src float64 = 1.23
662644 var ref = dyn .NewValue (1.23 , dyn.Location {File : "foo" })
663-
664- // case: value has not been changed
665- src = 1.23
666645 nv , err := FromTyped (src , ref )
667646 require .NoError (t , err )
668647 assert .Equal (t , dyn .NewValue (1.23 , dyn.Location {File : "foo" }), nv )
669-
670- // case: value has been changed
671- src = 1.24
672- nv , err = FromTyped (src , ref )
673- require .NoError (t , err )
674- assert .Equal (t , dyn .NewValue (1.24 , dyn.Location {File : "foo" }), nv )
675648}
676649
677650func TestFromTypedFloatVariableReference (t * testing.T ) {
@@ -696,35 +669,3 @@ func TestFromTypedAnyNil(t *testing.T) {
696669 require .NoError (t , err )
697670 assert .Equal (t , dyn .NilValue , nv )
698671}
699-
700- func TestFromTypedNilPointerRetainsLocations (t * testing.T ) {
701- type Tmp struct {
702- Foo string `json:"foo"`
703- Bar string `json:"bar"`
704- }
705-
706- var src * Tmp
707- ref := dyn .NewValue (nil , dyn.Location {File : "foobar" })
708-
709- nv , err := FromTyped (src , ref )
710- require .NoError (t , err )
711- assert .Equal (t , dyn .NewValue (nil , dyn.Location {File : "foobar" }), nv )
712- }
713-
714- func TestFromTypedNilMapRetainsLocation (t * testing.T ) {
715- var src map [string ]string
716- ref := dyn .NewValue (nil , dyn.Location {File : "foobar" })
717-
718- nv , err := FromTyped (src , ref )
719- require .NoError (t , err )
720- assert .Equal (t , dyn .NewValue (nil , dyn.Location {File : "foobar" }), nv )
721- }
722-
723- func TestFromTypedNilSliceRetainsLocation (t * testing.T ) {
724- var src []string
725- ref := dyn .NewValue (nil , dyn.Location {File : "foobar" })
726-
727- nv , err := FromTyped (src , ref )
728- require .NoError (t , err )
729- assert .Equal (t , dyn .NewValue (nil , dyn.Location {File : "foobar" }), nv )
730- }
0 commit comments