@@ -36,6 +36,7 @@ describe("splitMediaFromOutput", () => {
3636
3737 function expectAcceptedMediaPathCase ( expectedPath : string , input : string ) {
3838 expectParsedMediaOutputCase ( input , { mediaUrls : [ expectedPath ] } ) ;
39+ expect ( splitMediaFromOutput ( input ) . segments ) . toEqual ( [ { type : "media" , url : expectedPath } ] ) ;
3940 }
4041
4142 function expectRejectedMediaPathCase ( input : string ) {
@@ -95,6 +96,47 @@ describe("splitMediaFromOutput", () => {
9596 expectAcceptedMediaPathCase ( expectedPath , input ) ;
9697 } ) ;
9798
99+ it . each ( [
100+ [ "bare image" , "Generated image\nMEDIA:image.png" , [ "image.png" ] ] ,
101+ [ "bare audio" , "Generated audio\nMEDIA:voice.ogg" , [ "voice.ogg" ] ] ,
102+ [ "bare document" , "Generated document\nMEDIA:report.pdf" , [ "report.pdf" ] ] ,
103+ [ "caption after bare filename" , "MEDIA:image.png\nGenerated image" , [ "image.png" ] ] ,
104+ [ "quoted bare filename" , 'Generated image\nMEDIA:"image.png"' , [ "image.png" ] ] ,
105+ [
106+ "quoted bare filename with spaces" ,
107+ 'Generated image\nMEDIA:"render final.png"' ,
108+ [ "render final.png" ] ,
109+ ] ,
110+ [ "unquoted bare filename with spaces" , "MEDIA:render final.png" , [ "render final.png" ] ] ,
111+ [
112+ "remote followed by bare filename" ,
113+ "MEDIA:https://example.com/remote.png\nMEDIA:image.png" ,
114+ [ "https://example.com/remote.png" , "image.png" ] ,
115+ ] ,
116+ [
117+ "bare filenames surrounding remote media" ,
118+ "MEDIA:image.png\nMEDIA:https://example.com/remote.png\nMEDIA:voice.ogg" ,
119+ [ "image.png" , "https://example.com/remote.png" , "voice.ogg" ] ,
120+ ] ,
121+ [ "explicit relative sibling" , "MEDIA:./image.png" , [ "./image.png" ] ] ,
122+ [ "absolute sibling" , "MEDIA:/tmp/image.png" , [ "/tmp/image.png" ] ] ,
123+ [
124+ "multiple paths on one directive" ,
125+ "MEDIA:/tmp/image.png /tmp/voice.ogg" ,
126+ [ "/tmp/image.png" , "/tmp/voice.ogg" ] ,
127+ ] ,
128+ ] as const ) (
129+ "projects every accepted media URL into ordered segments: %s" ,
130+ ( _name , input , urls ) => {
131+ const result = splitMediaFromOutput ( input ) ;
132+
133+ expect ( result . mediaUrls ) . toEqual ( urls ) ;
134+ expect ( result . segments ?. filter ( ( segment ) => segment . type === "media" ) ) . toEqual (
135+ urls . map ( ( url ) => ( { type : "media" , url } ) ) ,
136+ ) ;
137+ } ,
138+ ) ;
139+
98140 it . each ( [
99141 [ "MEDIA:/tmp/a.png /tmp/b.png" , [ "/tmp/a.png" , "/tmp/b.png" ] ] ,
100142 [ "MEDIA:media/a.png media/b.png" , [ "media/a.png" , "media/b.png" ] ] ,
0 commit comments