package gatecode

import (
	"errors"
	"fmt"
	"github.com/gogf/gf/v2/errors/gcode"
	"github.com/gogf/gf/v2/errors/gerror"
	"runtime"
	"testing"
)

func TestGError(t *testing.T) {
	err := errors.New("1")
	err = gerror.Wrap(err, "2")
	err = gerror.Wrap(err, "3")
	t.Log(err, nil)
	t.Log(fmt.Sprintf("%s", err), "3: 2: 1")
	t.Log(fmt.Sprintf("%v", err), "3: 2: 1")

}

func TestGCode(t *testing.T) {
	err1 := errors.New("permission denied")
	err2 := gerror.WrapCode(gcode.New(10000, "aaaa", nil), err1, "Custom Error")
	fmt.Println(err2.Error())
	fmt.Println(gerror.Code(err2))
	err3 := gerror.Wrap(err2, "sss")
	fmt.Println(err3)
}

func TestGErr(t *testing.T) {
	err := errors.New("permission denied")
	c := gerror.Code(err)
	t.Log(c == gcode.CodeNil)
	t.Log("www", c.Detail())

	cc := gerror.Stack(err)
	t.Log(cc)

	ccc := gerror.Code(nil)
	t.Log(ccc.Detail())
}

func TestErrorCodeIncrease(t *testing.T) {
	c1 := getErrCode(1000)
	c2 := getErrCode(2000)
	for i := 0; i < 10; i++ {
		fmt.Println(c1())
	}
	for i := 0; i < 10; i++ {
		fmt.Println(c2())
	}
}

func TestErrCode(t *testing.T) {
	fmt.Println(runtime.Version())
	fmt.Println("GLOBAL_ERR_NIL =>", GLOBAL_ERR_NIL, int(GLOBAL_ERR_NIL), GLOBAL_ERR_NIL.String())
}
