-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_value_test.go
More file actions
64 lines (53 loc) · 1.46 KB
/
check_value_test.go
File metadata and controls
64 lines (53 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package done
import (
"testing"
"github.com/stretchr/testify/require"
)
// TestGood tests the Good function with non-zero values.
// TestGood 测试 Good 函数处理非零值。
func TestGood(t *testing.T) {
Good(&Example{})
Good(Example{S: "xyz"})
}
// TestNice tests the Nice function returns non-zero values.
// TestNice 测试 Nice 函数返回非零值。
func TestNice(t *testing.T) {
a := Nice(Example{S: "abc"})
require.Equal(t, "abc", a.S)
p := Nice(&Example{S: "uvw"})
require.Equal(t, "uvw", p.S)
}
// TestZero tests the Zero function with zero values.
// TestZero 测试 Zero 函数处理零值。
func TestZero(t *testing.T) {
Zero((*Example)(nil))
Zero(Example{})
}
// Example is a test struct with a string field.
// Example 是包含字符串字段的测试结构体。
type Example struct {
S string
}
// newExample creates a new Example instance.
// newExample 创建一个新的 Example 实例。
func newExample() (*Example, error) {
return &Example{S: "xyz"}, nil
}
// TestNull tests the Null function ensures pointer is nil.
// TestNull 测试 Null 函数确保指针是 nil。
func TestNull(t *testing.T) {
var example *Example
Null(example)
require.Panics(t, func() {
Null(&Example{S: "abc"})
})
}
// TestFull tests the Full function ensures pointer is not nil.
// TestFull 测试 Full 函数确保指针非 nil。
func TestFull(t *testing.T) {
Full(&Example{S: "abc"})
require.Panics(t, func() {
var example *Example
Full(example)
})
}