-
Notifications
You must be signed in to change notification settings - Fork 128
/
repo_grep_test.go
144 lines (137 loc) · 3.4 KB
/
repo_grep_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright 2022 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package git
import (
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRepository_Grep_Simple(t *testing.T) {
want := []*GrepResult{
{
Tree: "HEAD",
Path: "src/Main.groovy",
Line: 7,
Column: 5,
Text: "int programmingPoints = 10",
}, {
Tree: "HEAD",
Path: "src/Main.groovy",
Line: 10,
Column: 33,
Text: `println "${name} has at least ${programmingPoints} programming points."`,
}, {
Tree: "HEAD",
Path: "src/Main.groovy",
Line: 11,
Column: 12,
Text: `println "${programmingPoints} squared is ${square(programmingPoints)}"`,
}, {
Tree: "HEAD",
Path: "src/Main.groovy",
Line: 12,
Column: 12,
Text: `println "${programmingPoints} divided by 2 bonus points is ${divide(programmingPoints, 2)}"`,
}, {
Tree: "HEAD",
Path: "src/Main.groovy",
Line: 13,
Column: 12,
Text: `println "${programmingPoints} minus 7 bonus points is ${subtract(programmingPoints, 7)}"`,
}, {
Tree: "HEAD",
Path: "src/Main.groovy",
Line: 14,
Column: 12,
Text: `println "${programmingPoints} plus 3 bonus points is ${sum(programmingPoints, 3)}"`,
},
}
got := testrepo.Grep("programmingPoints")
assert.Equal(t, want, got)
}
func TestRepository_Grep_IgnoreCase(t *testing.T) {
want := []*GrepResult{
{
Tree: "HEAD",
Path: "README.txt",
Line: 9,
Column: 36,
Text: "* [email protected]:matthewmccullough/hellogitworld.git",
}, {
Tree: "HEAD",
Path: "README.txt",
Line: 10,
Column: 38,
Text: "* git://github.com/matthewmccullough/hellogitworld.git",
}, {
Tree: "HEAD",
Path: "README.txt",
Line: 11,
Column: 58,
Text: "* https://[email protected]/matthewmccullough/hellogitworld.git",
}, {
Tree: "HEAD",
Path: "src/Main.groovy",
Line: 9,
Column: 10,
Text: `println "Hello ${name}"`,
}, {
Tree: "HEAD",
Path: "src/main/java/com/github/App.java",
Line: 4,
Column: 4,
Text: " * Hello again",
}, {
Tree: "HEAD",
Path: "src/main/java/com/github/App.java",
Line: 5,
Column: 4,
Text: " * Hello world!",
}, {
Tree: "HEAD",
Path: "src/main/java/com/github/App.java",
Line: 6,
Column: 4,
Text: " * Hello",
}, {
Tree: "HEAD",
Path: "src/main/java/com/github/App.java",
Line: 13,
Column: 30,
Text: ` System.out.println( "Hello World!" );`,
},
}
got := testrepo.Grep("Hello", GrepOptions{IgnoreCase: true})
assert.Equal(t, want, got)
}
func TestRepository_Grep_ExtendedRegexp(t *testing.T) {
if runtime.GOOS == "darwin" {
t.Skip("Skipping testing on macOS")
return
}
want := []*GrepResult{
{
Tree: "HEAD",
Path: "src/main/java/com/github/App.java",
Line: 13,
Column: 30,
Text: ` System.out.println( "Hello World!" );`,
},
}
got := testrepo.Grep(`Hello\sW\w+`, GrepOptions{ExtendedRegexp: true})
assert.Equal(t, want, got)
}
func TestRepository_Grep_WordRegexp(t *testing.T) {
want := []*GrepResult{
{
Tree: "HEAD",
Path: "src/main/java/com/github/App.java",
Line: 5,
Column: 10,
Text: ` * Hello world!`,
},
}
got := testrepo.Grep("world", GrepOptions{WordRegexp: true})
assert.Equal(t, want, got)
}