Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8170899

Browse files
test: 🧪 added tests for .process_script() (#476)
* test: 🧪 added tests for `.process_script()` * refactor: ♻️ updated for await and `\` * fix: 🐛 replace `\` * refactor: ✏️ 🤫 * fix: 🐛 missed one * fix: 🐛 match `\` and new line * test: 🧪 added case for `func_name\\n#comment(` * test: 🧪 added `# (` to `func_name\\n#comment(` * test: 🧪 add space before `(` * test: 🧪 add comments in params case * test: 🧪 add param to commented func * test: 🧪 commented func with space * test: 🧪 more comment testing and did some reformatting * test: 🧪 more comment testing * test: 🧪 similar func names * test: 🧪 test script A and B without hook check * test: 🧪 added not in child / parent class case * test: 🙈 added edge case issue script * refactor: ♻️ updated process results * refactor: ♻️ update processed scripts * fix: 🐛 wrong args * docs: 📝 add short comment why `source_code.trim_prefix("#")` is used
1 parent afe3b31 commit 8170899

File tree

9 files changed

+919
-0
lines changed

9 files changed

+919
-0
lines changed

‎test/Unit/test_mod_hook_preprocessor.gd‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,20 @@ func test_match_func_with_whitespace(params: Array = use_parameters(test_match_f
8989
result.get_string(), expected_string,
9090
"expected %s, got %s" % [expected_string, result.get_string()]
9191
)
92+
93+
94+
func test_process_script() -> void:
95+
var hook_pre_processor := _ModLoaderModHookPreProcessor.new()
96+
hook_pre_processor.process_begin()
97+
98+
var result_a := hook_pre_processor.process_script("res://test_mod_hook_preprocessor/test_script_A.gd")
99+
# Using source_code.trim_prefix("#") to prevent hiding global class error.
100+
var result_a_expected: String = load("res://test_mod_hook_preprocessor/test_script_A_processed.gd").source_code.trim_prefix("#")
101+
var result_b := hook_pre_processor.process_script("res://test_mod_hook_preprocessor/test_script_B.gd")
102+
var result_b_expected: String = load("res://test_mod_hook_preprocessor/test_script_B_processed.gd").source_code.trim_prefix("#")
103+
var result_c := hook_pre_processor.process_script("res://test_mod_hook_preprocessor/test_script_C.gd", true)
104+
var result_c_expected: String = load("res://test_mod_hook_preprocessor/test_script_C_processed.gd").source_code.trim_prefix("#")
105+
106+
assert_eq(result_a, result_a_expected)
107+
assert_eq(result_b, result_b_expected)
108+
assert_eq(result_c, result_c_expected)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extends Node
2+
3+
# Ste — 09/01/2025 12:46
4+
# did ya know you can escape indentation O_O
5+
\
6+
func what_the_hell() -> void:
7+
pass
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://ccew16mwmtfq7"]
2+
3+
[ext_resource type="Script" path="res://test_mod_hook_preprocessor/test_script_A.gd" id="1_txq7h"]
4+
5+
[node name="TestSceneA" type="Control"]
6+
layout_mode = 3
7+
anchors_preset = 15
8+
anchor_right = 1.0
9+
anchor_bottom = 1.0
10+
grow_horizontal = 2
11+
grow_vertical = 2
12+
script = ExtResource("1_txq7h")
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
class_name ModHookPreprocessorTestScriptA
2+
extends Node
3+
4+
5+
@export var some_export_var_with_type: float = 1.11
6+
@export_dir var some_export_var_no_type
7+
8+
var some_var_no_type = "text"
9+
var some_var_with_type: int = -1
10+
var some_var_with_inline_set :
11+
set(new_value):
12+
some_var_with_inline_set = new_value
13+
var some_var_with_inline_get :
14+
get():
15+
return some_var_with_inline_get
16+
var some_var_with_inline_get_set :
17+
set(new_value):
18+
some_var_with_inline_get_set = new_value
19+
get():
20+
return some_var_with_inline_get_set
21+
var some_var_with_set := _set_some_var_with_set
22+
var some_var_with_get := _get_some_var_with_get
23+
24+
@onready var some_var_onready_no_type
25+
@onready var some_var_onready_with_type: String = "ready"
26+
27+
28+
func _ready() -> void:
29+
some_var_no_type = "update"
30+
await get_tree().create_timer(0.1).timeout
31+
some_var_with_inline_set = "time has passed"
32+
33+
34+
func _process(delta: float) -> void:
35+
pass
36+
37+
38+
func that_is_super() -> void:
39+
pass
40+
41+
42+
func give_default() -> String:
43+
return "AAAAAAHHHHHH"
44+
45+
46+
func did_you_know_you_can_realy_write_your_function___like_this(param_1: String \
47+
,param_2 = give_default() ) -> \
48+
void:
49+
pass
50+
51+
52+
func _set_some_var_with_set(new_value):
53+
some_var_with_set = new_value
54+
55+
56+
func _get_some_var_with_get():
57+
return some_var_with_get
58+
59+
60+
func im_not_in_the_child_class() -> void:
61+
pass
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#class_name ModHookPreprocessorTestScriptA
2+
extends Node
3+
4+
5+
@export var some_export_var_with_type: float = 1.11
6+
@export_dir var some_export_var_no_type
7+
8+
var some_var_no_type = "text"
9+
var some_var_with_type: int = -1
10+
var some_var_with_inline_set :
11+
set(new_value):
12+
some_var_with_inline_set = new_value
13+
var some_var_with_inline_get :
14+
get():
15+
return some_var_with_inline_get
16+
var some_var_with_inline_get_set :
17+
set(new_value):
18+
some_var_with_inline_get_set = new_value
19+
get():
20+
return some_var_with_inline_get_set
21+
var some_var_with_set := _set_some_var_with_set
22+
var some_var_with_get := _get_some_var_with_get
23+
24+
@onready var some_var_onready_no_type
25+
@onready var some_var_onready_with_type: String = "ready"
26+
27+
28+
func vanilla_2078459544__ready() -> void:
29+
some_var_no_type = "update"
30+
await get_tree().create_timer(0.1).timeout
31+
some_var_with_inline_set = "time has passed"
32+
33+
34+
func vanilla_2078459544__process(delta: float) -> void:
35+
pass
36+
37+
38+
func vanilla_2078459544_that_is_super() -> void:
39+
pass
40+
41+
42+
func vanilla_2078459544_give_default() -> String:
43+
return "AAAAAAHHHHHH"
44+
45+
46+
func vanilla_2078459544_did_you_know_you_can_realy_write_your_function___like_this(param_1: String \
47+
,param_2 = give_default() ) -> \
48+
void:
49+
pass
50+
51+
52+
func vanilla_2078459544__set_some_var_with_set(new_value):
53+
some_var_with_set = new_value
54+
55+
56+
func vanilla_2078459544__get_some_var_with_get():
57+
return some_var_with_get
58+
59+
60+
func vanilla_2078459544_im_not_in_the_child_class() -> void:
61+
pass
62+
63+
64+
# ModLoader Hooks - The following code has been automatically added by the Godot Mod Loader.
65+
66+
67+
func _ready():
68+
await _ModLoaderHooks.call_hooks_async(vanilla_2078459544__ready, [], 2195022348)
69+
70+
71+
func _process(delta: float):
72+
_ModLoaderHooks.call_hooks(vanilla_2078459544__process, [delta], 319893654)
73+
74+
75+
func that_is_super():
76+
_ModLoaderHooks.call_hooks(vanilla_2078459544_that_is_super, [], 3896778322)
77+
78+
79+
func give_default() -> String:
80+
return _ModLoaderHooks.call_hooks(vanilla_2078459544_give_default, [], 3905258887)
81+
82+
83+
func did_you_know_you_can_realy_write_your_function___like_this(param_1: String\
84+
, param_2=give_default()):
85+
_ModLoaderHooks.call_hooks(vanilla_2078459544_did_you_know_you_can_realy_write_your_function___like_this, [param_1, param_2], 833669474)
86+
87+
88+
func _set_some_var_with_set(new_value):
89+
return _ModLoaderHooks.call_hooks(vanilla_2078459544__set_some_var_with_set, [new_value], 1894552580)
90+
91+
92+
func _get_some_var_with_get():
93+
return _ModLoaderHooks.call_hooks(vanilla_2078459544__get_some_var_with_get, [], 2756748012)
94+
95+
96+
func im_not_in_the_child_class():
97+
_ModLoaderHooks.call_hooks(vanilla_2078459544_im_not_in_the_child_class, [], 3426759564)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class_name ModHookPreprocessorTestScriptB
2+
extends ModHookPreprocessorTestScriptA
3+
4+
5+
func _ready() -> void:
6+
super._ready() # I'm super ready here
7+
8+
9+
func that_is_super() -> void:
10+
super()
11+
12+
13+
func im_not_in_the_parent_class() -> void:
14+
pass
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#class_name ModHookPreprocessorTestScriptB
2+
extends ModHookPreprocessorTestScriptA
3+
4+
5+
func vanilla_2078495481__ready() -> void:
6+
super._ready() # I'm super ready here
7+
8+
9+
func vanilla_2078495481_that_is_super() -> void:
10+
super.that_is_super()
11+
12+
13+
func vanilla_2078495481_im_not_in_the_parent_class() -> void:
14+
pass
15+
16+
17+
# ModLoader Hooks - The following code has been automatically added by the Godot Mod Loader.
18+
19+
20+
func _ready():
21+
_ModLoaderHooks.call_hooks(vanilla_2078495481__ready, [], 2262823725)
22+
23+
24+
func that_is_super():
25+
_ModLoaderHooks.call_hooks(vanilla_2078495481_that_is_super, [], 2065563731)
26+
27+
28+
func im_not_in_the_parent_class():
29+
_ModLoaderHooks.call_hooks(vanilla_2078495481_im_not_in_the_parent_class, [], 986863251)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /