gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/tools/github/reviver/reviver_test.go (about) 1 // Copyright 2019 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package reviver 16 17 import ( 18 "testing" 19 ) 20 21 func TestProcessLine(t *testing.T) { 22 for _, tc := range []struct { 23 line string 24 want *Todo 25 }{ 26 { 27 line: "// TODO(foobar.com/issue/123): comment, bla. blabla.", 28 want: &Todo{ 29 Issue: "foobar.com/issue/123", 30 Locations: []Location{ 31 {Comment: "comment, bla. blabla."}, 32 }, 33 }, 34 }, 35 { 36 line: "// TODO(foobar.com/issues/123): comment, bla. blabla.", 37 want: &Todo{ 38 Issue: "foobar.com/issues/123", 39 Locations: []Location{ 40 {Comment: "comment, bla. blabla."}, 41 }, 42 }, 43 }, 44 { 45 line: "// FIXME(b/123): internal bug", 46 want: &Todo{ 47 Issue: "b/123", 48 Locations: []Location{ 49 {Comment: "internal bug"}, 50 }, 51 }, 52 }, 53 { 54 line: "TODO(issue): not todo", 55 }, 56 { 57 line: "FIXME(issue): not todo", 58 }, 59 { 60 line: "// TODO (issue): not todo", 61 }, 62 { 63 line: "// TODO(issue) not todo", 64 }, 65 { 66 line: "// todo(issue): not todo", 67 }, 68 { 69 line: "// TODO(issue):", 70 }, 71 } { 72 t.Logf("Testing: %s", tc.line) 73 r := Reviver{} 74 got := r.processLine(tc.line, "test", 0) 75 if got == nil { 76 if tc.want != nil { 77 t.Errorf("failed to process line, want: %+v", tc.want) 78 } 79 } else { 80 if tc.want == nil { 81 t.Errorf("expected error, got: %+v", got) 82 continue 83 } 84 if got.Issue != tc.want.Issue { 85 t.Errorf("wrong issue, got: %v, want: %v", got.Issue, tc.want.Issue) 86 } 87 if len(got.Locations) != len(tc.want.Locations) { 88 t.Errorf("wrong number of locations, got: %v, want: %v, locations: %+v", len(got.Locations), len(tc.want.Locations), got.Locations) 89 } 90 for i, wantLoc := range tc.want.Locations { 91 if got.Locations[i].Comment != wantLoc.Comment { 92 t.Errorf("wrong comment, got: %v, want: %v", got.Locations[i].Comment, wantLoc.Comment) 93 } 94 } 95 } 96 } 97 }