import XCTest @testable import TVAnarchyCore final class LibraryDisplayNamesTests: XCTestCase { private var tmp: URL! private var store: TitleLibraryStore! override func setUp() { tmp = FileManager.default.temporaryDirectory .appendingPathComponent("tv-anarchy-display-\(UUID().uuidString)", isDirectory: true) try? FileManager.default.createDirectory(at: tmp, withIntermediateDirectories: true) setenv("TV_ANARCHY_STATE_DIR", tmp.path, 1) store = TitleLibraryStore() TitleLibrary.store = store } override func tearDown() { unsetenv("TV_ANARCHY_STATE_DIR") try? FileManager.default.removeItem(at: tmp) TitleLibrary.store = TitleLibraryStore() } func testPsychReleaseFilenameUsesCodeNotDots() { let path = "/media/tv/Psych/Psych.S01E04.720p.WEB-DL.x264-GROUP.mkv" let resolved = LibraryDisplayNames.resolve(showName: "Psych", path: path, titleLibrary: store) XCTAssertEqual(resolved.displayName, "S01E04") XCTAssertNil(resolved.episodeTitle) } func testTitleAfterSxxEyyInFilename() { let path = "/m/cartoons/Futurama/Futurama S03E01 The Honking.mp4" let resolved = LibraryDisplayNames.resolve(showName: "Futurama", path: path, titleLibrary: store) XCTAssertEqual(resolved.displayName, "S03E01 · The Honking") XCTAssertEqual(resolved.episodeTitle, "The Honking") } func testLibraryHitSkipsRegexWrite() { let key = ContentID.canonical(work: "Psych", season: 1, episode: 4) store.observe(TitleObservation(contentKey: key, showName: "Psych", season: 1, episode: 4, episodeTitle: "Shawn vs. the Red Phantom", provenance: .tvmaze)) let path = "/media/tv/Psych/Psych.S01E04.720p.WEB-DL.x264-GROUP.mkv" let resolved = LibraryDisplayNames.resolve(showName: "Psych", path: path, titleLibrary: store) XCTAssertEqual(resolved.displayName, "S01E04 · Shawn vs. the Red Phantom") XCTAssertEqual(resolved.episodeTitle, "Shawn vs. the Red Phantom") } func testTitleAfterSxxEyyHelper() { XCTAssertEqual( LibraryDisplayNames.titleAfterSxxEyy( "Dharma & Greg S01E03 Shower the People You Love With Love.mkv" ), "Shower the People You Love With Love" ) } }