|
| 1 | +package matchers |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/preslavmihaylov/todocheck/matchers/state" |
| 8 | +) |
| 9 | + |
| 10 | +func TestTodoMatcherForFile(t *testing.T) { |
| 11 | + testTodo := []string{"// TODO"} |
| 12 | + |
| 13 | + for extension, factory := range supportedMatchers { |
| 14 | + t.Run(extension, func(t *testing.T) { |
| 15 | + matcher := TodoMatcherForFile("test"+extension, testTodo) |
| 16 | + want := factory.newTodoMatcher(testTodo) |
| 17 | + if matcher != want { |
| 18 | + t.Errorf("got %v want %v", matcher, want) |
| 19 | + } |
| 20 | + }) |
| 21 | + } |
| 22 | + |
| 23 | + t.Run("Unsupported extension", func(t *testing.T) { |
| 24 | + matcher := TodoMatcherForFile("test.md", testTodo) |
| 25 | + if matcher != nil { |
| 26 | + t.Errorf("Expected nil matcher") |
| 27 | + } |
| 28 | + }) |
| 29 | +} |
| 30 | + |
| 31 | +func TestCommentMatcherForFile(t *testing.T) { |
| 32 | + var testCommentCallback state.CommentCallback |
| 33 | + |
| 34 | + for extension, factory := range supportedMatchers { |
| 35 | + t.Run(extension, func(t *testing.T) { |
| 36 | + matcher := CommentMatcherForFile("test"+extension, testCommentCallback) |
| 37 | + want := factory.newCommentsMatcher(testCommentCallback) |
| 38 | + if !reflect.DeepEqual(matcher, want) { |
| 39 | + t.Errorf("got %v want %v", matcher, want) |
| 40 | + } |
| 41 | + }) |
| 42 | + } |
| 43 | + |
| 44 | + t.Run("Unsupported extension", func(t *testing.T) { |
| 45 | + matcher := CommentMatcherForFile("test.md", testCommentCallback) |
| 46 | + if matcher != nil { |
| 47 | + t.Errorf("Expected nil matcher") |
| 48 | + } |
| 49 | + }) |
| 50 | +} |
| 51 | + |
| 52 | +func TestSupportedFileExtensions(t *testing.T) { |
| 53 | + extensions := SupportedFileExtensions() |
| 54 | + |
| 55 | + for _, ext := range extensions { |
| 56 | + if _, ok := supportedMatchers[ext]; !ok { |
| 57 | + t.Errorf("Extension %v is not in supported extensions", ext) |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + if len(extensions) != len(supportedMatchers) { |
| 62 | + t.Errorf("Some extensions from supported extensions are missing") |
| 63 | + } |
| 64 | +} |
0 commit comments