@@ -344,6 +344,96 @@ func Test_viewRun(t *testing.T) {
344344 },
345345 wantOut : "cicada.txt\n foo.md\n " ,
346346 },
347+ {
348+ name : "truncated file with raw and filename" ,
349+ isTTY : true ,
350+ opts : & ViewOptions {
351+ Selector : "1234" ,
352+ Raw : true ,
353+ Filename : "large.txt" ,
354+ },
355+ mockGist : & shared.Gist {
356+ Files : map [string ]* shared.GistFile {
357+ "large.txt" : {
358+ Content : "This is truncated content..." ,
359+ Type : "text/plain" ,
360+ Truncated : true ,
361+ RawURL : "https://gist.githubusercontent.com/user/1234/raw/large.txt" ,
362+ },
363+ },
364+ },
365+ wantOut : "This is the full content of the large file retrieved from raw URL\n " ,
366+ },
367+ {
368+ name : "truncated file without raw flag" ,
369+ isTTY : true ,
370+ opts : & ViewOptions {
371+ Selector : "1234" ,
372+ Raw : false ,
373+ Filename : "large.txt" ,
374+ },
375+ mockGist : & shared.Gist {
376+ Files : map [string ]* shared.GistFile {
377+ "large.txt" : {
378+ Content : "This is truncated content..." ,
379+ Type : "text/plain" ,
380+ Truncated : true ,
381+ RawURL : "https://gist.githubusercontent.com/user/1234/raw/large.txt" ,
382+ },
383+ },
384+ },
385+ wantOut : "This is the full content of the large file retrieved from raw URL\n " ,
386+ },
387+ {
388+ name : "multiple files with one truncated" ,
389+ isTTY : true ,
390+ opts : & ViewOptions {
391+ Selector : "1234" ,
392+ Raw : true ,
393+ },
394+ mockGist : & shared.Gist {
395+ Description : "Mixed files" ,
396+ Files : map [string ]* shared.GistFile {
397+ "normal.txt" : {
398+ Content : "normal content" ,
399+ Type : "text/plain" ,
400+ },
401+ "large.txt" : {
402+ Content : "This is truncated content..." ,
403+ Type : "text/plain" ,
404+ Truncated : true ,
405+ RawURL : "https://gist.githubusercontent.com/user/1234/raw/large.txt" ,
406+ },
407+ },
408+ },
409+ wantOut : "Mixed files\n \n large.txt\n \n This is the full content of the large file retrieved from raw URL\n \n normal.txt\n \n normal content\n " ,
410+ },
411+ {
412+ name : "multiple files with subsequent files truncated as empty" ,
413+ isTTY : true ,
414+ opts : & ViewOptions {
415+ Selector : "1234" ,
416+ Raw : true ,
417+ },
418+ mockGist : & shared.Gist {
419+ Description : "Large gist with multiple files" ,
420+ Files : map [string ]* shared.GistFile {
421+ "large.txt" : {
422+ Content : "This is truncated content..." ,
423+ Type : "text/plain" ,
424+ Truncated : true ,
425+ RawURL : "https://gist.githubusercontent.com/user/1234/raw/large.txt" ,
426+ },
427+ "also-truncated.txt" : {
428+ Type : "text/plain" ,
429+ Content : "" , // Empty because GitHub truncates subsequent files
430+ Truncated : true , // Subsequent files are also marked as truncated
431+ RawURL : "https://gist.githubusercontent.com/user/1234/raw/also-truncated.txt" ,
432+ },
433+ },
434+ },
435+ wantOut : "Large gist with multiple files\n \n also-truncated.txt\n \n This is the full content of the also-truncated file retrieved from raw URL\n \n large.txt\n \n This is the full content of the large file retrieved from raw URL\n " ,
436+ },
347437 }
348438
349439 for _ , tt := range tests {
@@ -354,6 +444,18 @@ func Test_viewRun(t *testing.T) {
354444 } else {
355445 reg .Register (httpmock .REST ("GET" , "gists/1234" ),
356446 httpmock .JSONResponse (tt .mockGist ))
447+
448+ for filename , file := range tt .mockGist .Files {
449+ if file .Truncated && file .RawURL != "" {
450+ if filename == "large.txt" {
451+ reg .Register (httpmock .REST ("GET" , "user/1234/raw/large.txt" ),
452+ httpmock .StringResponse ("This is the full content of the large file retrieved from raw URL" ))
453+ } else if filename == "also-truncated.txt" {
454+ reg .Register (httpmock .REST ("GET" , "user/1234/raw/also-truncated.txt" ),
455+ httpmock .StringResponse ("This is the full content of the also-truncated file retrieved from raw URL" ))
456+ }
457+ }
458+ }
357459 }
358460
359461 if tt .opts == nil {
0 commit comments