github.com/mailru/activerecord@v1.12.2/pkg/serializer/printf_w_test.go (about) 1 package serializer 2 3 import ( 4 "errors" 5 "reflect" 6 "testing" 7 8 "github.com/mailru/activerecord/pkg/serializer/errs" 9 ) 10 11 func TestPrintfUnmarshal(t *testing.T) { 12 type args struct { 13 val string 14 } 15 tests := []struct { 16 name string 17 args args 18 want float64 19 wantErr error 20 }{ 21 { 22 name: "simple", 23 args: args{val: `1.223`}, 24 want: 1.223, 25 wantErr: nil, 26 }, 27 { 28 name: "err", 29 args: args{val: `{"key": {"nestedkey": "value}}`}, 30 want: 0, 31 wantErr: errs.ErrPrintfParse, 32 }, 33 } 34 for _, tt := range tests { 35 t.Run(tt.name, func(t *testing.T) { 36 var got float64 37 err := PrintfUnmarshal("", tt.args.val, &got) 38 if tt.wantErr != err && !errors.Is(err, tt.wantErr) { 39 t.Errorf("PrintfUnmarshal() error = %v, wantErr %v", err, tt.wantErr) 40 } 41 if tt.wantErr == nil && !reflect.DeepEqual(got, tt.want) { 42 t.Errorf("PrintfUnmarshal() = %v, want %v", got, tt.want) 43 } 44 }) 45 } 46 }