Skip to content

Commit e5ccce8

Browse files
committed
Add more generator test
1 parent 1dfa19a commit e5ccce8

File tree

13 files changed

+343
-8
lines changed

13 files changed

+343
-8
lines changed

src/test/kotlin/com/tomwyr/GeneratorTest.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,23 @@ import kotlin.test.assertEquals
1111

1212
class GeneratorTest {
1313
@Test
14-
fun `generates expected output for simple project`() {
14+
fun `single scene with nested nodes`() {
15+
test("physics-test", "com.physics.test")
16+
}
17+
18+
@Test
19+
fun `spaces in node names`() {
1520
test("simple", "com.simple.game")
1621
}
1722

1823
@Test
19-
fun `generates expected output for the example project`() {
20-
test("example", "com.example.game")
24+
fun `multiple independent scenes`() {
25+
test("scene-changer", "com.scenes.changer")
26+
}
27+
28+
@Test
29+
fun `multiple scenes`() {
30+
test("dodge-the-creeps", "com.example.game")
2131
}
2232

2333
@BeforeTest
@@ -44,20 +54,20 @@ const val basePath = "src/test/resources/"
4454

4555
fun setUpTestProject(testCase: String, targetPackage: String): GodotKotlinProject {
4656
return GodotKotlinProject(
47-
"$basePath/$testCase/input",
48-
"$basePath/$testCase/output/Actual",
57+
"$basePath/$testCase/scenes",
58+
"$basePath/$testCase/Actual",
4959
targetPackage,
5060
)
5161
}
5262

5363
fun assertOutputsEqual(testCase: String) {
54-
val expected = File("$basePath/$testCase/output/Expected").readText(Charsets.UTF_8)
55-
val actual = File("$basePath/$testCase/output/Actual").readText(Charsets.UTF_8)
64+
val expected = File("$basePath/$testCase/Expected").readText(Charsets.UTF_8)
65+
val actual = File("$basePath/$testCase/Actual").readText(Charsets.UTF_8)
5666
assertEquals(expected, actual)
5767
}
5868

5969
fun cleanUpGeneratedOutput(testCase: String) {
60-
File("$basePath/$testCase/output/Actual").run {
70+
File("$basePath/$testCase/Actual").run {
6171
if (exists()) delete()
6272
}
6373
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.physics.test
2+
3+
import godot.*
4+
import godot.core.NodePath
5+
import kotlin.reflect.KProperty
6+
7+
object GDTree {
8+
object Main : NodeRef<Control>("/root/Main", "Control") {
9+
val TestsMenu = NodeRef<MenuButton>("/root/Main/TestsMenu", "MenuButton")
10+
val LabelControls = NodeRef<Label>("/root/Main/LabelControls", "Label")
11+
val LabelFPS = NodeRef<Label>("/root/Main/LabelFPS", "Label")
12+
val LabelEngine = NodeRef<Label>("/root/Main/LabelEngine", "Label")
13+
val LabelVersion = NodeRef<Label>("/root/Main/LabelVersion", "Label")
14+
val LabelTest = NodeRef<Label>("/root/Main/LabelTest", "Label")
15+
val LabelPause = NodeRef<Label>("/root/Main/LabelPause", "Label")
16+
object PanelLog : NodeRef<Panel>("/root/Main/PanelLog", "Panel") {
17+
val ButtonClear = NodeRef<Button>("/root/Main/PanelLog/ButtonClear", "Button")
18+
val CheckBoxScroll = NodeRef<CheckButton>("/root/Main/PanelLog/CheckBoxScroll", "CheckButton")
19+
object ScrollLog : NodeRef<ScrollContainer>("/root/Main/PanelLog/ScrollLog", "ScrollContainer") {
20+
object VBoxLog : NodeRef<VBoxContainer>("/root/Main/PanelLog/ScrollLog/VBoxLog", "VBoxContainer") {
21+
val LabelLog = NodeRef<Label>("/root/Main/PanelLog/ScrollLog/VBoxLog/LabelLog", "Label")
22+
}
23+
}
24+
}
25+
}
26+
}
27+
28+
open class NodeRef<T : Node>(
29+
private val path: String,
30+
private val type: String,
31+
) {
32+
operator fun getValue(thisRef: Node, property: KProperty<*>): T {
33+
val node = thisRef.getNode(NodePath(path)) ?: throw NodeNotFoundException(path)
34+
@Suppress("UNCHECKED_CAST")
35+
(node as? T) ?: throw NodeInvalidTypeException(type)
36+
return node
37+
}
38+
}
39+
40+
class NodeNotFoundException(expectedPath: String) : Exception("Node not found under given path $expectedPath")
41+
42+
class NodeInvalidTypeException(expectedType: String?) : Exception("Node is not an instance of $expectedType")
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
[gd_scene load_steps=11 format=3 uid="uid://6a0nxwkgf5dq"]
2+
3+
[ext_resource type="Script" path="res://utils/label_fps.gd" id="1"]
4+
[ext_resource type="Script" path="res://utils/label_version.gd" id="2"]
5+
[ext_resource type="Script" path="res://utils/label_engine.gd" id="3"]
6+
[ext_resource type="Script" path="res://tests_menu.gd" id="4"]
7+
[ext_resource type="Script" path="res://utils/label_test.gd" id="5"]
8+
[ext_resource type="Script" path="res://utils/label_pause.gd" id="6"]
9+
[ext_resource type="Script" path="res://utils/container_log.gd" id="10"]
10+
[ext_resource type="Script" path="res://utils/scroll_log.gd" id="11"]
11+
[ext_resource type="Script" path="res://tests.gd" id="12"]
12+
13+
[sub_resource type="StyleBoxFlat" id="1"]
14+
bg_color = Color(0, 0, 0, 0.176471)
15+
16+
[node name="Main" type="Control"]
17+
layout_mode = 3
18+
anchors_preset = 15
19+
anchor_right = 1.0
20+
anchor_bottom = 1.0
21+
grow_horizontal = 2
22+
grow_vertical = 2
23+
mouse_filter = 2
24+
script = ExtResource("12")
25+
26+
[node name="TestsMenu" type="MenuButton" parent="."]
27+
layout_mode = 0
28+
offset_left = 10.0
29+
offset_top = 10.0
30+
offset_right = 125.0
31+
offset_bottom = 30.0
32+
text = "TESTS"
33+
flat = false
34+
script = ExtResource("4")
35+
36+
[node name="LabelControls" type="Label" parent="."]
37+
layout_mode = 0
38+
offset_left = 157.0
39+
offset_top = 13.0
40+
offset_right = 646.0
41+
offset_bottom = 27.0
42+
text = "P - TOGGLE PAUSE / R - RESTART / C - TOGGLE COLLISION / F - TOGGLE FULL SCREEN / ESC - QUIT"
43+
44+
[node name="LabelFPS" type="Label" parent="."]
45+
layout_mode = 1
46+
anchors_preset = 2
47+
anchor_top = 1.0
48+
anchor_bottom = 1.0
49+
offset_left = 10.0
50+
offset_top = -19.0
51+
offset_right = 50.0
52+
offset_bottom = -5.0
53+
grow_vertical = 0
54+
text = "FPS: 0"
55+
script = ExtResource("1")
56+
57+
[node name="LabelEngine" type="Label" parent="."]
58+
layout_mode = 1
59+
anchors_preset = 2
60+
anchor_top = 1.0
61+
anchor_bottom = 1.0
62+
offset_left = 10.0
63+
offset_top = -39.0
64+
offset_right = 50.0
65+
offset_bottom = -25.0
66+
grow_vertical = 0
67+
text = "Physics engine:"
68+
script = ExtResource("3")
69+
70+
[node name="LabelVersion" type="Label" parent="."]
71+
layout_mode = 1
72+
anchors_preset = 2
73+
anchor_top = 1.0
74+
anchor_bottom = 1.0
75+
offset_left = 10.0
76+
offset_top = -59.0
77+
offset_right = 50.0
78+
offset_bottom = -45.0
79+
grow_vertical = 0
80+
text = "Godot Version:"
81+
script = ExtResource("2")
82+
83+
[node name="LabelTest" type="Label" parent="."]
84+
layout_mode = 1
85+
anchors_preset = 2
86+
anchor_top = 1.0
87+
anchor_bottom = 1.0
88+
offset_left = 10.0
89+
offset_top = -79.0
90+
offset_right = 50.0
91+
offset_bottom = -65.0
92+
grow_vertical = 0
93+
text = "Test:"
94+
script = ExtResource("5")
95+
96+
[node name="LabelPause" type="Label" parent="."]
97+
modulate = Color(1, 1, 0, 1)
98+
layout_mode = 1
99+
anchors_preset = 5
100+
anchor_left = 0.5
101+
anchor_right = 0.5
102+
offset_left = -62.0
103+
offset_top = 48.0
104+
offset_right = 62.0
105+
offset_bottom = 96.0
106+
grow_horizontal = 2
107+
theme_override_font_sizes/font_size = 32
108+
text = "PAUSED"
109+
script = ExtResource("6")
110+
111+
[node name="PanelLog" type="Panel" parent="."]
112+
layout_mode = 1
113+
anchors_preset = 3
114+
anchor_left = 1.0
115+
anchor_top = 1.0
116+
anchor_right = 1.0
117+
anchor_bottom = 1.0
118+
offset_left = -630.0
119+
offset_top = -251.0
120+
grow_horizontal = 0
121+
grow_vertical = 0
122+
theme_override_styles/panel = SubResource("1")
123+
124+
[node name="ButtonClear" type="Button" parent="PanelLog"]
125+
layout_mode = 1
126+
anchors_preset = 3
127+
anchor_left = 1.0
128+
anchor_top = 1.0
129+
anchor_right = 1.0
130+
anchor_bottom = 1.0
131+
offset_left = -48.0
132+
offset_top = -25.0
133+
offset_right = -5.0
134+
offset_bottom = -5.0
135+
grow_horizontal = 0
136+
grow_vertical = 0
137+
focus_mode = 0
138+
text = "Clear"
139+
140+
[node name="CheckBoxScroll" type="CheckButton" parent="PanelLog"]
141+
layout_mode = 1
142+
anchors_preset = 3
143+
anchor_left = 1.0
144+
anchor_top = 1.0
145+
anchor_right = 1.0
146+
anchor_bottom = 1.0
147+
offset_left = -261.0
148+
offset_top = -35.0
149+
offset_right = -62.0
150+
offset_bottom = -4.0
151+
grow_horizontal = 0
152+
grow_vertical = 0
153+
focus_mode = 0
154+
text = "Automatic Scrolling"
155+
156+
[node name="ScrollLog" type="ScrollContainer" parent="PanelLog"]
157+
layout_mode = 0
158+
offset_left = 10.0
159+
offset_top = 5.0
160+
offset_right = 619.0
161+
offset_bottom = 210.0
162+
script = ExtResource("11")
163+
auto_scroll = true
164+
165+
[node name="VBoxLog" type="VBoxContainer" parent="PanelLog/ScrollLog"]
166+
layout_mode = 2
167+
size_flags_horizontal = 3
168+
size_flags_vertical = 3
169+
alignment = 2
170+
script = ExtResource("10")
171+
172+
[node name="LabelLog" type="Label" parent="PanelLog/ScrollLog/VBoxLog"]
173+
layout_mode = 2
174+
text = "Log start"
175+
max_lines_visible = 5
176+
177+
[connection signal="pressed" from="PanelLog/ButtonClear" to="PanelLog/ScrollLog/VBoxLog" method="clear"]
178+
[connection signal="toggled" from="PanelLog/CheckBoxScroll" to="PanelLog/ScrollLog" method="_on_check_box_scroll_toggled"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.scenes.changer
2+
3+
import godot.*
4+
import godot.core.NodePath
5+
import kotlin.reflect.KProperty
6+
7+
object GDTree {
8+
object SceneA : NodeRef<Panel>("/root/SceneA", "Panel") {
9+
val Label = NodeRef<Label>("/root/SceneA/Label", "Label")
10+
val GoToScene = NodeRef<Button>("/root/SceneA/GoToScene", "Button")
11+
}
12+
13+
object SceneB : NodeRef<Panel>("/root/SceneB", "Panel") {
14+
val Label = NodeRef<Label>("/root/SceneB/Label", "Label")
15+
val GoToScene = NodeRef<Button>("/root/SceneB/GoToScene", "Button")
16+
}
17+
}
18+
19+
open class NodeRef<T : Node>(
20+
private val path: String,
21+
private val type: String,
22+
) {
23+
operator fun getValue(thisRef: Node, property: KProperty<*>): T {
24+
val node = thisRef.getNode(NodePath(path)) ?: throw NodeNotFoundException(path)
25+
@Suppress("UNCHECKED_CAST")
26+
(node as? T) ?: throw NodeInvalidTypeException(type)
27+
return node
28+
}
29+
}
30+
31+
class NodeNotFoundException(expectedPath: String) : Exception("Node not found under given path $expectedPath")
32+
33+
class NodeInvalidTypeException(expectedType: String?) : Exception("Node is not an instance of $expectedType")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://dnveeke63vq8x"]
2+
3+
[ext_resource type="Script" path="res://scene_a.gd" id="1"]
4+
5+
[node name="SceneA" type="Panel"]
6+
anchors_preset = 15
7+
anchor_right = 1.0
8+
anchor_bottom = 1.0
9+
grow_horizontal = 2
10+
grow_vertical = 2
11+
size_flags_horizontal = 2
12+
size_flags_vertical = 2
13+
script = ExtResource("1")
14+
15+
[node name="Label" type="Label" parent="."]
16+
layout_mode = 0
17+
offset_left = 64.0
18+
offset_top = 48.0
19+
offset_right = 104.0
20+
offset_bottom = 62.0
21+
size_flags_vertical = 0
22+
text = "This is scene A."
23+
24+
[node name="GoToScene" type="Button" parent="."]
25+
layout_mode = 0
26+
offset_left = 64.0
27+
offset_top = 128.0
28+
offset_right = 277.0
29+
offset_bottom = 182.0
30+
size_flags_horizontal = 2
31+
size_flags_vertical = 2
32+
theme_override_colors/font_color = Color(0.639216, 1, 0.639216, 1)
33+
theme_override_font_sizes/font_size = 24
34+
text = "Go to Scene B"
35+
36+
[connection signal="pressed" from="GoToScene" to="." method="_on_goto_scene_pressed"]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://c71ureg6hk2u1"]
2+
3+
[ext_resource type="Script" path="res://scene_b.gd" id="1"]
4+
5+
[node name="SceneB" type="Panel"]
6+
anchors_preset = 15
7+
anchor_right = 1.0
8+
anchor_bottom = 1.0
9+
grow_horizontal = 2
10+
grow_vertical = 2
11+
size_flags_horizontal = 2
12+
size_flags_vertical = 2
13+
script = ExtResource("1")
14+
15+
[node name="Label" type="Label" parent="."]
16+
layout_mode = 0
17+
offset_left = 64.0
18+
offset_top = 48.0
19+
offset_right = 164.0
20+
offset_bottom = 62.0
21+
size_flags_vertical = 0
22+
text = "This is scene B."
23+
24+
[node name="GoToScene" type="Button" parent="."]
25+
layout_mode = 0
26+
offset_left = 64.0
27+
offset_top = 128.0
28+
offset_right = 277.0
29+
offset_bottom = 182.0
30+
size_flags_horizontal = 2
31+
size_flags_vertical = 2
32+
theme_override_colors/font_color = Color(0.905882, 0.627451, 0.984314, 1)
33+
theme_override_font_sizes/font_size = 24
34+
text = "Go to Scene A"
35+
36+
[connection signal="pressed" from="GoToScene" to="." method="_on_goto_scene_pressed"]

0 commit comments

Comments
 (0)