-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathextract_end_test.go
More file actions
94 lines (90 loc) · 1.82 KB
/
extract_end_test.go
File metadata and controls
94 lines (90 loc) · 1.82 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package bix
import (
"testing"
)
func TestExtractEndValue(t *testing.T) {
tests := []struct {
name string
info string
expected int
hasError bool
}{
{
name: "END at beginning of INFO",
info: "END=12345",
expected: 12345,
hasError: false,
},
{
name: "END at end of INFO",
info: "SVTYPE=DEL;SVLEN=-1000;END=12345",
expected: 12345,
hasError: false,
},
{
name: "END in middle of INFO",
info: "SVTYPE=DEL;END=12345;SVLEN=-1000",
expected: 12345,
hasError: false,
},
{
name: "END at beginning with multiple fields",
info: "END=54321;SVTYPE=DUP;SVLEN=2000",
expected: 54321,
hasError: false,
},
{
name: "No END field",
info: "SVTYPE=DEL;SVLEN=-1000;AC=1",
expected: 0,
hasError: true,
},
{
name: "Invalid END value",
info: "SVTYPE=DEL;END=not_a_number;AC=1",
expected: 0,
hasError: true,
},
{
name: "Empty INFO field",
info: "",
expected: 0,
hasError: true,
},
{
name: "END with zero value",
info: "SVTYPE=DEL;END=0",
expected: 0,
hasError: false,
},
{
name: "END field only",
info: "END=999",
expected: 999,
hasError: false,
},
{
name: "Multiple semicolons after END",
info: "SVTYPE=DEL;END=8888;AC=2;AF=0.5",
expected: 8888,
hasError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := extractEndValue(tt.info)
if tt.hasError {
if err == nil {
t.Errorf("expected error but got none for input: %s", tt.info)
}
} else {
if err != nil {
t.Errorf("unexpected error for input %s: %v", tt.info, err)
}
if result != tt.expected {
t.Errorf("expected %d but got %d for input: %s", tt.expected, result, tt.info)
}
}
})
}
}