(t *testing.T)
| 27 | ) |
| 28 | |
| 29 | func TestGetQuestionLink(t *testing.T) { |
| 30 | // Step 1: Test empty content |
| 31 | t.Run("Empty content", func(t *testing.T) { |
| 32 | links := checker.GetQuestionLink("") |
| 33 | assert.Empty(t, links) |
| 34 | }) |
| 35 | |
| 36 | // Step 2: Test content without link or ID |
| 37 | t.Run("Content without link or ID", func(t *testing.T) { |
| 38 | links := checker.GetQuestionLink("This is a random text") |
| 39 | assert.Empty(t, links) |
| 40 | }) |
| 41 | |
| 42 | // Step 3: Test content with valid question link |
| 43 | t.Run("Valid question link", func(t *testing.T) { |
| 44 | links := checker.GetQuestionLink("Check this question: https://example.com/questions/10010000000000060") |
| 45 | assert.Equal(t, []checker.QuestionLink{ |
| 46 | { |
| 47 | LinkType: checker.QuestionLinkTypeURL, |
| 48 | QuestionID: "10010000000000060", |
| 49 | AnswerID: "", |
| 50 | }, |
| 51 | }, links) |
| 52 | }) |
| 53 | |
| 54 | // Step 4: Test content with valid question and answer link |
| 55 | t.Run("Valid question and answer link", func(t *testing.T) { |
| 56 | links := checker.GetQuestionLink("Check this answer: https://example.com/questions/10010000000000060/10020000000000060?from=copy") |
| 57 | assert.Equal(t, []checker.QuestionLink{ |
| 58 | { |
| 59 | LinkType: checker.QuestionLinkTypeURL, |
| 60 | QuestionID: "10010000000000060", |
| 61 | AnswerID: "10020000000000060", |
| 62 | }, |
| 63 | }, links) |
| 64 | }) |
| 65 | |
| 66 | // Step 5: Test content with #questionID |
| 67 | t.Run("Content with #questionID", func(t *testing.T) { |
| 68 | links := checker.GetQuestionLink("This is question #10010000000000060") |
| 69 | assert.Equal(t, []checker.QuestionLink{ |
| 70 | { |
| 71 | LinkType: checker.QuestionLinkTypeID, |
| 72 | QuestionID: "10010000000000060", |
| 73 | AnswerID: "", |
| 74 | }, |
| 75 | }, links) |
| 76 | }) |
| 77 | |
| 78 | // Step 6: Test content with #answerID |
| 79 | t.Run("Content with #answerID", func(t *testing.T) { |
| 80 | links := checker.GetQuestionLink("This is answer #10020000000000060") |
| 81 | assert.Equal(t, []checker.QuestionLink{ |
| 82 | { |
| 83 | LinkType: checker.QuestionLinkTypeID, |
| 84 | QuestionID: "", |
| 85 | AnswerID: "10020000000000060", |
| 86 | }, |
nothing calls this directly
no test coverage detected