TestSearchSingleMatch asserts that the expected output is returned when a single match is returned
(t *testing.T)
| 33 | // TestSearchSingleMatch asserts that the expected output is returned |
| 34 | // when a single match is returned |
| 35 | func TestSearchSingleMatch(t *testing.T) { |
| 36 | |
| 37 | // mock a cheatsheet |
| 38 | sheet := Sheet{ |
| 39 | Text: "The quick brown fox\njumped over\n\nthe lazy dog.", |
| 40 | } |
| 41 | |
| 42 | // compile the search regex |
| 43 | reg, err := regexp.Compile("(?i)fox") |
| 44 | if err != nil { |
| 45 | t.Errorf("failed to compile regex: %v", err) |
| 46 | } |
| 47 | |
| 48 | // search the sheet |
| 49 | matches := sheet.Search(reg) |
| 50 | |
| 51 | // specify the expected results |
| 52 | want := "The quick brown fox\njumped over" |
| 53 | |
| 54 | // assert that the correct matches were returned |
| 55 | if matches != want { |
| 56 | t.Errorf( |
| 57 | "failed to return expected matches: want:\n%s, got:\n%s", |
| 58 | want, |
| 59 | matches, |
| 60 | ) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // TestSearchMultiMatch asserts that the expected output is returned |
| 65 | // when a multiple matches are returned |