This file is indexed.

/usr/share/gocode/src/github.com/glacjay/goini/ini_test.go is in golang-github-glacjay-goini-dev 0.0~git20150730-1.

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
package ini

import (
	"io/ioutil"
	"testing"
	"strings"
	"bufio"
)

var (
	dict Dict
	err  error
)

func init() {
	dict, err = Load("example.ini")
}

func TestLoad(t *testing.T) {
	if err != nil {
		t.Error("Example: load error:", err)
	}
}

func TestWrite(t *testing.T) {
	d, err := Load("empty.ini")
	if err != nil {
		t.Error("Example: load error:", err)
	}
	d.SetString("", "key", "value")
	tempFile, err := ioutil.TempFile("", "")
	if err != nil {
		t.Error("Write: Couldn't create temp file.", err)
	}
	err = Write(tempFile.Name(), &d)
	if err != nil {
		t.Error("Write: Couldn't write to temp config file.", err)
	}
	contents, err := ioutil.ReadFile(tempFile.Name())
	if err != nil {
		t.Error("Write: Couldn't read from the temp config file.", err)
	}
	if string(contents) != "key = value\n\n" {
		t.Error("Write: Contents of the config file doesn't match the expected.")
	}
}

func TestGetBool(t *testing.T) {
	b, found := dict.GetBool("pizza", "ham")
	if !found || !b {
		t.Error("Example: parse error for key ham of section pizza.")
	}
	b, found = dict.GetBool("pizza", "mushrooms")
	if !found || !b {
		t.Error("Example: parse error for key mushrooms of section pizza.")
	}
	b, found = dict.GetBool("pizza", "capres")
	if !found || b {
		t.Error("Example: parse error for key capres of section pizza.")
	}
	b, found = dict.GetBool("pizza", "cheese")
	if !found || b {
		t.Error("Example: parse error for key cheese of section pizza.")
	}
}

func TestGetStringIntAndDouble(t *testing.T) {
	str, found := dict.GetString("wine", "grape")
	if !found || str != "Cabernet Sauvignon" {
		t.Error("Example: parse error for key grape of section wine.")
	}
	i, found := dict.GetInt("wine", "year")
	if !found || i != 1989 {
		t.Error("Example: parse error for key year of section wine.")
	}
	str, found = dict.GetString("wine", "country")
	if !found || str != "Spain" {
		t.Error("Example: parse error for key grape of section wine.")
	}
	d, found := dict.GetDouble("wine", "alcohol")
	if !found || d != 12.5 {
		t.Error("Example: parse error for key grape of section wine.")
	}
}

func TestSetBoolAndStringAndIntAndDouble(t *testing.T) {
	dict.SetBool("pizza", "ham", false)
	b, found := dict.GetBool("pizza", "ham")
	if !found || b {
		t.Error("Example: bool set error for key ham of section pizza.")
	}
	dict.SetString("pizza", "ham", "no")
	n, found := dict.GetString("pizza", "ham")
	if !found || n != "no" {
		t.Error("Example: string set error for key ham of section pizza.")
	}
	dict.SetInt("wine", "year", 1978)
	i, found := dict.GetInt("wine", "year")
	if !found || i != 1978 {
		t.Error("Example: int set error for key year of section wine.")
	}
	dict.SetDouble("wine", "not-exists", 5.6)
	d, found := dict.GetDouble("wine", "not-exists")
	if !found || d != 5.6 {
		t.Error("Example: float set error for not existing key for wine.")
	}
}

func TestDelete(t *testing.T) {
	d, err := Load("empty.ini")
	if err != nil {
		t.Error("Example: load error:", err)
	}
	d.SetString("pizza", "ham", "yes")
	d.Delete("pizza", "ham")
	_, found := d.GetString("pizza", "ham")
	if found {
		t.Error("Example: delete error for key ham of section pizza.")
	}
	if len(d.GetSections()) > 1 {
		t.Error("Only a single section should exist after deletion.")
	}
}

func TestGetNotExist(t *testing.T) {
	_, found := dict.GetString("not", "exist")
	if found {
		t.Error("There is no key exist of section not.")
	}
}

func TestGetSections(t *testing.T) {
	sections := dict.GetSections()
	if len(sections) != 3 {
		t.Error("The number of sections is wrong:", len(sections))
	}
	for _, section := range sections {
		if section != "" && section != "pizza" && section != "wine" {
			t.Errorf("Section '%s' should not be exist.", section)
		}
	}
}

func TestString(t *testing.T) {
	d, err := Load("empty.ini")
	if err != nil {
		t.Error("Example: load error:", err)
	}
	d.SetBool("", "key1", true)
	d.SetString("section1", "key1", "value2")
	d.SetInt("section1", "key2", 5)
	d.SetDouble("section1", "key3", 1.3)
	d.SetDouble("section2", "key1", 5.0)
	reader := strings.NewReader(d.String())
	d2, err := LoadReader(bufio.NewReader(reader))
	if err != nil {
		t.Error("Example: load error:", err)
	}
	b, found := d2.GetBool("", "key1")
	if !found || !b {
		t.Errorf("Stringify failed for key1")
	}
	s, found := d2.GetString("section1", "key1")
	if !found || s != "value2" {
	        t.Error("Stringify failed for section1, key1")
	}
	i, found := d2.GetInt("section1", "key2")
	if !found || i != 5 {
	        t.Error("Stringify failed for section1, key2")
	}
	db, found := d2.GetDouble("section1", "key3")
	if !found || db != 1.3 {
	        t.Error("Stringify failed for section1, key3")
	}
	db, found = d2.GetDouble("section2", "key1")
	if !found || db != 5.0 {
	        t.Error("Stringify failed for section2, key1")
	}
}