@@ -185,3 +185,42 @@ See the License for the specific language governing permissions and
185
185
limitations under the License.` ))
186
186
require .Nil (t , issue )
187
187
}
188
+
189
+ func TestFix (t * testing.T ) {
190
+ const src = `// mycompany.net
191
+ // SPDX-License-Identifier: Foo
192
+
193
+ // Package foo
194
+ package foo
195
+
196
+ func Foo() { println("Foo") }
197
+ `
198
+
199
+ a := goheader .New (
200
+ goheader .WithTemplate (`{{ MY COMPANY }}
201
+ SPDX-License-Identifier: Foo` ),
202
+ goheader .WithValues (map [string ]goheader.Value {
203
+ "MY COMPANY" : & goheader.ConstValue {
204
+ RawValue : "mycompany.com" ,
205
+ },
206
+ }))
207
+
208
+ fset := token .NewFileSet ()
209
+ file , err := parser .ParseFile (fset , "foo.go" , src , parser .ParseComments )
210
+ require .NoError (t , err )
211
+
212
+ issue := a .Analyze (& goheader.Target {
213
+ File : file ,
214
+ Path : t .TempDir (),
215
+ })
216
+ require .NotNil (t , issue )
217
+ require .NotNil (t , issue .Fix ())
218
+ require .Equal (t , []string {
219
+ "// mycompany.net" ,
220
+ "// SPDX-License-Identifier: Foo" ,
221
+ }, issue .Fix ().Actual )
222
+ require .Equal (t , []string {
223
+ "// mycompany.com" ,
224
+ "// SPDX-License-Identifier: Foo" ,
225
+ }, issue .Fix ().Expected )
226
+ }
0 commit comments