github.com/LanderTome/numerologyCalculator@v1.0.2/numerology/opts_test.go (about) 1 // Copyright 2021 Robert D. Wukmir 2 // This file is subject to the terms and conditions defined in 3 // the LICENSE file, which is part of this source code package. 4 // 5 // Unless required by applicable law or agreed to in writing, 6 // software distributed under the License is distributed on an 7 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 // either express or implied. See the License for the specific 9 // language governing permissions and limitations under the 10 // License. 11 12 package numerology 13 14 import ( 15 "reflect" 16 "testing" 17 ) 18 19 func TestGender_MarshalJSON(t *testing.T) { 20 tests := []struct { 21 name string 22 g Gender 23 want []byte 24 wantErr bool 25 }{ 26 {"Marshal Gender M", 'M', []byte("\"M\""), false}, 27 {"Marshal Gender F", 'F', []byte("\"F\""), false}, 28 {"Marshal Gender B", 'B', []byte("\"B\""), false}, 29 } 30 for _, tt := range tests { 31 t.Run(tt.name, func(t *testing.T) { 32 got, err := tt.g.MarshalJSON() 33 if (err != nil) != tt.wantErr { 34 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr) 35 return 36 } 37 if !reflect.DeepEqual(got, tt.want) { 38 t.Errorf("MarshalJSON() got = %v, want %v", got, tt.want) 39 } 40 }) 41 } 42 } 43 44 func TestGender_UnmarshalJSON(t *testing.T) { 45 type args struct { 46 value []byte 47 } 48 tests := []struct { 49 name string 50 g Gender 51 args args 52 wantErr bool 53 }{ 54 {"Unmarshal Gender", 'F', args{[]byte("\"F\"")}, false}, 55 {"Unmarshal Male", 'M', args{[]byte("\"Male\"")}, false}, 56 {"Unmarshal Female", 'F', args{[]byte("\"Female\"")}, false}, 57 {"Unmarshal Both", 'B', args{[]byte("\"B\"")}, false}, 58 {"Unmarshal Unknown", 'B', args{[]byte("\"Something\"")}, true}, 59 } 60 for _, tt := range tests { 61 t.Run(tt.name, func(t *testing.T) { 62 if err := tt.g.UnmarshalJSON(tt.args.value); (err != nil) != tt.wantErr { 63 t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) 64 } 65 }) 66 } 67 }