-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfixed_string_test.go
More file actions
57 lines (52 loc) · 1001 Bytes
/
fixed_string_test.go
File metadata and controls
57 lines (52 loc) · 1001 Bytes
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
package ecs
import (
"bufio"
"fmt"
"os"
"testing"
)
func TestFixedString_Generate(t *testing.T) {
return
filePath := "./fixed_string_utils.go"
file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println("文件打开失败", err)
}
defer file.Close()
write := bufio.NewWriter(file)
h1 := `package ecs
`
write.WriteString(h1)
h2 := "type Fixed%d [%d]byte\n"
for i := 1; i < 129; i++ {
write.WriteString(fmt.Sprintf(h2, i, i))
}
write.Flush()
}
func TestFixedString_String(t *testing.T) {
tests := []struct {
name string
arg string
want string
}{
{
name: "test",
arg: "hello world",
want: "hello world",
},
{
name: "test1",
arg: "hello 中文 ☺",
want: "hello 中文 ☺",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := FixedString[Fixed128]{}
f.Set(tt.arg)
if got := f.String(); got != tt.want {
t.Errorf("String() = %v, want %v", got, tt.want)
}
})
}
}