test: add test cases to increase test coverage (#268)
yuangongji authored 3 years ago
GitHub committed 3 years ago
538 | 538 | cfg := ini.Empty() |
539 | 539 | type SpecialStruct struct { |
540 | 540 | FirstName string `ini:"first_name"` |
541 | LastName string `ini:"last_name"` | |
541 | LastName string `ini:"last_name,omitempty"` | |
542 | 542 | JustOmitMe string `ini:"omitempty"` |
543 | 543 | LastLogin time.Time `ini:"last_login,omitempty"` |
544 | 544 | LastLogin2 time.Time `ini:",omitempty"` |
545 | 545 | NotEmpty int `ini:"omitempty"` |
546 | } | |
547 | ||
548 | So(ini.ReflectFrom(cfg, &SpecialStruct{FirstName: "John", LastName: "Doe", NotEmpty: 9}), ShouldBeNil) | |
546 | Number int64 `ini:",omitempty"` | |
547 | Ages uint `ini:",omitempty"` | |
548 | Population uint64 `ini:",omitempty"` | |
549 | Coordinate float64 `ini:",omitempty"` | |
550 | Flag bool `ini:",omitempty"` | |
551 | Note *string `ini:",omitempty"` | |
552 | } | |
553 | special := &SpecialStruct{ | |
554 | FirstName: "John", | |
555 | LastName: "Doe", | |
556 | NotEmpty: 9, | |
557 | } | |
558 | ||
559 | So(ini.ReflectFrom(cfg, special), ShouldBeNil) | |
549 | 560 | |
550 | 561 | var buf bytes.Buffer |
551 | 562 | _, err = cfg.WriteTo(&buf) |
723 | 734 | AllowShadows: true, |
724 | 735 | }) |
725 | 736 | type ShadowStruct struct { |
726 | StringArray []string `ini:"sa,,allowshadow"` | |
727 | EmptyStringArrat []string `ini:"empty,omitempty,allowshadow"` | |
728 | Allowshadow []string `ini:"allowshadow,,allowshadow"` | |
729 | } | |
730 | ||
731 | So(ini.ReflectFrom(cfg, &ShadowStruct{StringArray: []string{"s1", "s2"}, Allowshadow: []string{"s3", "s4"}}), ShouldBeNil) | |
737 | StringArray []string `ini:"sa,,allowshadow"` | |
738 | EmptyStringArrat []string `ini:"empty,omitempty,allowshadow"` | |
739 | Allowshadow []string `ini:"allowshadow,,allowshadow"` | |
740 | Dates []time.Time `ini:",,allowshadow"` | |
741 | Places []string `ini:",,allowshadow"` | |
742 | Years []int `ini:",,allowshadow"` | |
743 | Numbers []int64 `ini:",,allowshadow"` | |
744 | Ages []uint `ini:",,allowshadow"` | |
745 | Populations []uint64 `ini:",,allowshadow"` | |
746 | Coordinates []float64 `ini:",,allowshadow"` | |
747 | Flags []bool `ini:",,allowshadow"` | |
748 | None []int `ini:",,allowshadow"` | |
749 | } | |
750 | ||
751 | shadow := &ShadowStruct{ | |
752 | StringArray: []string{"s1", "s2"}, | |
753 | Allowshadow: []string{"s3", "s4"}, | |
754 | Dates: []time.Time{time.Date(2020, 9, 12, 00, 00, 00, 651387237, time.UTC), | |
755 | time.Date(2020, 9, 12, 00, 00, 00, 651387237, time.UTC)}, | |
756 | Places: []string{"HangZhou", "Boston"}, | |
757 | Years: []int{1993, 1994}, | |
758 | Numbers: []int64{10010, 10086}, | |
759 | Ages: []uint{18, 19}, | |
760 | Populations: []uint64{12345678, 98765432}, | |
761 | Coordinates: []float64{192.168, 10.11}, | |
762 | Flags: []bool{true, false}, | |
763 | None: []int{}, | |
764 | } | |
765 | ||
766 | So(ini.ReflectFrom(cfg, shadow), ShouldBeNil) | |
732 | 767 | |
733 | 768 | var buf bytes.Buffer |
734 | 769 | _, err := cfg.WriteTo(&buf) |
737 | 772 | sa = s2 |
738 | 773 | allowshadow = s3 |
739 | 774 | allowshadow = s4 |
775 | Dates = 2020-09-12T00:00:00Z | |
776 | Places = HangZhou | |
777 | Places = Boston | |
778 | Years = 1993 | |
779 | Years = 1994 | |
780 | Numbers = 10010 | |
781 | Numbers = 10086 | |
782 | Ages = 18 | |
783 | Ages = 19 | |
784 | Populations = 12345678 | |
785 | Populations = 98765432 | |
786 | Coordinates = 192.168 | |
787 | Coordinates = 10.11 | |
788 | Flags = true | |
789 | Flags = false | |
790 | None = | |
740 | 791 | |
741 | 792 | `) |
742 | 793 | }) |