Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_tree.lua « base « tests - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7435bd98eea314491e9615f74806f11acd7c19cc (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
--
-- tests/base/test_tree.lua
-- Automated test suite source code tree handling.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--

	T.tree = { }
	local tree = premake.tree


--
-- Setup/teardown
--

	local tr, nodes
			
	function T.tree.setup()
		tr = tree.new()
		nodes = { }
	end

	local function getresult()
		tree.traverse(tr, {
			onnode = function(node, depth)
				table.insert(nodes, string.rep(".", depth) .. node.name)
			end
		})
		return table.concat(nodes)
	end

	

--
-- Tests for tree.new()
--

	function T.tree.NewReturnsObject()
		test.isnotnil(tr)
	end


--
-- Tests for tree.add()
--

	function T.tree.CanAddAtRoot()
		tree.add(tr, "Root")
		test.isequal(""
			.. "Root",
			getresult())
	end

	function T.tree.CanAddAtChild()
		tree.add(tr, "Root/Child")
		test.isequal(""
			.. "Root"
			.. ".Child",
			getresult())
	end

	function T.tree.CanAddAtGrandchild()
		tree.add(tr, "Root/Child/Grandchild")
		test.isequal(""
			.. "Root"
			.. ".Child"
			.. "..Grandchild",
			getresult())
	end

	function T.tree.SkipsDotDots()
		tree.add(tr, "../MyProject/hello")
		test.isequal(""
			.. "MyProject"
			.. ".hello",
			getresult())
	end


--
-- Tests for tree.getlocalpath()
--

	function T.tree.GetLocalPath_ReturnsPath_OnNoParentPath()
		local c = tree.add(tr, "Root/Child")
		c.parent.path = nil
		test.isequal("Root/Child", tree.getlocalpath(c))
	end

	function T.tree.GetLocalPath_ReturnsName_OnParentPathSet()
		local c = tree.add(tr, "Root/Child")
		test.isequal("Child", tree.getlocalpath(c))
	end


--
-- Tests for tree.remove()
--

	function T.tree.Remove_RemovesNodes()
		local n1 = tree.add(tr, "1")
		local n2 = tree.add(tr, "2")
		local n3 = tree.add(tr, "3")
		tree.remove(n2)
		local r = ""
		for _, n in ipairs(tr.children) do r = r .. n.name end
		test.isequal("13", r)
	end

	
	function T.tree.Remove_WorksInTraversal()
		tree.add(tr, "Root/1")
		tree.add(tr, "Root/2")
		tree.add(tr, "Root/3")
		local r = ""
		tree.traverse(tr, {
			onleaf = function(node)
				r = r .. node.name
				tree.remove(node)
			end
		})
		test.isequal("123", r)
		test.isequal(0, #tr.children[1])
	end