summaryrefslogtreecommitdiff
path: root/spec/parser_spec.lua
blob: f20ae0fa59a77f2c0a5514347209122f74f5ad88 (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
local parser = require "headers.parser"


describe("Scheme", function()
	local headers

	before_each(function()
		headers = parser.new()
	end)

	it("version one is supported", function()
		assert.has_no.errors(function()
			headers:parse [[scheme "headers/1"]]
		end)
	end)

	it("is not required", function()
		assert.has_no.errors(function()
			headers:parse ""
		end)
	end)
end)


describe("Tags", function()
	local headers

	before_each(function()
		headers = parser.new()
	end)

	it("can be created with aliases definition without actual aliases", function()
		headers:parse [[aliases "Example"]]
		assert.are.same({"Example"}, headers:get_tags())
	end)

	it("can be created with aliases definition", function()
		headers:parse [[aliases "Example" {"Alias for Example"}]]
		assert.are.same({"Example"}, headers:get_tags())
	end)

	it("can be created with headers definition", function()
		headers:parse [[headers "Example" {"example.h"}]]
		assert.are.same({"Example"}, headers:get_tags())
	end)
end)


describe("Headers", function()
	local headers

	before_each(function()
		headers = parser.new()
	end)

	it("are not available if never assigned", function()
		headers:parse [[]]
		assert.is_nil(headers:get_headers("Example"))
	end)

	it("can be assigned to a tag", function()
		headers:parse [[headers "Example" {"example.h"}]]
		assert.are.same({"example.h"}, headers:get_headers("Example"))
	end)

	it("can be included from another tag", function()
		headers:parse [[
			headers "Parent" {"example.h"}
			headers "Derived" {include "Parent"}
		]]
		assert.are.same({"example.h"}, headers:get_headers("Derived"))
	end)

	it("can be removed after including from another tag", function()
		headers:parse [[
			headers "Parent" {"example.h", "removed.h"}
			headers "Derived" {include "Parent", remove "removed.h"}
		]]
		assert.are.same({"example.h"}, headers:get_headers("Derived"))
	end)
end)