···
8
+
func TestSplitPatches(t *testing.T) {
15
+
name: "Empty input",
17
+
expected: []string{},
20
+
name: "No valid patches",
21
+
input: "This is not a patch\nJust some random text",
22
+
expected: []string{},
25
+
name: "Single patch",
26
+
input: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
27
+
From: Author <author@example.com>
28
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
29
+
Subject: [PATCH] Example patch
31
+
diff --git a/file.txt b/file.txt
32
+
index 123456..789012 100644
41
+
`From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
42
+
From: Author <author@example.com>
43
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
44
+
Subject: [PATCH] Example patch
46
+
diff --git a/file.txt b/file.txt
47
+
index 123456..789012 100644
58
+
name: "Two patches",
59
+
input: `From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
60
+
From: Author <author@example.com>
61
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
62
+
Subject: [PATCH 1/2] First patch
64
+
diff --git a/file1.txt b/file1.txt
65
+
index 123456..789012 100644
73
+
From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
74
+
From: Author <author@example.com>
75
+
Date: Wed, 16 Apr 2025 11:03:11 +0300
76
+
Subject: [PATCH 2/2] Second patch
78
+
diff --git a/file2.txt b/file2.txt
79
+
index abcdef..ghijkl 100644
88
+
`From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
89
+
From: Author <author@example.com>
90
+
Date: Wed, 16 Apr 2025 11:01:00 +0300
91
+
Subject: [PATCH 1/2] First patch
93
+
diff --git a/file1.txt b/file1.txt
94
+
index 123456..789012 100644
102
+
`From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
103
+
From: Author <author@example.com>
104
+
Date: Wed, 16 Apr 2025 11:03:11 +0300
105
+
Subject: [PATCH 2/2] Second patch
107
+
diff --git a/file2.txt b/file2.txt
108
+
index abcdef..ghijkl 100644
119
+
name: "Patches with additional text between them",
120
+
input: `Some text before the patches
122
+
From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
123
+
From: Author <author@example.com>
124
+
Subject: [PATCH] First patch
130
+
Some text between patches
132
+
From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
133
+
From: Author <author@example.com>
134
+
Subject: [PATCH] Second patch
140
+
Text after patches`,
141
+
expected: []string{
142
+
`From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
143
+
From: Author <author@example.com>
144
+
Subject: [PATCH] First patch
150
+
Some text between patches`,
151
+
`From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
152
+
From: Author <author@example.com>
153
+
Subject: [PATCH] Second patch
159
+
Text after patches`,
163
+
name: "Patches with whitespace padding",
166
+
From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
167
+
From: Author <author@example.com>
175
+
From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
176
+
From: Author <author@example.com>
177
+
Subject: Another patch
183
+
expected: []string{
184
+
`From 3c5035488318164b81f60fe3adcd6c9199d76331 Mon Sep 17 00:00:00 2001
185
+
From: Author <author@example.com>
191
+
`From a9529f3b3a653329a5268f0f4067225480207e3c Mon Sep 17 00:00:00 2001
192
+
From: Author <author@example.com>
193
+
Subject: Another patch
202
+
for _, tt := range tests {
203
+
t.Run(tt.name, func(t *testing.T) {
204
+
result := splitFormatPatch(tt.input)
205
+
if !reflect.DeepEqual(result, tt.expected) {
206
+
t.Errorf("splitPatches() = %v, want %v", result, tt.expected)