-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembedded_clone_test.go
More file actions
42 lines (37 loc) · 1.07 KB
/
Copy pathembedded_clone_test.go
File metadata and controls
42 lines (37 loc) · 1.07 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
package jsonkit
import "testing"
func TestCloneEmbeddedBlockDeepCopy(t *testing.T) {
in := EmbeddedBlock{
Start: 1,
End: 9,
Terminators: [][]byte{[]byte("END")},
HookCodes: []string{"A"},
}
out := cloneEmbeddedBlock(in)
if out.Start != in.Start || out.End != in.End {
t.Fatalf("scalar fields not preserved")
}
if len(out.Terminators) != 1 || string(out.Terminators[0]) != "END" {
t.Fatalf("unexpected cloned terminators: %+v", out.Terminators)
}
if len(out.HookCodes) != 1 || out.HookCodes[0] != "A" {
t.Fatalf("unexpected cloned hook codes: %+v", out.HookCodes)
}
in.Terminators[0][0] = 'X'
in.HookCodes[0] = "B"
if string(out.Terminators[0]) != "END" {
t.Fatalf("terminator was not deep-copied")
}
if out.HookCodes[0] != "A" {
t.Fatalf("hook codes were not copied")
}
}
func TestCloneEmbeddedBlockEmptySlices(t *testing.T) {
out := cloneEmbeddedBlock(EmbeddedBlock{})
if out.Terminators != nil {
t.Fatalf("expected nil terminators for empty input")
}
if out.HookCodes != nil {
t.Fatalf("expected nil hook codes for empty input")
}
}