summaryrefslogtreecommitdiff
path: root/srcinfo_spec.lua
blob: 231290523554de3f4c18200708ad97e0b603caa3 (plain)
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
local srcinfo = require "srcinfo"
local stx = require "pl.stringx"


describe("Empty strings ared parsed successfully in", function()
	it("pkgname mode", function()
		assert.are.same({}, srcinfo"")
		assert.are.same({}, srcinfo"\n")
		assert.are.same({}, srcinfo" ")
		assert.are.same({}, srcinfo"\n ")
		assert.are.same({}, srcinfo" \n")
		assert.are.same({}, srcinfo" \n ")
	end)

	it("pkgbase mode", function()
		assert.are.same({}, srcinfo("", {mode="pkgbase"}))
		assert.are.same({}, srcinfo("\n", {mode="pkgbase"}))
		assert.are.same({}, srcinfo(" ", {mode="pkgbase"}))
		assert.are.same({}, srcinfo("\n ", {mode="pkgbase"}))
		assert.are.same({}, srcinfo(" \n", {mode="pkgbase"}))
		assert.are.same({}, srcinfo(" \n ", {mode="pkgbase"}))
	end)
end)


describe("Parses name-only .SRCINFO in", function()
	describe("pkgname mode (default) with", function()
		it("one package", function()
			local pkgs = srcinfo(stx.dedent[[
				pkgbase = example
				pkgname = example
			]])
			assert.are.same("example", pkgs[1].name)
			assert.are.same("example", pkgs[1].base.name)
			assert.is_nil(pkgs[2])
		end)

		it("multiple packages", function()
			local pkgs = srcinfo(stx.dedent[[
				pkgbase = example
				pkgname = example
				pkgname = example-b
				pkgname = example-c
			]])
			assert.are.same("example", pkgs[1].name)
			assert.are.same("example-b", pkgs[2].name)
			assert.are.same("example-c", pkgs[3].name)
			assert.are.same("example", pkgs[1].base.name)
			assert.are.equal(pkgs[1].base, pkgs[2].base)
			assert.are.equal(pkgs[1].base, pkgs[3].base)
			assert.is_nil(pkgs[4])
		end)
	end)

	describe("pkgbase mode with", function()
		it("one package", function()
			local bases = srcinfo(stx.dedent[[
				pkgbase = example
				pkgname = example
			]], {mode="pkgbase"})
			assert.are.same("example", bases[1].name)
			assert.are.same("example", bases[1].packages[1].name)
			assert.is_nil(bases[2])
			assert.is_nil(bases[1].packages[2])
		end)

		it("multiple packages", function()
			local bases = srcinfo(stx.dedent[[
				pkgbase = example
				pkgname = example
				pkgname = example-b
				pkgname = example-c
			]], {mode="pkgbase"})
			assert.are.same("example", bases[1].name)
			assert.are.same("example", bases[1].packages[1].name)
			assert.are.same("example-b", bases[1].packages[2].name)
			assert.are.same("example-c", bases[1].packages[3].name)
			assert.is_nil(bases[2])
			assert.is_nil(bases[1].packages[4])
		end)
	end)
end)


describe("Default mode is", function()
	it("pkgname", function()
		local default = srcinfo(stx.dedent[[
			pkgbase = example
			pkgname = example
		]])
		local explicit = srcinfo(stx.dedent[[
			pkgbase = example
			pkgname = example
		]], {mode="pkgname"})
		assert.are.same(default, explicit)
	end)
end)


describe("Indentation does not matter", function()
	local conventional = srcinfo(stx.dedent[[
		pkgbase = example
			pkgdesc = Example package
			pkgver = 1.0.0
			pkgrel = 1
			arch = any
			license = BSD-3

		pkgname = example

		pkgname = example-bonus
			depends = lua
	]])

	it("for fields", function()
		assert.are.same(conventional, srcinfo(stx.dedent[[
			pkgbase = example
			pkgdesc = Example package
			pkgver = 1.0.0
			pkgrel = 1
			arch = any
			license = BSD-3
			pkgname = example
			pkgname = example-bonus
			depends = lua
		]]))
	end)

	it("between sections", function()
		assert.are.same(conventional, srcinfo(stx.dedent[[
			pkgbase = example
				pkgdesc = Example package
				pkgver = 1.0.0
				pkgrel = 1
				arch = any
				license = BSD-3
				pkgname = example
					pkgname = example-bonus
			depends = lua
		]]))
	end)
end)


