@@ -39,10 +39,53 @@ describe("general pager detection", () => {
3939 expect ( looksLikePatchInput ( patch ) ) . toBe ( true ) ;
4040 } ) ;
4141
42- test ( "does not misclassify plain git pager text as a patch" , ( ) => {
43- const branchOutput = [ "* main" , " feat/persist-view-config" , " release/0.1.0" ] . join ( "\n" ) ;
42+ test ( "detects common patch shapes across line endings and terminal wrappers" , ( ) => {
43+ const patchFixtures = [
44+ [
45+ "diff --git a/src/example.ts b/src/example.ts" ,
46+ "--- a/src/example.ts" ,
47+ "+++ b/src/example.ts" ,
48+ "@@ -1 +1 @@" ,
49+ "-export const value = 1;" ,
50+ "+export const value = 2;" ,
51+ ] ,
52+ [
53+ "--- a/src/example.ts" ,
54+ "+++ b/src/example.ts" ,
55+ "@@ -1 +1,2 @@" ,
56+ "-export const value = 1;" ,
57+ "+export const value = 2;" ,
58+ "+export const extra = true;" ,
59+ ] ,
60+ [
61+ "header" ,
62+ "@@ -10,0 +11,2 @@" ,
63+ "+export const inserted = true;" ,
64+ "+export const added = true;" ,
65+ ] ,
66+ ] ;
4467
45- expect ( looksLikePatchInput ( branchOutput ) ) . toBe ( false ) ;
68+ for ( const lines of patchFixtures ) {
69+ for ( const newline of [ "\n" , "\r\n" ] ) {
70+ const patch = lines . join ( newline ) ;
71+ expect ( looksLikePatchInput ( patch ) ) . toBe ( true ) ;
72+ expect ( looksLikePatchInput ( `\u001b]0;title\u0007${ patch } \u001bPignored\u001b\\` ) ) . toBe ( true ) ;
73+ }
74+ }
75+ } ) ;
76+
77+ test ( "does not misclassify partial diff markers or plain git pager text as a patch" , ( ) => {
78+ const fixtures = [
79+ [ "* main" , " feat/persist-view-config" , " release/0.1.0" ] . join ( "\n" ) ,
80+ [ "--- separator only" , "still prose" ] . join ( "\n" ) ,
81+ [ "+++ banner only" , "still prose" ] . join ( "\n" ) ,
82+ [ "@@section heading" , "still prose" ] . join ( "\n" ) ,
83+ [ "\u001b]0;title\u0007--- looks patchy" , "+++but is just text" ] . join ( "\n" ) ,
84+ ] ;
85+
86+ for ( const fixture of fixtures ) {
87+ expect ( looksLikePatchInput ( fixture ) ) . toBe ( false ) ;
88+ }
4689 } ) ;
4790} ) ;
4891
0 commit comments