Adds UIStrings autoload that loads display text from a YAML file, replacing hardcoded strings in HUD and interaction prompt. Copy team can now author UI microcopy in client/data/ui-strings.yaml without touching GDScript. Includes 38 strings across 5 categories and 16 gdUnit4 tests for the parser and lookup API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
83 lines
2.9 KiB
GDScript
83 lines
2.9 KiB
GDScript
class_name TestUIStrings
|
|
extends GdUnitTestSuite
|
|
|
|
# Tests for ticket #409: UI string loading system.
|
|
# Covers YAML parsing, autoload lookup, and fallback behavior.
|
|
|
|
|
|
# -- YAML parser: basic behavior --
|
|
|
|
func test_parse_simple_key_value() -> void:
|
|
var yaml := "section:\n key: value"
|
|
var result := UIStrings._parse_yaml(yaml)
|
|
assert_that(result.has("section.key")).is_true()
|
|
assert_that(result["section.key"]).is_equal("value")
|
|
|
|
func test_parse_quoted_value() -> void:
|
|
var yaml := "section:\n key: \"hello world\""
|
|
var result := UIStrings._parse_yaml(yaml)
|
|
assert_that(result["section.key"]).is_equal("hello world")
|
|
|
|
func test_parse_multiple_sections() -> void:
|
|
var yaml := "hud:\n mode: Mode\ninteraction:\n talk: Talk"
|
|
var result := UIStrings._parse_yaml(yaml)
|
|
assert_that(result.has("hud.mode")).is_true()
|
|
assert_that(result.has("interaction.talk")).is_true()
|
|
assert_that(result["hud.mode"]).is_equal("Mode")
|
|
assert_that(result["interaction.talk"]).is_equal("Talk")
|
|
|
|
func test_parse_skips_comments() -> void:
|
|
var yaml := "# comment\nsection:\n key: value\n # another comment"
|
|
var result := UIStrings._parse_yaml(yaml)
|
|
assert_that(result.size()).is_equal(1)
|
|
|
|
func test_parse_skips_empty_lines() -> void:
|
|
var yaml := "section:\n\n key: value\n\n"
|
|
var result := UIStrings._parse_yaml(yaml)
|
|
assert_that(result["section.key"]).is_equal("value")
|
|
|
|
func test_parse_empty_string() -> void:
|
|
var result := UIStrings._parse_yaml("")
|
|
assert_that(result.size()).is_equal(0)
|
|
|
|
func test_parse_value_with_colon() -> void:
|
|
var yaml := "hud:\n time: \"12:30\""
|
|
var result := UIStrings._parse_yaml(yaml)
|
|
assert_that(result["hud.time"]).is_equal("12:30")
|
|
|
|
func test_parse_multiple_keys_per_section() -> void:
|
|
var yaml := "hud:\n mode: Mode\n time: Time\n health: Health"
|
|
var result := UIStrings._parse_yaml(yaml)
|
|
assert_that(result.size()).is_equal(3)
|
|
assert_that(result["hud.mode"]).is_equal("Mode")
|
|
assert_that(result["hud.time"]).is_equal("Time")
|
|
assert_that(result["hud.health"]).is_equal("Health")
|
|
|
|
|
|
# -- Autoload: registration and file loading --
|
|
|
|
func test_autoload_registered() -> void:
|
|
assert_that(UIStrings).is_not_null()
|
|
|
|
func test_autoload_loaded_strings() -> void:
|
|
assert_that(UIStrings.has_key("hud.mode_label")).is_true()
|
|
|
|
func test_get_text_returns_value() -> void:
|
|
assert_that(UIStrings.get_text("hud.mode_label")).is_equal("Mode")
|
|
|
|
func test_get_text_interaction_prefix() -> void:
|
|
assert_that(UIStrings.get_text("interaction.prompt_prefix")).is_equal("E")
|
|
|
|
func test_get_text_missing_key_returns_key() -> void:
|
|
var result := UIStrings.get_text("nonexistent.key")
|
|
assert_that(result).is_equal("nonexistent.key")
|
|
|
|
func test_get_all_keys_not_empty() -> void:
|
|
assert_that(UIStrings.get_all_keys().size()).is_greater(0)
|
|
|
|
func test_has_key_true_for_existing() -> void:
|
|
assert_that(UIStrings.has_key("interaction.talk")).is_true()
|
|
|
|
func test_has_key_false_for_missing() -> void:
|
|
assert_that(UIStrings.has_key("nonexistent.key")).is_false()
|