Files
MusicPlayer/tests/unit/test_search.gd
T
Sansan a0428e3475 Follow the GDScript style guide in every script
- Types on every parameter, return value and variable, and snake_case names
  (the player name limit is the constant MAX_NAME_LENGTH).
- Spelling fixes: *_triggered, character_selected, separator, caught_errors.
  The server's catched_errors key stays as the server sends it.
- Signals are connected with signal.connect() instead of by name.
- Code is ordered signals, constants, exported vars, vars, @onready vars,
  functions, with @onready on one line and two blank lines between functions.
- Every script starts with a ## description. Template comments, old LOC notes
  and commented-out code are gone, apart from the local play code.
- Lines are at most 100 characters, apart from the local play path.
- The screenshot tour turns off the blinking text cursor so pictures match.
2026-10-06 11:53:26 +02:00

65 lines
1.8 KiB
GDScript

extends GdUnitTestSuite
## How the search popup finds and orders matching soundtracks.
const SearchWindowScript: GDScript = preload("res://search_popup.gd")
var _search: Control
func before_test() -> void:
_search = auto_free(SearchWindowScript.new())
_search.set_soundtracks([
"Chrono Trigger",
"Final Fantasy VI",
"Mario & Luigi: Superstar Saga",
"Pokémon Red",
"Q*bert",
"Super Mario 64",
"The Legend of Zelda: A Link to the Past",
])
func test_plain_text_matches_case_insensitively() -> void:
assert_array(_search.find_matches("chrono")).contains_exactly(["Chrono Trigger"])
func test_contains_matches_come_before_letter_order_matches() -> void:
var matches: Array[String] = _search.find_matches("mario")
assert_array(matches).contains_exactly([
"Mario & Luigi: Superstar Saga",
"Super Mario 64",
])
func test_ignores_spaces() -> void:
assert_array(_search.find_matches("finalfantasy")).contains_exactly(["Final Fantasy VI"])
func test_and_matches_ampersand() -> void:
assert_array(_search.find_matches("mario and luigi")) \
.contains(["Mario & Luigi: Superstar Saga"])
func test_accented_letters_match_plain_letters() -> void:
assert_array(_search.find_matches("pokemon")).contains_exactly(["Pokémon Red"])
func test_letters_in_order_match_abbreviations() -> void:
assert_array(_search.find_matches("lozlttp")).contains_exactly([
"The Legend of Zelda: A Link to the Past",
])
func test_regex_characters_are_matched_literally() -> void:
assert_array(_search.find_matches("q*b")).contains_exactly(["Q*bert"])
func test_no_matches() -> void:
assert_array(_search.find_matches("metroid")).is_empty()
func test_clean_term() -> void:
assert_str(_search.clean_term("Rock 'n Roll Racing")).is_equal("rockandrollracing")
assert_str(_search.clean_term("Ys I & II")).is_equal("ysiandii")