@@ -36,6 +36,57 @@ func Test_checkWithAspell(t *testing.T) {
3636 }
3737}
3838
39+ func Test_removeKnownHashesFromBody (t * testing.T ) {
40+ hashes := map [string ]struct {}{
41+ "abc1234567890abcdef1234567890abcdef12340" : {},
42+ "def9876543210fedcba9876543210fedcba98760" : {},
43+ }
44+ tests := []struct {
45+ name string
46+ input string
47+ expect string
48+ }{
49+ {
50+ "no body" ,
51+ "subject line only" ,
52+ "subject line only" ,
53+ },
54+ {
55+ "hash in body is removed" ,
56+ "subject line\n \n This reverts abc1234567890abcdef1234567890abcdef12340." ,
57+ "subject line\n \n This reverts ." ,
58+ },
59+ {
60+ "short hash in body is removed" ,
61+ "subject line\n \n This reverts abc1234." ,
62+ "subject line\n \n This reverts ." ,
63+ },
64+ {
65+ "hash in subject is preserved" ,
66+ "revert abc1234\n \n body text here" ,
67+ "revert abc1234\n \n body text here" ,
68+ },
69+ {
70+ "unknown hex string preserved" ,
71+ "subject\n \n See fffffff for details" ,
72+ "subject\n \n See fffffff for details" ,
73+ },
74+ {
75+ "multiple hashes in body" ,
76+ "subject\n \n Reverts abc1234 and def9876." ,
77+ "subject\n \n Reverts and ." ,
78+ },
79+ }
80+ for _ , tt := range tests {
81+ t .Run (tt .name , func (t * testing.T ) {
82+ got := removeKnownHashesFromBody (tt .input , hashes )
83+ if got != tt .expect {
84+ t .Errorf ("removeKnownHashesFromBody() = %q, want %q" , got , tt .expect )
85+ }
86+ })
87+ }
88+ }
89+
3990func TestAspell_Check (t * testing.T ) {
4091 type fields struct {
4192 Mode mode
@@ -109,7 +160,7 @@ func TestAspell_Check(t *testing.T) {
109160 AllowedWords : tt .fields .AllowedWords ,
110161 HelpText : tt .fields .HelpText ,
111162 }
112- if err := a .Check (tt .args .subjects , tt .args .commitsFull , tt .args .content , & junit.JunitSuiteDummy {}); (err != nil ) != tt .wantErr {
163+ if err := a .Check (tt .args .subjects , tt .args .commitsFull , tt .args .content , & junit.JunitSuiteDummy {}, nil ); (err != nil ) != tt .wantErr {
113164 t .Errorf ("Aspell.Check() error = %v, wantErr %v" , err , tt .wantErr )
114165 }
115166 })
0 commit comments