/
loc_test.go
48 lines (40 loc) · 869 Bytes
/
loc_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
package gokatas
import (
"github.com/jgroeneveld/trial/assert"
"testing"
)
func TestGetLOC(t *testing.T) {
codeToTest := `/* this is the code to test
the first lines are a documentation comment
*/
// after this comes a function
func name(params) int {
// indented comment
return 42
}`
loc := GetLOC(codeToTest)
assert.DeepEqual(t, LOCData{
Total: 9,
Code: 3,
Comments: 5,
Whitespace: 1,
}, loc)
}
func TestStripLines(t *testing.T) {
unstripped := `first
second
further in
third`
stripped := `first
second
further in
third`
assert.Equal(t, stripped, stripLines(unstripped))
}
func TestIsWhitespaceLine(t *testing.T) {
assert.True(t, isWhitespaceLine(""))
assert.True(t, isWhitespaceLine(" "))
assert.True(t, isWhitespaceLine(" "))
assert.False(t, isWhitespaceLine(" //"))
assert.False(t, isWhitespaceLine("x //"))
}