8c790357d3
- tests/runner.gd: lightweight headless test runner (TAP format output) - tests/weapons.gd: 6 tests for weapon registry and stats - tests/team.gd: 5 tests for team assignment and balancing - tests/economy.gd: 6 tests for economy constants and loss streaks - tests/bootstrapper.gd: 4 tests for LAN bootstrapper input parsing Run with: godot --headless -s tests/runner.gd --path . All 21 tests pass on Linux and Windows.
71 lines
1.9 KiB
GDScript
71 lines
1.9 KiB
GDScript
extends RefCounted
|
|
|
|
## Bootstrapper network input tests.
|
|
## Tests the input parsing and validation in lan-bootstrapper.gd.
|
|
|
|
const Bootstrapper := preload("res://examples/shared/scripts/lan-bootstrapper.gd")
|
|
|
|
func test_empty_address_rejected() -> String:
|
|
var bp := Bootstrapper.new()
|
|
bp.address_input = LineEdit.new()
|
|
bp.port_input = LineEdit.new()
|
|
bp.connect_ui = Control.new()
|
|
|
|
bp.address_input.text = ""
|
|
bp.port_input.text = "34201"
|
|
|
|
var result = bp._parse_input()
|
|
if not result.is_empty():
|
|
return "Empty address should return empty dict"
|
|
return ""
|
|
|
|
func test_valid_input_parsed() -> String:
|
|
var bp := Bootstrapper.new()
|
|
bp.address_input = LineEdit.new()
|
|
bp.port_input = LineEdit.new()
|
|
bp.connect_ui = Control.new()
|
|
|
|
bp.address_input.text = "192.168.0.127"
|
|
bp.port_input.text = "34201"
|
|
|
|
var result = bp._parse_input()
|
|
if result.is_empty():
|
|
return "Valid input should return filled dict"
|
|
if result.address != "192.168.0.127":
|
|
return "Address mismatch"
|
|
if result.port != 34201:
|
|
return "Port mismatch: got %d" % result.port
|
|
return ""
|
|
|
|
func test_invalid_port_rejected() -> String:
|
|
var bp := Bootstrapper.new()
|
|
bp.address_input = LineEdit.new()
|
|
bp.port_input = LineEdit.new()
|
|
bp.connect_ui = Control.new()
|
|
|
|
bp.address_input.text = "192.168.0.127"
|
|
bp.port_input.text = "not-a-number"
|
|
|
|
var result = bp._parse_input()
|
|
if not result.is_empty():
|
|
return "Non-numeric port should return empty dict"
|
|
return ""
|
|
|
|
func test_localhost_accepted() -> String:
|
|
var bp := Bootstrapper.new()
|
|
bp.address_input = LineEdit.new()
|
|
bp.port_input = LineEdit.new()
|
|
bp.connect_ui = Control.new()
|
|
|
|
bp.address_input.text = "localhost"
|
|
bp.port_input.text = "34197"
|
|
|
|
var result = bp._parse_input()
|
|
if result.is_empty():
|
|
return "localhost should be valid"
|
|
if result.address != "localhost":
|
|
return "Address should be 'localhost'"
|
|
if result.port != 34197:
|
|
return "Port 34197 should be parsed"
|
|
return ""
|