Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: 🧪 added tests for .process_script() #476

Open
wants to merge 18 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/Unit/test_mod_hook_preprocessor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,19 @@ func test_match_func_with_whitespace(params: Array = use_parameters(test_match_f
result.get_string(), expected_string,
"expected %s, got %s" % [expected_string, result.get_string()]
)


func test_process_script() -> void:
var hook_pre_processor := _ModLoaderModHookPreProcessor.new()
hook_pre_processor.process_begin()

var result_a := hook_pre_processor.process_script("res://test_mod_hook_preprocessor/test_script_A.gd", false)
var result_a_expected: String = load("res://test_mod_hook_preprocessor/test_script_A_processed.gd").source_code.trim_prefix("#")
var result_b := hook_pre_processor.process_script("res://test_mod_hook_preprocessor/test_script_B.gd", false)
var result_b_expected: String = load("res://test_mod_hook_preprocessor/test_script_B_processed.gd").source_code.trim_prefix("#")
var result_c := hook_pre_processor.process_script("res://test_mod_hook_preprocessor/test_script_C.gd")
var result_c_expected: String = load("res://test_mod_hook_preprocessor/test_script_C_processed.gd").source_code.trim_prefix("#")

assert_eq(result_a, result_a_expected)
assert_eq(result_b, result_b_expected)
assert_eq(result_c, result_c_expected)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Node

# Ste — 09/01/2025 12:46
# did ya know you can escape indentation O_O
\
func what_the_hell() -> void:
pass
12 changes: 12 additions & 0 deletions test/test_mod_hook_preprocessor/test_scene_A.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://ccew16mwmtfq7"]

[ext_resource type="Script" path="res://test_mod_hook_preprocessor/test_script_A.gd" id="1_txq7h"]

[node name="TestSceneA" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_txq7h")
61 changes: 61 additions & 0 deletions test/test_mod_hook_preprocessor/test_script_A.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class_name ModHookPreprocessorTestScriptA
extends Node


@export var some_export_var_with_type: float = 1.11
@export_dir var some_export_var_no_type

var some_var_no_type = "text"
var some_var_with_type: int = -1
var some_var_with_inline_set :
set(new_value):
some_var_with_inline_set = new_value
var some_var_with_inline_get :
get():
return some_var_with_inline_get
var some_var_with_inline_get_set :
set(new_value):
some_var_with_inline_get_set = new_value
get():
return some_var_with_inline_get_set
var some_var_with_set := _set_some_var_with_set
var some_var_with_get := _get_some_var_with_get

@onready var some_var_onready_no_type
@onready var some_var_onready_with_type: String = "ready"


func _ready() -> void:
some_var_no_type = "update"
await get_tree().create_timer(0.1).timeout
some_var_with_inline_set = "time has passed"


func _process(delta: float) -> void:
pass


func that_is_super() -> void:
pass


func give_default() -> String:
return "AAAAAAHHHHHH"


func did_you_know_you_can_realy_write_your_function___like_this(param_1: String \
,param_2 = give_default() ) -> \
void:
pass


func _set_some_var_with_set(new_value):
some_var_with_set = new_value


func _get_some_var_with_get():
return some_var_with_get


func im_not_in_the_child_class() -> void:
pass
97 changes: 97 additions & 0 deletions test/test_mod_hook_preprocessor/test_script_A_processed.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#class_name ModHookPreprocessorTestScriptA
extends Node


@export var some_export_var_with_type: float = 1.11
@export_dir var some_export_var_no_type

var some_var_no_type = "text"
var some_var_with_type: int = -1
var some_var_with_inline_set :
set(new_value):
some_var_with_inline_set = new_value
var some_var_with_inline_get :
get():
return some_var_with_inline_get
var some_var_with_inline_get_set :
set(new_value):
some_var_with_inline_get_set = new_value
get():
return some_var_with_inline_get_set
var some_var_with_set := _set_some_var_with_set
var some_var_with_get := _get_some_var_with_get

@onready var some_var_onready_no_type
@onready var some_var_onready_with_type: String = "ready"


func vanilla_2078459544__ready() -> void:
some_var_no_type = "update"
await get_tree().create_timer(0.1).timeout
some_var_with_inline_set = "time has passed"


func vanilla_2078459544__process(delta: float) -> void:
pass


func vanilla_2078459544_that_is_super() -> void:
pass


func vanilla_2078459544_give_default() -> String:
return "AAAAAAHHHHHH"


func vanilla_2078459544_did_you_know_you_can_realy_write_your_function___like_this(param_1: String \
,param_2 = give_default() ) -> \
void:
pass


func vanilla_2078459544__set_some_var_with_set(new_value):
some_var_with_set = new_value


func vanilla_2078459544__get_some_var_with_get():
return some_var_with_get


func vanilla_2078459544_im_not_in_the_child_class() -> void:
pass


# ModLoader Hooks - The following code has been automatically added by the Godot Mod Loader.


func _ready():
await _ModLoaderHooks.call_hooks_async(vanilla_2078459544__ready, [], 2195022348)


func _process(delta: float):
_ModLoaderHooks.call_hooks(vanilla_2078459544__process, [delta], 319893654)


func that_is_super():
_ModLoaderHooks.call_hooks(vanilla_2078459544_that_is_super, [], 3896778322)


func give_default() -> String:
return _ModLoaderHooks.call_hooks(vanilla_2078459544_give_default, [], 3905258887)


func did_you_know_you_can_realy_write_your_function___like_this(param_1: String\
, param_2=give_default()):
_ModLoaderHooks.call_hooks(vanilla_2078459544_did_you_know_you_can_realy_write_your_function___like_this, [param_1, param_2], 833669474)


func _set_some_var_with_set(new_value):
_ModLoaderHooks.call_hooks(vanilla_2078459544__set_some_var_with_set, [new_value], 1894552580)


func _get_some_var_with_get():
return _ModLoaderHooks.call_hooks(vanilla_2078459544__get_some_var_with_get, [], 2756748012)


func im_not_in_the_child_class():
_ModLoaderHooks.call_hooks(vanilla_2078459544_im_not_in_the_child_class, [], 3426759564)
14 changes: 14 additions & 0 deletions test/test_mod_hook_preprocessor/test_script_B.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class_name ModHookPreprocessorTestScriptB
extends ModHookPreprocessorTestScriptA


func _ready() -> void:
super._ready() # I'm super ready here


func that_is_super() -> void:
super()


func im_not_in_the_parent_class() -> void:
pass
29 changes: 29 additions & 0 deletions test/test_mod_hook_preprocessor/test_script_B_processed.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#class_name ModHookPreprocessorTestScriptB
extends ModHookPreprocessorTestScriptA


func vanilla_2078495481__ready() -> void:
super._ready() # I'm super ready here


func vanilla_2078495481_that_is_super() -> void:
super.that_is_super()


func vanilla_2078495481_im_not_in_the_parent_class() -> void:
pass


# ModLoader Hooks - The following code has been automatically added by the Godot Mod Loader.


func _ready():
_ModLoaderHooks.call_hooks(vanilla_2078495481__ready, [], 2262823725)


func that_is_super():
_ModLoaderHooks.call_hooks(vanilla_2078495481_that_is_super, [], 2065563731)


func im_not_in_the_parent_class():
_ModLoaderHooks.call_hooks(vanilla_2078495481_im_not_in_the_parent_class, [], 986863251)
Loading
Loading