package utils

import (
	"testing"
	"time"
)

func TestNOPanicWrap(t *testing.T) {
	type args struct {
		name string
		f    func() error
	}
	tests := []struct {
		name    string
		args    args
		wantErr bool
	}{
		{
			"OK",
			args{
				name: "OK_test",
				f: func() error {
					time.Sleep(time.Second)
					return nil
				},
			},
			false,
		},
		{
			"Panic",
			args{
				name: "Panic_test",
				f: func() error {
					panic("test panic")
				},
			},
			true,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := NOPanicWrap(tt.args.name, tt.args.f)(); (got != nil) != tt.wantErr {
				t.Errorf("NOPanicWrap() = %v, wantErr %v", got, tt.wantErr)
			}
		})
	}
}

func TestIsNil(t *testing.T) {
	type args struct {
		x any
	}
	tests := []struct {
		name string
		args args
		want bool
	}{
		{
			name: "nil OK",
			args: args{
				x: nil,
			},
			want: true,
		},
		{
			name: "nil ptr OK",
			args: args{
				x: (*int)(nil),
			},
			want: true,
		},
		{
			name: "nil map OK",
			args: args{
				x: (map[string]any)(nil),
			},
			want: true,
		},
		{
			name: "Not OK",
			args: args{
				x: struct{}{},
			},
			want: false,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := IsNil(tt.args.x); got != tt.want {
				t.Errorf("IsNil() = %v, want %v", got, tt.want)
			}
		})
	}
}
