forked from the4thamigo-uk/nocov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
85 lines (71 loc) · 1.91 KB
/
main_test.go
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
package main
import (
"testing"
"golang.org/x/tools/cover"
)
func TestMain_NewBlock(t *testing.T) {
block := newBlock(1, 2, 3, 4)
valid := block.StartLine == 1 &&
block.StartCol == 2 &&
block.EndLine == 3 &&
block.EndCol == 4 &&
block.NumStmt == 0 &&
block.Count == 0
if !valid {
t.Error("block constructed correctly")
}
}
func TestMain_IsWithin_SameBlock(t *testing.T) {
if !isWithin(newBlock(1, 5, 10, 10), newBlock(1, 5, 10, 10)) {
t.Error("block within itself")
}
}
func TestMain_IsWithin_Lines(t *testing.T) {
if !isWithin(newBlock(2, 5, 9, 5), newBlock(1, 5, 10, 5)) {
t.Error("block within lines")
}
}
func TestMain_IsWithin_OverlapStartCol(t *testing.T) {
if isWithin(newBlock(1, 4, 10, 5), newBlock(1, 5, 10, 5)) {
t.Error("block overlapping start column")
}
}
func TestMain_IsWithin_OverlapEndCol(t *testing.T) {
if isWithin(newBlock(1, 5, 10, 6), newBlock(1, 5, 10, 5)) {
t.Error("block overlapping end column")
}
}
func TestMain_IsWithin_OverlapStartLine(t *testing.T) {
if isWithin(newBlock(1, 5, 10, 5), newBlock(2, 5, 10, 5)) {
t.Error("block overlapping start line")
}
}
func TestMain_IsWithin_OverlapEndLine(t *testing.T) {
if isWithin(newBlock(1, 5, 11, 6), newBlock(1, 5, 10, 5)) {
t.Error("block overlapping end line")
}
}
func TestMain_IsWithin_DisjointLines(t *testing.T) {
if isWithin(newBlock(1, 5, 5, 5), newBlock(6, 5, 10, 5)) {
t.Error("disjoint lines")
}
}
func TestMain_IsWithin_DisjointColumns(t *testing.T) {
if isWithin(newBlock(1, 5, 5, 5), newBlock(5, 6, 10, 5)) {
t.Error("disjoint lines")
}
}
func TestMain_IsWithin_PrintProfile(t *testing.T) {
profile := cover.Profile{
FileName: "FILENAME",
Mode: "MODE",
Blocks: []cover.ProfileBlock{
*newBlock(1, 5, 10, 15),
*newBlock(11, 5, 20, 15),
},
}
out := printProfile(&profile)
if out != "FILENAME:1.5,10.15 0 0\nFILENAME:11.5,20.15 0 0\n" {
t.Errorf("print cover profile: %s", out)
}
}