Skip to content

Commit 2a76f61

Browse files
authored
test: add test cases to increase test coverage (#268)
1 parent 61b7223 commit 2a76f61

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

struct_test.go

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,25 @@ None =
539539
cfg := ini.Empty()
540540
type SpecialStruct struct {
541541
FirstName string `ini:"first_name"`
542-
LastName string `ini:"last_name"`
542+
LastName string `ini:"last_name,omitempty"`
543543
JustOmitMe string `ini:"omitempty"`
544544
LastLogin time.Time `ini:"last_login,omitempty"`
545545
LastLogin2 time.Time `ini:",omitempty"`
546546
NotEmpty int `ini:"omitempty"`
547+
Number int64 `ini:",omitempty"`
548+
Ages uint `ini:",omitempty"`
549+
Population uint64 `ini:",omitempty"`
550+
Coordinate float64 `ini:",omitempty"`
551+
Flag bool `ini:",omitempty"`
552+
Note *string `ini:",omitempty"`
553+
}
554+
special := &SpecialStruct{
555+
FirstName: "John",
556+
LastName: "Doe",
557+
NotEmpty: 9,
547558
}
548559

549-
So(ini.ReflectFrom(cfg, &SpecialStruct{FirstName: "John", LastName: "Doe", NotEmpty: 9}), ShouldBeNil)
560+
So(ini.ReflectFrom(cfg, special), ShouldBeNil)
550561

551562
var buf bytes.Buffer
552563
_, err = cfg.WriteTo(&buf)
@@ -724,12 +735,36 @@ path = /tmp/gpm-profiles/test1.profile
724735
AllowShadows: true,
725736
})
726737
type ShadowStruct struct {
727-
StringArray []string `ini:"sa,,allowshadow"`
728-
EmptyStringArrat []string `ini:"empty,omitempty,allowshadow"`
729-
Allowshadow []string `ini:"allowshadow,,allowshadow"`
738+
StringArray []string `ini:"sa,,allowshadow"`
739+
EmptyStringArrat []string `ini:"empty,omitempty,allowshadow"`
740+
Allowshadow []string `ini:"allowshadow,,allowshadow"`
741+
Dates []time.Time `ini:",,allowshadow"`
742+
Places []string `ini:",,allowshadow"`
743+
Years []int `ini:",,allowshadow"`
744+
Numbers []int64 `ini:",,allowshadow"`
745+
Ages []uint `ini:",,allowshadow"`
746+
Populations []uint64 `ini:",,allowshadow"`
747+
Coordinates []float64 `ini:",,allowshadow"`
748+
Flags []bool `ini:",,allowshadow"`
749+
None []int `ini:",,allowshadow"`
750+
}
751+
752+
shadow := &ShadowStruct{
753+
StringArray: []string{"s1", "s2"},
754+
Allowshadow: []string{"s3", "s4"},
755+
Dates: []time.Time{time.Date(2020, 9, 12, 00, 00, 00, 651387237, time.UTC),
756+
time.Date(2020, 9, 12, 00, 00, 00, 651387237, time.UTC)},
757+
Places: []string{"HangZhou", "Boston"},
758+
Years: []int{1993, 1994},
759+
Numbers: []int64{10010, 10086},
760+
Ages: []uint{18, 19},
761+
Populations: []uint64{12345678, 98765432},
762+
Coordinates: []float64{192.168, 10.11},
763+
Flags: []bool{true, false},
764+
None: []int{},
730765
}
731766

732-
So(ini.ReflectFrom(cfg, &ShadowStruct{StringArray: []string{"s1", "s2"}, Allowshadow: []string{"s3", "s4"}}), ShouldBeNil)
767+
So(ini.ReflectFrom(cfg, shadow), ShouldBeNil)
733768

734769
var buf bytes.Buffer
735770
_, err := cfg.WriteTo(&buf)
@@ -738,6 +773,22 @@ path = /tmp/gpm-profiles/test1.profile
738773
sa = s2
739774
allowshadow = s3
740775
allowshadow = s4
776+
Dates = 2020-09-12T00:00:00Z
777+
Places = HangZhou
778+
Places = Boston
779+
Years = 1993
780+
Years = 1994
781+
Numbers = 10010
782+
Numbers = 10086
783+
Ages = 18
784+
Ages = 19
785+
Populations = 12345678
786+
Populations = 98765432
787+
Coordinates = 192.168
788+
Coordinates = 10.11
789+
Flags = true
790+
Flags = false
791+
None =
741792
742793
`)
743794
})

0 commit comments

Comments
 (0)