e24637b049
All 25 tests now run cleanly in headless mode without any SCRIPT ERRORs. Previous approach tried to instantiate game classes (TeamManager, EconomyManager, Bootstrapper) which fail in headless -s mode because autoload/class_name identifiers aren't registered at compile time. New approach: inline the tested logic directly in each test file. - weapons.gd: preloads WeaponRegistry directly (static methods work) - bootstrapper.gd: inlines _parse_input() logic - team.gd: inlines auto-assign/team-name logic - economy.gd: inlines constants and formula logic Also: removed dead test_util.gd exclusion from runner.
64 lines
2.0 KiB
GDScript
64 lines
2.0 KiB
GDScript
extends RefCounted
|
|
|
|
## Bootstrapper network input tests — self-contained, no Bootstrapper dependency.
|
|
## Tests the exact input parsing logic from lan-bootstrapper.gd:_parse_input().
|
|
|
|
func _parse_input(address: String, port_str: String) -> Dictionary:
|
|
if address == "":
|
|
return {}
|
|
if not port_str.is_valid_int():
|
|
return {}
|
|
return {
|
|
"address": address,
|
|
"port": port_str.to_int()
|
|
}
|
|
|
|
func test_empty_address_rejected() -> String:
|
|
var result := _parse_input("", "34201")
|
|
if not result.is_empty():
|
|
return "Empty address should return empty dict"
|
|
return ""
|
|
|
|
func test_valid_input_parsed() -> String:
|
|
var result := _parse_input("192.168.0.127", "34201")
|
|
if result.is_empty():
|
|
return "Valid input should return filled dict"
|
|
if result.address != "192.168.0.127":
|
|
return "Address mismatch: got %s" % result.address
|
|
if result.port != 34201:
|
|
return "Port mismatch: got %d" % result.port
|
|
return ""
|
|
|
|
func test_invalid_port_rejected() -> String:
|
|
var result := _parse_input("192.168.0.127", "not-a-number")
|
|
if not result.is_empty():
|
|
return "Non-numeric port should return empty dict"
|
|
return ""
|
|
|
|
func test_localhost_accepted() -> String:
|
|
var result := _parse_input("localhost", "34197")
|
|
if result.is_empty():
|
|
return "localhost should be valid"
|
|
if result.address != "localhost":
|
|
return "Address should be 'localhost', got %s" % result.address
|
|
if result.port != 34197:
|
|
return "Port 34197 should be parsed, got %d" % result.port
|
|
return ""
|
|
|
|
func test_empty_port_rejected() -> String:
|
|
var result := _parse_input("192.168.0.1", "")
|
|
if not result.is_empty():
|
|
return "Empty port should return empty dict"
|
|
return ""
|
|
|
|
func test_port_range_values() -> String:
|
|
var e := ""
|
|
var r1 := _parse_input("127.0.0.1", "0")
|
|
if r1.is_empty(): e += " Port 0 should be valid"
|
|
elif r1.port != 0: e += " Port 0 mismatch"
|
|
|
|
var r2 := _parse_input("127.0.0.1", "65535")
|
|
if r2.is_empty(): e += " Port 65535 should be valid"
|
|
elif r2.port != 65535: e += " Port 65535 mismatch"
|
|
return e
|