Files
MusicPlayer/tests/unit/test_music_player_time.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

70 lines
2.0 KiB
GDScript

extends GdUnitTestSuite
## How the music player shows a song's time, including the hidden parts.
var _music_player: MusicPlayer
var _hide_beginning: bool
var _hide_length: bool
var _hide_for_seconds: float
func before_test() -> void:
_music_player = auto_free(MusicPlayer.new())
_hide_beginning = Settings.hide_beginning
_hide_length = Settings.hide_length
_hide_for_seconds = Settings.hide_for_seconds
Settings.hide_beginning = false
Settings.hide_length = false
Settings.hide_for_seconds = 5.0
func after_test() -> void:
Settings.hide_beginning = _hide_beginning
Settings.hide_length = _hide_length
Settings.hide_for_seconds = _hide_for_seconds
func test_format_time() -> void:
assert_str(_music_player.format_time(0.0)).is_equal("00:00")
assert_str(_music_player.format_time(65.0)).is_equal("01:05")
assert_str(_music_player.format_time(3661.0)).is_equal("61:01")
func test_format_time_rounds_up_into_next_minute() -> void:
assert_str(_music_player.format_time(59.6)).is_equal("01:00")
func test_format_text_shows_position_and_length() -> void:
assert_str(_music_player.format_text(10.0, 100.0)).is_equal("00:10 / 01:40")
func test_format_text_hides_length() -> void:
Settings.hide_length = true
assert_str(_music_player.format_text(10.0, 100.0)).is_equal("00:10 / ??:??")
func test_format_text_hides_position_at_start() -> void:
Settings.hide_beginning = true
assert_str(_music_player.format_text(3.0, 100.0)).is_equal("??:?? / 01:40")
func test_format_text_shows_position_after_hidden_start() -> void:
Settings.hide_beginning = true
assert_str(_music_player.format_text(5.0, 100.0)).is_equal("00:05 / 01:40")
func test_format_text_hides_everything_at_start() -> void:
Settings.hide_beginning = true
Settings.hide_length = true
assert_str(_music_player.format_text(3.0, 100.0)).is_equal("??:?? / ??:??")
func test_format_text_keeps_length_hidden_after_hidden_start() -> void:
Settings.hide_beginning = true
Settings.hide_length = true
assert_str(_music_player.format_text(5.0, 100.0)).is_equal("00:05 / ??:??")