describe("Parses multiple .SRCINFO in the same context in", function()
	it("pkgname mode (default)", function()
		local pkgs = srcinfo(stx.dedent[[
			pkgbase = example
			pkgname = example
			pkgbase = sample
			pkgname = sample
		]])
		assert.are.same("example", pkgs[1].name)
		assert.are.same("example", pkgs[1].base.name)
		assert.are.same("sample", pkgs[2].name)
		assert.are.same("sample", pkgs[2].base.name)
	end)

	it("pkgbase mode", function()
		local bases = srcinfo(stx.dedent[[
			pkgbase = example
			pkgname = example
			pkgbase = sample
			pkgname = sample
		]], {mode="pkgbase"})
		assert.are.same("example", bases[1].name)
		assert.are.same("example", bases[1].packages[1].name)
		assert.are.same("sample", bases[2].name)
		assert.are.same("sample", bases[2].packages[1].name)
	end)
end)


describe("Comments", function()
	it("are ignored", function()
		local pkgs = srcinfo(stx.dedent[[
			pkgbase = example
				#arch = any

			pkgname = example

			# pkgname = sample
		]])
		assert.are.same("example", pkgs[1].name)
		assert.is_nil(pkgs[1].base.arch)
		assert.is_nil(pkgs[2])
	end)

	it("work only if they are the first thing in the line", function()
		local pkgs = srcinfo(stx.dedent[[
			pkgbase = example
				pkgdesc = I like #hiking

			pkgname = example
		]])
		assert.are.same("I like #hiking", pkgs[1].base.pkgdesc)
	end)
end)


describe("Fields are parsed into", function()
	it("simple values", function()
		local pkgs = srcinfo(stx.dedent[[
			pkgbase = example
				pkgdesc = Example package
				pkgver = 1.0.0
				pkgrel = 1
				arch = any

			pkgname = example
		]])
		assert.are.same("example", pkgs[1].base.name)
		assert.are.same("Example package", pkgs[1].base.pkgdesc)
		assert.are.same("1.0.0", pkgs[1].base.pkgver)
		assert.are.same("1", pkgs[1].base.pkgrel)
		assert.are.same("any", pkgs[1].base.arch)
	end)

	it("composite values", function()
		local pkgs = srcinfo(stx.dedent[[
			pkgbase = example
				depends = library
				depends = utility

			pkgname = example
		]])
		assert.are.same({"library", "utility"}, pkgs[1].base.depends)
	end)
end)


describe("Packages can access base", function()
	it("simple value fields", function()
		local pkgs = srcinfo(stx.dedent[[
			pkgbase = example
				arch = any
			pkgname = example
		]])
		assert.are.same("any", pkgs[1].arch)
	end)

	it("composite value fields", function()
		local pkgs = srcinfo(stx.dedent[[
			pkgbase = example
				depends = library
				depends = utility
			pkgname = example
		]])
		assert.are.same({"library", "utility"}, pkgs[1].depends)
	end)
end)


describe("Composite fields are", function()
	it("extended", function()
		local pkgs = srcinfo(stx.dedent[[
			pkgbase = example
				depends = library
			pkgname = example
				depends = utility
			pkgname = example-b
				depends = special
		]])
		assert.are.same("library", pkgs[1].base.depends)
		assert.are.same({"library", "utility"}, pkgs[1].depends)
		assert.are.same({"library", "special"}, pkgs[2].depends)
	end)

	it("separated", function()
		local pkgs = srcinfo(stx.dedent[[
			pkgbase = example
				depends = library
				depends = module
			pkgname = example
				depends = utility
			pkgname = example-b
				depends = special
		]])
		assert.are.same({"library", "module"}, pkgs[1].base.depends)
		assert.are.same({"library", "module", "utility"}, pkgs[1].depends)
		assert.are.same({"library", "module", "special"}, pkgs[2].depends)
	end)
end)