@@ -1710,58 +1710,55 @@ func TestMarshalNotRespectNil(t *testing.T) {
1710
1710
assert .NotNil (t , testStruct2 .Map , "expected non-nil map" )
1711
1711
}
1712
1712
1713
- // func TestMarshalRespectNil(t *testing.T) {
1714
- // type T struct {
1715
- // Slice []int
1716
- // SlicePtr *[]int
1717
- // Ptr *int
1718
- // Map map[string]interface{}
1719
- // MapPtr *map[string]interface{}
1720
- // }
1721
-
1722
- // bson.SetRespectNilValues(true)
1723
- // defer bson.SetRespectNilValues(false)
1713
+ func TestMarshalRespectNil (t * testing.T ) {
1714
+ type T struct {
1715
+ Slice []int
1716
+ SlicePtr * []int
1717
+ Ptr * int
1718
+ Map map [string ]interface {}
1719
+ MapPtr * map [string ]interface {}
1720
+ }
1724
1721
1725
- // testStruct1 := T{}
1722
+ testStruct1 := T {}
1726
1723
1727
- // assert.Nil(t, testStruct1.Slice, "expected nil slice, got: %v", testStruct1.Slice)
1728
- // assert.Nil(t, testStruct1.SlicePtr, "expected nil slice ptr, got: %v", testStruct1.SlicePtr)
1729
- // assert.Nil(t, testStruct1.Map, "expected nil map, got: %v", testStruct1.Map)
1730
- // assert.Nil(t, testStruct1.MapPtr, "expected nil map ptr, got: %v", testStruct1.MapPtr)
1731
- // assert.Nil(t, testStruct1.Ptr, "expected nil ptr, got: %v", testStruct1.Ptr)
1724
+ assert .Nil (t , testStruct1 .Slice , "expected nil slice, got: %v" , testStruct1 .Slice )
1725
+ assert .Nil (t , testStruct1 .SlicePtr , "expected nil slice ptr, got: %v" , testStruct1 .SlicePtr )
1726
+ assert .Nil (t , testStruct1 .Map , "expected nil map, got: %v" , testStruct1 .Map )
1727
+ assert .Nil (t , testStruct1 .MapPtr , "expected nil map ptr, got: %v" , testStruct1 .MapPtr )
1728
+ assert .Nil (t , testStruct1 .Ptr , "expected nil ptr, got: %v" , testStruct1 .Ptr )
1732
1729
1733
- // b, _ := bson.MarshalWithRegistry(mgoRegistry , testStruct1)
1730
+ b , _ := bson .MarshalWithRegistry (mgoRegistryRespectNilValues , testStruct1 )
1734
1731
1735
- // testStruct2 := T{}
1732
+ testStruct2 := T {}
1736
1733
1737
- // _ = bson.UnmarshalWithRegistry(mgoRegistry , b, &testStruct2)
1734
+ _ = bson .UnmarshalWithRegistry (mgoRegistryRespectNilValues , b , & testStruct2 )
1738
1735
1739
- // assert.Nil(t, testStruct2.Slice, "expected nil slice, got: %v", testStruct2.Slice)
1740
- // assert.Nil(t, testStruct2.SlicePtr, "expected nil slice ptr, got: %v", testStruct2.SlicePtr)
1741
- // assert.Nil(t, testStruct2.Map, "expected nil map, got: %v", testStruct2.Map)
1742
- // assert.Nil(t, testStruct2.MapPtr, "expected nil map ptr, got: %v", testStruct2.MapPtr)
1743
- // assert.Nil(t, testStruct2.Ptr, "expected nil ptr, got: %v", testStruct2.Ptr)
1736
+ assert .Nil (t , testStruct2 .Slice , "expected nil slice, got: %v" , testStruct2 .Slice )
1737
+ assert .Nil (t , testStruct2 .SlicePtr , "expected nil slice ptr, got: %v" , testStruct2 .SlicePtr )
1738
+ assert .Nil (t , testStruct2 .Map , "expected nil map, got: %v" , testStruct2 .Map )
1739
+ assert .Nil (t , testStruct2 .MapPtr , "expected nil map ptr, got: %v" , testStruct2 .MapPtr )
1740
+ assert .Nil (t , testStruct2 .Ptr , "expected nil ptr, got: %v" , testStruct2 .Ptr )
1744
1741
1745
- // testStruct1 = T{
1746
- // Slice: []int{},
1747
- // SlicePtr: &[]int{},
1748
- // Map: map[string]interface{}{},
1749
- // MapPtr: &map[string]interface{}{},
1750
- // }
1742
+ testStruct1 = T {
1743
+ Slice : []int {},
1744
+ SlicePtr : & []int {},
1745
+ Map : map [string ]interface {}{},
1746
+ MapPtr : & map [string ]interface {}{},
1747
+ }
1751
1748
1752
- // assert.NotNil(t, testStruct1.Slice, "expected non-nil slice")
1753
- // assert.NotNil(t, testStruct1.SlicePtr, "expected non-nil slice ptr")
1754
- // assert.NotNil(t, testStruct1.Map, "expected non-nil map")
1755
- // assert.NotNil(t, testStruct1.MapPtr, "expected non-nil map ptr")
1749
+ assert .NotNil (t , testStruct1 .Slice , "expected non-nil slice" )
1750
+ assert .NotNil (t , testStruct1 .SlicePtr , "expected non-nil slice ptr" )
1751
+ assert .NotNil (t , testStruct1 .Map , "expected non-nil map" )
1752
+ assert .NotNil (t , testStruct1 .MapPtr , "expected non-nil map ptr" )
1756
1753
1757
- // b, _ = bson.MarshalWithRegistry(mgoRegistry , testStruct1)
1754
+ b , _ = bson .MarshalWithRegistry (mgoRegistryRespectNilValues , testStruct1 )
1758
1755
1759
- // testStruct2 = T{}
1756
+ testStruct2 = T {}
1760
1757
1761
- // _ = bson.UnmarshalWithRegistry(mgoRegistry , b, &testStruct2)
1758
+ _ = bson .UnmarshalWithRegistry (mgoRegistryRespectNilValues , b , & testStruct2 )
1762
1759
1763
- // assert.NotNil(t, testStruct2.Slice, "expected non-nil slice")
1764
- // assert.NotNil(t, testStruct2.SlicePtr, "expected non-nil slice ptr")
1765
- // assert.NotNil(t, testStruct2.Map, "expected non-nil map")
1766
- // assert.NotNil(t, testStruct2.MapPtr, "expected non-nil map ptr")
1767
- // }
1760
+ assert .NotNil (t , testStruct2 .Slice , "expected non-nil slice" )
1761
+ assert .NotNil (t , testStruct2 .SlicePtr , "expected non-nil slice ptr" )
1762
+ assert .NotNil (t , testStruct2 .Map , "expected non-nil map" )
1763
+ assert .NotNil (t , testStruct2 .MapPtr , "expected non-nil map ptr" )
1764
+ }
0 commit comments