This file is indexed.

/usr/share/gocode/src/github.com/constabulary/gb/internal/depfile/depfile_test.go is in golang-github-constabulary-gb-dev 0.4.4-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package depfile

import (
	"fmt"
	"reflect"
	"strings"
	"testing"
)

func TestParseKeyVal(t *testing.T) {
	tests := []struct {
		args []string
		want map[string]string
		err  error
	}{{
		args: []string{},          // handled by Parse
		want: map[string]string{}, // expected
	}, {
		args: []string{"version"},
		err:  fmt.Errorf("expected key=value pair, got %q", "version"),
	}, {
		args: []string{"=9.9.9"},
		err:  fmt.Errorf("expected key=value pair, missing key %q", "=9.9.9"),
	}, {
		args: []string{"version="},
		err:  fmt.Errorf("expected key=value pair, missing value %q", "version="),
	}, {
		args: []string{"version=1.2.3"},
		want: map[string]string{
			"version": "1.2.3",
		},
	}, {
		args: []string{"version=1.2.3", "version=2.4.5"},
		err:  fmt.Errorf("duplicate key=value pair, have \"version=1.2.3\" got %q", "version=2.4.5"),
	}, {
		args: []string{"version=1.2.3", "//", "comment"},
		err:  fmt.Errorf("expected key=value pair, got %q", "//"),
	}, {
		args: []string{"vcs=git", "version=1.2.3"},
		want: map[string]string{
			"version": "1.2.3",
			"vcs":     "git",
		},
	}}

	for _, tt := range tests {
		got, err := parseKeyVal(tt.args)
		if !reflect.DeepEqual(err, tt.err) {
			t.Errorf("parseKeyVal(%v): got %v, expected %v", tt.args, err, tt.err)
			continue
		}
		if err == nil && !reflect.DeepEqual(tt.want, got) {
			t.Errorf("parseKeyVal(%v): got %#v, expected %#v", tt.args, got, tt.want)
		}
	}
}

func TestParseLine(t *testing.T) {
	tests := []struct {
		line string
		name string
		kv   map[string]string
		err  error
	}{{
		line: "a", // no \n, sc.Text removes it
		err:  fmt.Errorf("a: expected key=value pair after name"),
	}, {
		line: "a\ta",
		err:  fmt.Errorf("a: expected key=value pair, got %q", "a"),
	}, {
		line: "a\tversion=7\t  ",
		name: "a",
		kv: map[string]string{
			"version": "7",
		},
	}}

	for _, tt := range tests {
		name, kv, err := parseLine(tt.line)
		if !reflect.DeepEqual(err, tt.err) {
			t.Errorf("parseLine(%q): got %v, expected %v", tt.line, err, tt.err)
			continue
		}
		if err == nil && !reflect.DeepEqual(tt.kv, kv) || name != tt.name {
			t.Errorf("parseLine(%q): got %s %#v, expected %s %#v", tt.line, name, kv, tt.name, tt.kv)
		}
	}
}

func TestParse(t *testing.T) {
	tests := []struct {
		c    string
		want map[string]map[string]string
		err  error
	}{{
		c:    "",                                 // empty
		want: make(map[string]map[string]string), // empty map, not nil
	}, {
		c:    "\n",                               // effectively empty
		want: make(map[string]map[string]string), // empty map, not nil
	}, {
		c:   "github.com/pkg/profile", // no \n
		err: fmt.Errorf("1: github.com/pkg/profile: expected key=value pair after name"),
	}, {
		c:   "github.com/pkg/profile\n",
		err: fmt.Errorf("1: github.com/pkg/profile: expected key=value pair after name"),
	}, {
		c: "github.com/pkg/profile version=1.2.3", // no \n
		want: map[string]map[string]string{
			"github.com/pkg/profile": {
				"version": "1.2.3",
			},
		},
	}, {
		c: "github.com/pkg/profile version=1.2.3\n",
		want: map[string]map[string]string{
			"github.com/pkg/profile": {
				"version": "1.2.3",
			},
		},
	}, {
		c: "// need to pin version\ngithub.com/pkg/profile version=1.2.3\n",
		want: map[string]map[string]string{
			"github.com/pkg/profile": {
				"version": "1.2.3",
			},
		},
	}, {
		c: "github.com/pkg/profile version=1.2.3\ngithub.com/pkg/sftp version=0.0.0",
		want: map[string]map[string]string{
			"github.com/pkg/profile": {
				"version": "1.2.3",
			},
			"github.com/pkg/sftp": {
				"version": "0.0.0",
			},
		},
	}, {
		c: `# some comment
github.com/pkg/profile version=0.1.0

; some other comment
// third kind of comment
 lines starting with blank lines are also ignored
github.com/pkg/sftp version=0.2.1
`,
		want: map[string]map[string]string{
			"github.com/pkg/profile": {
				"version": "0.1.0",
			},
			"github.com/pkg/sftp": {
				"version": "0.2.1",
			},
		},
	}}

	for _, tt := range tests {
		r := strings.NewReader(tt.c)
		got, err := Parse(r)
		if !reflect.DeepEqual(err, tt.err) {
			t.Errorf("Parse(%q): got %v, expected %v", tt.c, err, tt.err)
			continue
		}
		if err == nil && !reflect.DeepEqual(tt.want, got) {
			t.Errorf("Parse(%q): got %#v, expected %#v", tt.c, got, tt.want)
		}
	}
}

func TestSplitLine(t *testing.T) {
	tests := []struct {
		s    string
		want []string
	}{
		{s: "", want: nil},
		{s: "a", want: []string{"a"}},
		{s: " a", want: []string{"a"}},
		{s: "a ", want: []string{"a"}},
		{s: "a b", want: []string{"a", "b"}},
		{s: "a b", want: []string{"a", "b"}},
		{s: "a\tb", want: []string{"a", "b"}},
		{s: "a \tb", want: []string{"a", "b"}},
		{s: "\ta \tb ", want: []string{"a", "b"}},
	}

	for _, tt := range tests {
		got := splitLine(tt.s)
		if !reflect.DeepEqual(got, tt.want) {
			t.Errorf("splitLine(%q): got %#v, expected %#v", tt.s, got, tt.want)
		}
	}
}