import { describe, expect, it } from "vitest"; import { capOut, creditedOut, fold, nameLines } from "./naming"; /** * What the bar prints where it has a tag. * * The fixtures are the tags of one real file, because every rule in `naming.ts` was written after * looking at it: a promotional Neptunes box set whose rip carries the production team as its artist, * the box set as its record, the disc number and the compiler's name in brackets, and the guests * appended to the song. The bar has about fifty-two characters of column for all three names, so the * question is never "is this tag accurate" and always "what can come off without changing what the * name names". * * The other half of what is asserted is the half that must not change: `locate()`, the tooltip, the * lyrics cache key and LRCLIB all keep seeing the raw tag, so nothing here is allowed to be a place * where legibility costs an identity. */ const bootleg = { title: "Partners For Life ft. Pharrell Williams & Jamie Foxx", album: "The Neptunes: The Other Side Of The Planet (Disc 12) [Presented by ESSNSE & Cory Townes]", artist: "The Neptunes", }; describe("the bar's three names", () => { it("says the song, the record and the artist of the bootleg in three readable lines", () => { expect(nameLines(bootleg)).toEqual({ title: "Partners For Life", album: "The Other Side Of The Planet", artist: "The Neptunes", }); }); it("leaves a name that needs nothing alone", () => { const tags = { title: "Harder Better Faster Stronger", album: "Discovery", artist: "Daft Punk", }; expect(nameLines(tags)).toEqual(tags); }); it("prints a tag it cannot tidy rather than printing nothing", () => { // An album that is *only* a pressing label still has to put something on that line: a strip that // wins here is not legibility, it is a missing name. expect(nameLines({ album: "[Explicit]" }).album).toBe("[Explicit]"); expect(nameLines({ title: "feat. Someone" }).title).toBe("feat. Someone"); }); it("is the same answer twice over", () => { // The memos that call this can be re-run on a track the bar has already printed, and a second // pass that shortened things further would be a name that erodes as you look at it. const once = nameLines(bootleg); expect(nameLines(once)).toEqual(once); }); }); describe("the title", () => { it("takes the credit off the end, and keeps the song", () => { expect(creditedOut("Partners For Life ft. Pharrell Williams & Jamie Foxx")).toEqual({ bare: "Partners For Life", credited: ["Pharrell Williams", "Jamie Foxx"], }); }); it("takes a bracketed credit out of the middle", () => { expect(creditedOut("Rockstar (feat. 21 Savage)")).toEqual({ bare: "Rockstar", credited: ["21 Savage"], }); }); it("does not mistake a word in a title for a credit", () => { // *With or Without You* is a title, and the bare form of it is not *You*. expect(creditedOut("With or Without You")).toEqual({ bare: "With or Without You", credited: [], }); expect(creditedOut("Dogs vs. Cats")).toEqual({ bare: "Dogs vs. Cats", credited: [] }); }); it("leaves a live or an edit alone, because that is the title", () => { expect(nameLines({ title: "Live at the Apollo" }).title).toBe("Live at the Apollo"); expect(nameLines({ title: "Hey Jude (Single Version)" }).title).toBe( "Hey Jude (Single Version)", ); }); }); describe("the record", () => { const record = (album: string, artist = "The Neptunes") => nameLines({ album, artist }).album; it("drops the disc and the compiler", () => { expect( record("The Other Side Of The Planet (Disc 12) [Presented by ESSNSE & Cory Townes]"), ).toBe("The Other Side Of The Planet"); }); it("drops the pressings' vocabulary and nothing else", () => { expect(record("Greatest Hits (CD 1) (Vol. 2) [Bonus Tracks]")).toBe("Greatest Hits"); expect(record("Songs [2 CD]")).toBe("Songs"); expect(record("Deck [Explicit]")).toBe("Deck"); expect(record("Hours (Presented by DJ Something)")).toBe("Hours"); }); it("keeps the brackets that are part of the name", () => { // The one rule that keeps the whole strip honest: a bracket is not evidence of anything, so the // keyword is what decides, and an album called *Dark Side of the Moon* keeps its brackets. expect(record("Dark Side of the Moon", "Pink Floyd")).toBe("Dark Side of the Moon"); // Short enough not to be capped, long enough to be a real one: what is asserted is that the // bracket survived, not that the ceiling had nothing to do. expect(record("Dark Side (Original Motion Picture Soundtrack)", "Hans Zimmer")).toBe( "Dark Side (Original Motion Picture Soundtrack)", ); expect(record("Live at the Apollo", "James Brown")).toBe("Live at the Apollo"); expect(record("1981 (Deluxe Edition)", "Someone")).toBe("1981 (Deluxe Edition)"); }); it("takes the artist's name off the front only when it is the artist's name", () => { expect(record("The Neptunes: The Other Side Of The Planet")).toBe( "The Other Side Of The Planet", ); // A colon inside a title is punctuation, not a label on a shelf. expect(record("Blade Runner: The Final Cut", "Vangelis")).toBe("Blade Runner: The Final Cut"); }); }); describe("the artist", () => { it("takes the credits out of an artist tag the same way", () => { expect(nameLines({ artist: "The Neptunes feat. Pharrell Williams" }).artist).toBe( "The Neptunes", ); }); it("keeps the brackets that are the name", () => { expect(nameLines({ artist: "(hed) p.e." }).artist).toBe("(hed) p.e."); }); }); describe("the ceiling", () => { it("cuts at a word, and says so with an ellipsis", () => { const long = "The Other Side Of The Planet Disc Twelve Presented By EssNSE And Cory Townes And Everybody Else"; const cut = capOut(long); expect(cut.endsWith("…")).toBe(true); expect(cut.length).toBeLessThanOrEqual(52); // The words that stayed are whole words: an ellipsis after half a word is a rendering artefact, // not a decision about the content. expect(cut).toBe("The Other Side Of The Planet Disc Twelve Presented…"); }); it("leaves anything a bar could print uncut", () => { expect(capOut("The Other Side Of The Planet")).toBe("The Other Side Of The Planet"); }); it("cuts a first word too long to ever fit", () => { const cut = capOut("Supercalifragilisticexpialidocious"); expect(cut.length).toBeLessThanOrEqual(52); expect(cut).toBe("Supercalifragilisticexpialidocious"); expect(capOut(`${"Supercalifragilisticexpialidocious".repeat(3)}`)).toMatch(/…$/); }); it("bounds what the flex row has to argue about", () => { // The reason the ceiling is not purely cosmetic: the three names are content-sized flex items, so // an unbounded title claims width from the artist's name from behind its own ellipsis. const names = nameLines({ title: "A".repeat(400), album: "B".repeat(400), artist: "C".repeat(400), }); expect(names.title.length).toBeLessThanOrEqual(52); expect(names.album.length).toBeLessThanOrEqual(52); expect(names.artist.length).toBeLessThanOrEqual(52); }); it("takes the ceiling from the caller when the space is smaller than the bar's", () => { expect(capOut("Harder Better Faster Stronger", 12)).toBe("Harder…"); }); }); describe("the fold the whole file compares on", () => { it("makes two spellings of one name the same string", () => { expect(fold(" The Neptunes ")).toBe(fold("the neptunes")); expect(fold(null)).toBe(""); }); });