Add gdlint and gdformat scripts
This commit is contained in:
@@ -11,6 +11,7 @@ var stepper_instance: Control
|
||||
var test_viewport: SubViewport
|
||||
var original_language: String
|
||||
|
||||
|
||||
func _initialize():
|
||||
# Wait for autoloads to initialize
|
||||
await process_frame
|
||||
@@ -21,6 +22,7 @@ func _initialize():
|
||||
# Exit after tests complete
|
||||
quit()
|
||||
|
||||
|
||||
func run_tests():
|
||||
TestHelper.print_test_header("ValueStepper Component")
|
||||
|
||||
@@ -47,6 +49,7 @@ func run_tests():
|
||||
|
||||
TestHelper.print_test_footer("ValueStepper Component")
|
||||
|
||||
|
||||
func setup_test_environment():
|
||||
TestHelper.print_step("Test Environment Setup")
|
||||
|
||||
@@ -69,6 +72,7 @@ func setup_test_environment():
|
||||
await process_frame
|
||||
await process_frame
|
||||
|
||||
|
||||
func test_basic_functionality():
|
||||
TestHelper.print_step("Basic Functionality")
|
||||
|
||||
@@ -77,16 +81,30 @@ func test_basic_functionality():
|
||||
return
|
||||
|
||||
# Test that ValueStepper has expected properties
|
||||
var expected_properties = ["data_source", "custom_format_function", "values", "display_names", "current_index"]
|
||||
var expected_properties = [
|
||||
"data_source", "custom_format_function", "values", "display_names", "current_index"
|
||||
]
|
||||
for prop in expected_properties:
|
||||
TestHelper.assert_true(prop in stepper_instance, "ValueStepper has property: " + prop)
|
||||
|
||||
# Test that ValueStepper has expected methods
|
||||
var expected_methods = ["change_value", "setup_custom_values", "get_current_value", "set_current_value", "set_highlighted", "handle_input_action", "get_control_name"]
|
||||
TestHelper.assert_has_methods(stepper_instance, expected_methods, "ValueStepper component methods")
|
||||
var expected_methods = [
|
||||
"change_value",
|
||||
"setup_custom_values",
|
||||
"get_current_value",
|
||||
"set_current_value",
|
||||
"set_highlighted",
|
||||
"handle_input_action",
|
||||
"get_control_name"
|
||||
]
|
||||
TestHelper.assert_has_methods(
|
||||
stepper_instance, expected_methods, "ValueStepper component methods"
|
||||
)
|
||||
|
||||
# Test signals
|
||||
TestHelper.assert_true(stepper_instance.has_signal("value_changed"), "ValueStepper has value_changed signal")
|
||||
TestHelper.assert_true(
|
||||
stepper_instance.has_signal("value_changed"), "ValueStepper has value_changed signal"
|
||||
)
|
||||
|
||||
# Test UI components
|
||||
TestHelper.assert_not_null(stepper_instance.left_button, "Left button is available")
|
||||
@@ -98,6 +116,7 @@ func test_basic_functionality():
|
||||
TestHelper.assert_true(stepper_instance.right_button is Button, "Right button is Button type")
|
||||
TestHelper.assert_true(stepper_instance.value_display is Label, "Value display is Label type")
|
||||
|
||||
|
||||
func test_data_source_loading():
|
||||
TestHelper.print_step("Data Source Loading")
|
||||
|
||||
@@ -105,7 +124,9 @@ func test_data_source_loading():
|
||||
return
|
||||
|
||||
# Test default language data source
|
||||
TestHelper.assert_equal("language", stepper_instance.data_source, "Default data source is language")
|
||||
TestHelper.assert_equal(
|
||||
"language", stepper_instance.data_source, "Default data source is language"
|
||||
)
|
||||
|
||||
# Test that values are loaded
|
||||
TestHelper.assert_not_null(stepper_instance.values, "Values array is initialized")
|
||||
@@ -116,14 +137,24 @@ func test_data_source_loading():
|
||||
# Test that language data is loaded correctly
|
||||
if stepper_instance.data_source == "language":
|
||||
TestHelper.assert_true(stepper_instance.values.size() > 0, "Language values loaded")
|
||||
TestHelper.assert_true(stepper_instance.display_names.size() > 0, "Language display names loaded")
|
||||
TestHelper.assert_equal(stepper_instance.values.size(), stepper_instance.display_names.size(), "Values and display names arrays have same size")
|
||||
TestHelper.assert_true(
|
||||
stepper_instance.display_names.size() > 0, "Language display names loaded"
|
||||
)
|
||||
TestHelper.assert_equal(
|
||||
stepper_instance.values.size(),
|
||||
stepper_instance.display_names.size(),
|
||||
"Values and display names arrays have same size"
|
||||
)
|
||||
|
||||
# Test that current language is properly selected
|
||||
var current_lang = root.get_node("SettingsManager").get_setting("language")
|
||||
var expected_index = stepper_instance.values.find(current_lang)
|
||||
if expected_index >= 0:
|
||||
TestHelper.assert_equal(expected_index, stepper_instance.current_index, "Current language index set correctly")
|
||||
TestHelper.assert_equal(
|
||||
expected_index,
|
||||
stepper_instance.current_index,
|
||||
"Current language index set correctly"
|
||||
)
|
||||
|
||||
# Test resolution data source
|
||||
var resolution_stepper = stepper_scene.instantiate()
|
||||
@@ -132,7 +163,9 @@ func test_data_source_loading():
|
||||
await process_frame
|
||||
|
||||
TestHelper.assert_true(resolution_stepper.values.size() > 0, "Resolution values loaded")
|
||||
TestHelper.assert_contains(resolution_stepper.values, "1920x1080", "Resolution data contains expected value")
|
||||
TestHelper.assert_contains(
|
||||
resolution_stepper.values, "1920x1080", "Resolution data contains expected value"
|
||||
)
|
||||
|
||||
resolution_stepper.queue_free()
|
||||
|
||||
@@ -143,11 +176,14 @@ func test_data_source_loading():
|
||||
await process_frame
|
||||
|
||||
TestHelper.assert_true(difficulty_stepper.values.size() > 0, "Difficulty values loaded")
|
||||
TestHelper.assert_contains(difficulty_stepper.values, "normal", "Difficulty data contains expected value")
|
||||
TestHelper.assert_contains(
|
||||
difficulty_stepper.values, "normal", "Difficulty data contains expected value"
|
||||
)
|
||||
TestHelper.assert_equal(1, difficulty_stepper.current_index, "Difficulty defaults to normal")
|
||||
|
||||
difficulty_stepper.queue_free()
|
||||
|
||||
|
||||
func test_value_navigation():
|
||||
TestHelper.print_step("Value Navigation")
|
||||
|
||||
@@ -167,23 +203,30 @@ func test_value_navigation():
|
||||
# Test backward navigation
|
||||
stepper_instance.change_value(-1)
|
||||
var back_value = stepper_instance.get_current_value()
|
||||
TestHelper.assert_equal(initial_value, back_value, "Backward navigation returns to original value")
|
||||
TestHelper.assert_equal(
|
||||
initial_value, back_value, "Backward navigation returns to original value"
|
||||
)
|
||||
|
||||
# Test wrap-around forward
|
||||
var max_index = stepper_instance.values.size() - 1
|
||||
stepper_instance.current_index = max_index
|
||||
stepper_instance.change_value(1)
|
||||
TestHelper.assert_equal(0, stepper_instance.current_index, "Forward navigation wraps to beginning")
|
||||
TestHelper.assert_equal(
|
||||
0, stepper_instance.current_index, "Forward navigation wraps to beginning"
|
||||
)
|
||||
|
||||
# Test wrap-around backward
|
||||
stepper_instance.current_index = 0
|
||||
stepper_instance.change_value(-1)
|
||||
TestHelper.assert_equal(max_index, stepper_instance.current_index, "Backward navigation wraps to end")
|
||||
TestHelper.assert_equal(
|
||||
max_index, stepper_instance.current_index, "Backward navigation wraps to end"
|
||||
)
|
||||
|
||||
# Restore original state
|
||||
stepper_instance.current_index = original_index
|
||||
stepper_instance._update_display()
|
||||
|
||||
|
||||
func test_custom_values():
|
||||
TestHelper.print_step("Custom Values")
|
||||
|
||||
@@ -202,27 +245,41 @@ func test_custom_values():
|
||||
TestHelper.assert_equal(3, stepper_instance.values.size(), "Custom values set correctly")
|
||||
TestHelper.assert_equal("apple", stepper_instance.values[0], "First custom value correct")
|
||||
TestHelper.assert_equal(0, stepper_instance.current_index, "Index reset to 0 for custom values")
|
||||
TestHelper.assert_equal("apple", stepper_instance.get_current_value(), "Current value matches first custom value")
|
||||
TestHelper.assert_equal(
|
||||
"apple", stepper_instance.get_current_value(), "Current value matches first custom value"
|
||||
)
|
||||
|
||||
# Test custom values with display names
|
||||
var custom_display_names = ["Red Apple", "Yellow Banana", "Red Cherry"]
|
||||
stepper_instance.setup_custom_values(custom_values, custom_display_names)
|
||||
|
||||
TestHelper.assert_equal(3, stepper_instance.display_names.size(), "Custom display names set correctly")
|
||||
TestHelper.assert_equal("Red Apple", stepper_instance.display_names[0], "First display name correct")
|
||||
TestHelper.assert_equal(
|
||||
3, stepper_instance.display_names.size(), "Custom display names set correctly"
|
||||
)
|
||||
TestHelper.assert_equal(
|
||||
"Red Apple", stepper_instance.display_names[0], "First display name correct"
|
||||
)
|
||||
|
||||
# Test navigation with custom values
|
||||
stepper_instance.change_value(1)
|
||||
TestHelper.assert_equal("banana", stepper_instance.get_current_value(), "Navigation works with custom values")
|
||||
TestHelper.assert_equal(
|
||||
"banana", stepper_instance.get_current_value(), "Navigation works with custom values"
|
||||
)
|
||||
|
||||
# Test set_current_value
|
||||
stepper_instance.set_current_value("cherry")
|
||||
TestHelper.assert_equal("cherry", stepper_instance.get_current_value(), "set_current_value works correctly")
|
||||
TestHelper.assert_equal(2, stepper_instance.current_index, "Index updated correctly by set_current_value")
|
||||
TestHelper.assert_equal(
|
||||
"cherry", stepper_instance.get_current_value(), "set_current_value works correctly"
|
||||
)
|
||||
TestHelper.assert_equal(
|
||||
2, stepper_instance.current_index, "Index updated correctly by set_current_value"
|
||||
)
|
||||
|
||||
# Test invalid value
|
||||
stepper_instance.set_current_value("grape")
|
||||
TestHelper.assert_equal("cherry", stepper_instance.get_current_value(), "Invalid value doesn't change current value")
|
||||
TestHelper.assert_equal(
|
||||
"cherry", stepper_instance.get_current_value(), "Invalid value doesn't change current value"
|
||||
)
|
||||
|
||||
# Restore original state
|
||||
stepper_instance.values = original_values
|
||||
@@ -230,6 +287,7 @@ func test_custom_values():
|
||||
stepper_instance.current_index = original_index
|
||||
stepper_instance._update_display()
|
||||
|
||||
|
||||
func test_input_handling():
|
||||
TestHelper.print_step("Input Handling")
|
||||
|
||||
@@ -242,12 +300,18 @@ func test_input_handling():
|
||||
# Test left input action
|
||||
var left_handled = stepper_instance.handle_input_action("move_left")
|
||||
TestHelper.assert_true(left_handled, "Left input action handled")
|
||||
TestHelper.assert_not_equal(original_value, stepper_instance.get_current_value(), "Left action changes value")
|
||||
TestHelper.assert_not_equal(
|
||||
original_value, stepper_instance.get_current_value(), "Left action changes value"
|
||||
)
|
||||
|
||||
# Test right input action
|
||||
var right_handled = stepper_instance.handle_input_action("move_right")
|
||||
TestHelper.assert_true(right_handled, "Right input action handled")
|
||||
TestHelper.assert_equal(original_value, stepper_instance.get_current_value(), "Right action returns to original value")
|
||||
TestHelper.assert_equal(
|
||||
original_value,
|
||||
stepper_instance.get_current_value(),
|
||||
"Right action returns to original value"
|
||||
)
|
||||
|
||||
# Test invalid input action
|
||||
var invalid_handled = stepper_instance.handle_input_action("invalid_action")
|
||||
@@ -257,12 +321,19 @@ func test_input_handling():
|
||||
if stepper_instance.left_button:
|
||||
var before_left = stepper_instance.get_current_value()
|
||||
stepper_instance._on_left_button_pressed()
|
||||
TestHelper.assert_not_equal(before_left, stepper_instance.get_current_value(), "Left button press changes value")
|
||||
TestHelper.assert_not_equal(
|
||||
before_left, stepper_instance.get_current_value(), "Left button press changes value"
|
||||
)
|
||||
|
||||
if stepper_instance.right_button:
|
||||
var before_right = stepper_instance.get_current_value()
|
||||
stepper_instance._on_right_button_pressed()
|
||||
TestHelper.assert_equal(original_value, stepper_instance.get_current_value(), "Right button press returns to original")
|
||||
TestHelper.assert_equal(
|
||||
original_value,
|
||||
stepper_instance.get_current_value(),
|
||||
"Right button press returns to original"
|
||||
)
|
||||
|
||||
|
||||
func test_visual_feedback():
|
||||
TestHelper.print_step("Visual Feedback")
|
||||
@@ -277,13 +348,19 @@ func test_visual_feedback():
|
||||
# Test highlighting
|
||||
stepper_instance.set_highlighted(true)
|
||||
TestHelper.assert_true(stepper_instance.is_highlighted, "Highlighted state set correctly")
|
||||
TestHelper.assert_true(stepper_instance.scale.x > original_scale.x, "Scale increased when highlighted")
|
||||
TestHelper.assert_true(
|
||||
stepper_instance.scale.x > original_scale.x, "Scale increased when highlighted"
|
||||
)
|
||||
|
||||
# Test unhighlighting
|
||||
stepper_instance.set_highlighted(false)
|
||||
TestHelper.assert_false(stepper_instance.is_highlighted, "Highlighted state cleared correctly")
|
||||
TestHelper.assert_equal(original_scale, stepper_instance.scale, "Scale restored when unhighlighted")
|
||||
TestHelper.assert_equal(original_modulate, stepper_instance.modulate, "Modulate restored when unhighlighted")
|
||||
TestHelper.assert_equal(
|
||||
original_scale, stepper_instance.scale, "Scale restored when unhighlighted"
|
||||
)
|
||||
TestHelper.assert_equal(
|
||||
original_modulate, stepper_instance.modulate, "Modulate restored when unhighlighted"
|
||||
)
|
||||
|
||||
# Test display update
|
||||
if stepper_instance.value_display:
|
||||
@@ -291,6 +368,7 @@ func test_visual_feedback():
|
||||
TestHelper.assert_true(current_text.length() > 0, "Value display has text content")
|
||||
TestHelper.assert_not_equal("N/A", current_text, "Value display shows valid content")
|
||||
|
||||
|
||||
func test_settings_integration():
|
||||
TestHelper.print_step("Settings Integration")
|
||||
|
||||
@@ -321,6 +399,7 @@ func test_settings_integration():
|
||||
# Restore original language
|
||||
root.get_node("SettingsManager").set_setting("language", original_lang)
|
||||
|
||||
|
||||
func test_boundary_conditions():
|
||||
TestHelper.print_step("Boundary Conditions")
|
||||
|
||||
@@ -333,7 +412,9 @@ func test_boundary_conditions():
|
||||
test_viewport.add_child(empty_stepper)
|
||||
await process_frame
|
||||
|
||||
TestHelper.assert_equal("", empty_stepper.get_current_value(), "Empty values array returns empty string")
|
||||
TestHelper.assert_equal(
|
||||
"", empty_stepper.get_current_value(), "Empty values array returns empty string"
|
||||
)
|
||||
|
||||
# Test change_value with empty array
|
||||
empty_stepper.change_value(1) # Should not crash
|
||||
@@ -346,17 +427,22 @@ func test_boundary_conditions():
|
||||
# Test negative index handling
|
||||
stepper_instance.current_index = -1
|
||||
stepper_instance._update_display()
|
||||
TestHelper.assert_equal("N/A", stepper_instance.value_display.text, "Negative index shows N/A")
|
||||
TestHelper.assert_equal(
|
||||
"N/A", stepper_instance.value_display.text, "Negative index shows N/A"
|
||||
)
|
||||
|
||||
# Test out-of-bounds index handling
|
||||
stepper_instance.current_index = stepper_instance.values.size()
|
||||
stepper_instance._update_display()
|
||||
TestHelper.assert_equal("N/A", stepper_instance.value_display.text, "Out-of-bounds index shows N/A")
|
||||
TestHelper.assert_equal(
|
||||
"N/A", stepper_instance.value_display.text, "Out-of-bounds index shows N/A"
|
||||
)
|
||||
|
||||
# Restore valid index
|
||||
stepper_instance.current_index = 0
|
||||
stepper_instance._update_display()
|
||||
|
||||
|
||||
func test_error_handling():
|
||||
TestHelper.print_step("Error Handling")
|
||||
|
||||
@@ -376,7 +462,9 @@ func test_error_handling():
|
||||
# Test get_control_name
|
||||
var control_name = stepper_instance.get_control_name()
|
||||
TestHelper.assert_true(control_name.ends_with("_stepper"), "Control name has correct suffix")
|
||||
TestHelper.assert_true(control_name.begins_with(stepper_instance.data_source), "Control name includes data source")
|
||||
TestHelper.assert_true(
|
||||
control_name.begins_with(stepper_instance.data_source), "Control name includes data source"
|
||||
)
|
||||
|
||||
# Test custom values with mismatched arrays
|
||||
var values_3 = ["a", "b", "c"]
|
||||
@@ -385,12 +473,17 @@ func test_error_handling():
|
||||
|
||||
# Should handle gracefully - display_names should be duplicated from values
|
||||
TestHelper.assert_equal(3, stepper_instance.values.size(), "Values array size preserved")
|
||||
TestHelper.assert_equal(2, stepper_instance.display_names.size(), "Display names size preserved as provided")
|
||||
TestHelper.assert_equal(
|
||||
2, stepper_instance.display_names.size(), "Display names size preserved as provided"
|
||||
)
|
||||
|
||||
# Test navigation with mismatched arrays
|
||||
stepper_instance.current_index = 2 # Index where display_names doesn't exist
|
||||
stepper_instance._update_display()
|
||||
TestHelper.assert_equal("c", stepper_instance.value_display.text, "Falls back to value when display name missing")
|
||||
TestHelper.assert_equal(
|
||||
"c", stepper_instance.value_display.text, "Falls back to value when display name missing"
|
||||
)
|
||||
|
||||
|
||||
func cleanup_tests():
|
||||
TestHelper.print_step("Cleanup")
|
||||
@@ -409,4 +502,4 @@ func cleanup_tests():
|
||||
# Wait for cleanup
|
||||
await process_frame
|
||||
|
||||
TestHelper.assert_true(true, "Test cleanup completed")
|
||||
TestHelper.assert_true(true, "Test cleanup completed")
|
||||
|
||||
Reference in New Issue
Block a user