github.com/gogf/gf/v2@v2.7.4/errors/gcode/gcode_z_unit_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gcode_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/gogf/gf/v2/errors/gcode"
    13  	"github.com/gogf/gf/v2/test/gtest"
    14  )
    15  
    16  func Test_Case(t *testing.T) {
    17  	gtest.C(t, func(t *gtest.T) {
    18  		t.Assert(gcode.CodeNil.String(), "-1")
    19  		t.Assert(gcode.CodeInternalError.String(), "50:Internal Error")
    20  	})
    21  }
    22  
    23  func Test_Nil(t *testing.T) {
    24  	gtest.C(t, func(t *gtest.T) {
    25  		c := gcode.New(1, "custom error", "detailed description")
    26  		t.Assert(c.Code(), 1)
    27  		t.Assert(c.Message(), "custom error")
    28  		t.Assert(c.Detail(), "detailed description")
    29  	})
    30  }
    31  
    32  func Test_WithCode(t *testing.T) {
    33  	gtest.C(t, func(t *gtest.T) {
    34  		c := gcode.WithCode(gcode.CodeInternalError, "CodeInternalError")
    35  		t.Assert(c.Code(), gcode.CodeInternalError.Code())
    36  		t.Assert(c.Detail(), "CodeInternalError")
    37  	})
    38  }