-
Notifications
You must be signed in to change notification settings - Fork 0
/
lll_test.go
76 lines (64 loc) · 2.1 KB
/
lll_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
package lll_test
import (
"bytes"
"path/filepath"
"testing"
"github.com/walle/lll"
)
func TestShouldSkipDirs(t *testing.T) {
skip, ret := lll.ShouldSkip(".git", true, nil, []string{".git"}, false)
if skip == false || ret != filepath.SkipDir {
t.Errorf("Expected %b, %s got. %b, %s", true, filepath.SkipDir, skip, ret)
}
skip, ret = lll.ShouldSkip("dir", true, nil, []string{".git"}, false)
if skip == false || ret != nil {
t.Errorf("Expected %b, %s got. %b, %s", true, nil, skip, ret)
}
}
func TestShouldSkipFiles(t *testing.T) {
skip, ret := lll.ShouldSkip("file.go", false, nil, []string{".git"}, true)
if skip == true || ret != nil {
t.Errorf("Expected %b, %s got. %b, %s", false, nil, skip, ret)
}
skip, ret = lll.ShouldSkip("file", false, nil, []string{".git"}, true)
if skip == false || ret != nil {
t.Errorf("Expected %b, %s got. %b, %s", true, nil, skip, ret)
}
skip, ret = lll.ShouldSkip("lll_test.go", false, nil, []string{".git"}, false)
if skip == true || ret != nil {
t.Errorf("Expected %b, %s got. %b, %s", false, nil, skip, ret)
}
skip, ret = lll.ShouldSkip("file", false, nil, []string{"file"}, false)
if skip == false || ret != nil {
t.Errorf("Expected %b, %s got. %b, %s", true, nil, skip, ret)
}
}
func TestProcess(t *testing.T) {
lines := "one\ntwo\ntree"
b := bytes.NewBufferString("")
err := lll.Process(bytes.NewBufferString(lines), b, "file", 80)
if err != nil {
t.Errorf("Expected %s, got %s", nil, err)
}
expected := "file:3: line is 4 characters\n"
_ = lll.Process(bytes.NewBufferString(lines), b, "file", 3)
if b.String() != expected {
t.Errorf("Expected %s, got %s", expected, b.String())
}
}
func TestProcessFile(t *testing.T) {
b := bytes.NewBufferString("")
err := lll.ProcessFile(b, "lll_test.go", 80)
if err != nil {
t.Errorf("Expected %s, got %s", nil, err)
}
}
func TestProcessUnicode(t *testing.T) {
lines := "日本語\n"
b := bytes.NewBufferString("")
expected := "file:1: line is 3 characters\n"
_ = lll.Process(bytes.NewBufferString(lines), b, "file", 2)
if b.String() != expected {
t.Errorf("Expected %s, got %s", expected, b.String())
}
}