"""Tests for pure utility functions in fungus.utils_pure.""" from fungus.utils_pure import format_title, is_executable_in_whitelist class TestFormatTitle: def test_basic_title(self): assert format_title("My Game") == "my-game" def test_removes_special_chars(self): assert format_title("Game! @#$% Title") == "game-title" def test_lowercases(self): assert format_title("UPPERCASE GAME") == "uppercase-game" def test_multiple_spaces_to_hyphens(self): assert format_title("game with spaces") == "game-with-spaces" def test_empty_string(self): assert format_title("") == "" def test_whitespace_only(self): assert format_title(" ") == "" def test_leading_trailing_whitespace(self): assert format_title(" My Game ") == "my-game" def test_numbers_preserved(self): assert format_title("Game 2024") == "game-2024" def test_unicode_removal(self): # Non-ASCII characters are stripped by the regex result = format_title("Game café") assert result == "game-caf" # é is removed, not normalized class TestIsExecutableInWhitelist: def test_empty_whitelist_allows_everything(self): assert is_executable_in_whitelist("/some/path/game", []) is True def test_exact_dir_match(self): game_dirs = ["/home/user/Games"] assert is_executable_in_whitelist("/home/user/Games/game.exe", game_dirs) is True def test_subdir_match(self): game_dirs = ["/home/user/Games"] assert ( is_executable_in_whitelist( "/home/user/Games/subfolder/game.exe", game_dirs ) is True ) def test_no_match_outside_whitelist(self): game_dirs = ["/home/user/Games"] assert ( is_executable_in_whitelist("/opt/other/game.exe", game_dirs) is False ) def test_multiple_whitelisted_dirs(self): game_dirs = ["/home/user/Games", "/mnt/steam/steamapps"] assert ( is_executable_in_whitelist("/mnt/steam/steamapps/game.exe", game_dirs) is True ) assert ( is_executable_in_whitelist("/home/user/Games/another/game.exe", game_dirs) is True ) assert ( is_executable_in_whitelist("/tmp/hacker/game.exe", game_dirs) is False ) def test_resolves_symlinks(self): """Should use realpath to resolve symlinks before checking.""" game_dirs = ["/home/user/Games"] # Even with a symlink-like path, realpath normalization matters # We can't easily create symlinks in tests, but we verify the # function uses os.path.realpath internally. assert is_executable_in_whitelist("/home/user/Games/game.exe", game_dirs) is True def test_prefix_match_prevents_escape(self): """Game dirs starting with same prefix should not match.""" game_dirs = ["/home/user/Games"] # /home/user/GamesExtra should NOT match /home/user/Games assert ( is_executable_in_whitelist("/home/user/GamesExtra/game.exe", game_dirs) is False )