github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/validate/test/Assert.go (about)

     1  package main
     2  
     3  import "testing"
     4  
     5  func True(t *testing.T, value bool) {
     6  	if !value {
     7  		t.Error("expect true, but actual is false")
     8  	}
     9  }
    10  
    11  func TrueErr(t *testing.T, value bool, errMsg string) {
    12  	if !value {
    13  		t.Errorf("expect true, but actual is false, error: %v", errMsg)
    14  	}
    15  }
    16  
    17  func False(t *testing.T, value bool) {
    18  	if value {
    19  		t.Error("expect false, but actual is true")
    20  	}
    21  }
    22  
    23  func FalseMsg(t *testing.T, value bool, msg string) {
    24  	if value {
    25  		t.Error("expect false, but actual is true:" + msg)
    26  	} else {
    27  		t.Log("结果false,信息为:" + msg)
    28  	}
    29  }
    30  
    31  func FalseErr(t *testing.T, value bool, errMsg string) {
    32  	if value {
    33  		t.Errorf("expect false, but actual is true, error: %v", errMsg)
    34  	} else {
    35  		t.Logf("error: %v", errMsg)
    36  	}
    37  }
    38  
    39  // Equal 参数为act-expect-act-expect-...结构,其中expect为期望值,act为实际值
    40  func Equal(t *testing.T, objects ...any) {
    41  	if len(objects)%2 != 0 {
    42  		t.Error("参数个数必须为偶数")
    43  	}
    44  
    45  	for i := 0; i < len(objects); i += 2 {
    46  		if objects[i] != objects[i+1] {
    47  			t.Errorf("期望:%v \n          实际:%v", objects[i+1], objects[i])
    48  		}
    49  	}
    50  }
    51  
    52  func main() {
    53  }