| 1 | import regex |
| 2 | |
| 3 | fn test_anchor_start() { |
| 4 | mut re := regex.regex_opt(r'^\w+') or { panic(err) } |
| 5 | start, end := re.find('id.') |
| 6 | assert start == 0 |
| 7 | assert end == 2 |
| 8 | } |
| 9 | |
| 10 | fn test_anchor_end() { |
| 11 | mut re := regex.regex_opt(r'\w+$') or { panic(err) } |
| 12 | start, end := re.find('(id') |
| 13 | assert start == 1 |
| 14 | assert end == 3 |
| 15 | } |
| 16 | |
| 17 | fn test_anchor_both() { |
| 18 | mut re := regex.regex_opt(r'^\w+$') or { panic(err) } |
| 19 | start, end := re.find('(id)') |
| 20 | assert start == -1 |
| 21 | assert end == -1 |
| 22 | } |
| 23 | |
| 24 | fn test_anchor_both_find_multiline() { |
| 25 | text := 'TITLE\n\nThis is a test.' |
| 26 | mut re := regex.regex_opt(r'^\w+$') or { panic(err) } |
| 27 | start, end := re.find(text) |
| 28 | assert start == 0 |
| 29 | assert end == 5 |
| 30 | } |
| 31 | |
| 32 | fn test_anchor_both_find_all_multiline() { |
| 33 | text := 'TITLE\n\nThis is a test.' |
| 34 | mut re := regex.regex_opt(r'^\w+$') or { panic(err) } |
| 35 | res := re.find_all(text) |
| 36 | assert res == [0, 5] |
| 37 | } |
| 38 | |
| 39 | fn test_anchor_both_find_all_str_multiline() { |
| 40 | text := 'TITLE\n\nThis is a test.' |
| 41 | mut re := regex.regex_opt(r'^\w+$') or { panic(err) } |
| 42 | res := re.find_all_str(text) |
| 43 | assert res == ['TITLE'] |
| 44 | } |
| 45 | |