| 1 |
# This is a basic test that checks ^ and $ treat \r\n as a single line |
| 2 |
# terminator. If ^ and $ only treated \n as a line terminator, then this would |
| 3 |
# only match 'xyz' at the end of the haystack. |
| 4 |
[[test]] |
| 5 |
name = "basic" |
| 6 |
regex = '(?mR)^[a-z]+$' |
| 7 |
haystack = "abc\r\ndef\r\nxyz" |
| 8 |
matches = [[0, 3], [5, 8], [10, 13]] |
| 9 |
|
| 10 |
# Tests that a CRLF-aware '^$' assertion does not match between CR and LF. |
| 11 |
[[test]] |
| 12 |
name = "start-end-non-empty" |
| 13 |
regex = '(?mR)^$' |
| 14 |
haystack = "abc\r\ndef\r\nxyz" |
| 15 |
matches = [] |
| 16 |
|
| 17 |
# Tests that a CRLF-aware '^$' assertion matches the empty string, just like |
| 18 |
# a non-CRLF-aware '^$' assertion. |
| 19 |
[[test]] |
| 20 |
name = "start-end-empty" |
| 21 |
regex = '(?mR)^$' |
| 22 |
haystack = "" |
| 23 |
matches = [[0, 0]] |
| 24 |
|
| 25 |
# Tests that a CRLF-aware '^$' assertion matches the empty string preceding |
| 26 |
# and following a line terminator. |
| 27 |
[[test]] |
| 28 |
name = "start-end-before-after" |
| 29 |
regex = '(?mR)^$' |
| 30 |
haystack = "\r\n" |
| 31 |
matches = [[0, 0], [2, 2]] |
| 32 |
|
| 33 |
# Tests that a CRLF-aware '^' assertion does not split a line terminator. |
| 34 |
[[test]] |
| 35 |
name = "start-no-split" |
| 36 |
regex = '(?mR)^' |
| 37 |
haystack = "abc\r\ndef\r\nxyz" |
| 38 |
matches = [[0, 0], [5, 5], [10, 10]] |
| 39 |
|
| 40 |
# Same as above, but with adjacent runs of line terminators. |
| 41 |
[[test]] |
| 42 |
name = "start-no-split-adjacent" |
| 43 |
regex = '(?mR)^' |
| 44 |
haystack = "\r\n\r\n\r\n" |
| 45 |
matches = [[0, 0], [2, 2], [4, 4], [6, 6]] |
| 46 |
|
| 47 |
# Same as above, but with adjacent runs of just carriage returns. |
| 48 |
[[test]] |
| 49 |
name = "start-no-split-adjacent-cr" |
| 50 |
regex = '(?mR)^' |
| 51 |
haystack = "\r\r\r" |
| 52 |
matches = [[0, 0], [1, 1], [2, 2], [3, 3]] |
| 53 |
|
| 54 |
# Same as above, but with adjacent runs of just line feeds. |
| 55 |
[[test]] |
| 56 |
name = "start-no-split-adjacent-lf" |
| 57 |
regex = '(?mR)^' |
| 58 |
haystack = "\n\n\n" |
| 59 |
matches = [[0, 0], [1, 1], [2, 2], [3, 3]] |
| 60 |
|
| 61 |
# Tests that a CRLF-aware '$' assertion does not split a line terminator. |
| 62 |
[[test]] |
| 63 |
name = "end-no-split" |
| 64 |
regex = '(?mR)$' |
| 65 |
haystack = "abc\r\ndef\r\nxyz" |
| 66 |
matches = [[3, 3], [8, 8], [13, 13]] |
| 67 |
|
| 68 |
# Same as above, but with adjacent runs of line terminators. |
| 69 |
[[test]] |
| 70 |
name = "end-no-split-adjacent" |
| 71 |
regex = '(?mR)$' |
| 72 |
haystack = "\r\n\r\n\r\n" |
| 73 |
matches = [[0, 0], [2, 2], [4, 4], [6, 6]] |
| 74 |
|
| 75 |
# Same as above, but with adjacent runs of just carriage returns. |
| 76 |
[[test]] |
| 77 |
name = "end-no-split-adjacent-cr" |
| 78 |
regex = '(?mR)$' |
| 79 |
haystack = "\r\r\r" |
| 80 |
matches = [[0, 0], [1, 1], [2, 2], [3, 3]] |
| 81 |
|
| 82 |
# Same as above, but with adjacent runs of just line feeds. |
| 83 |
[[test]] |
| 84 |
name = "end-no-split-adjacent-lf" |
| 85 |
regex = '(?mR)$' |
| 86 |
haystack = "\n\n\n" |
| 87 |
matches = [[0, 0], [1, 1], [2, 2], [3, 3]] |
| 88 |
|
| 89 |
# Tests that '.' does not match either \r or \n when CRLF mode is enabled. Note |
| 90 |
# that this doesn't require multi-line mode to be enabled. |
| 91 |
[[test]] |
| 92 |
name = "dot-no-crlf" |
| 93 |
regex = '(?R).' |
| 94 |
haystack = "\r\n\r\n\r\n" |
| 95 |
matches = [] |
| 96 |
|
| 97 |
# This is a test that caught a bug in the one-pass DFA where it (amazingly) was |
| 98 |
# using 'is_end_lf' instead of 'is_end_crlf' here. It was probably a copy & |
| 99 |
# paste bug. We insert an empty capture group here because it provokes the meta |
| 100 |
# regex engine to first find a match and then trip over a panic because the |
| 101 |
# one-pass DFA erroneously says there is no match. |
| 102 |
[[test]] |
| 103 |
name = "onepass-wrong-crlf-with-capture" |
| 104 |
regex = '(?Rm:().$)' |
| 105 |
haystack = "ZZ\r" |
| 106 |
matches = [[[1, 2], [1, 1]]] |
| 107 |
|
| 108 |
# This is like onepass-wrong-crlf-with-capture above, except it sets up the |
| 109 |
# test so that it can be run by the one-pass DFA directly. (i.e., Make it |
| 110 |
# anchored and start the search at the right place.) |
| 111 |
[[test]] |
| 112 |
name = "onepass-wrong-crlf-anchored" |
| 113 |
regex = '(?Rm:.$)' |
| 114 |
haystack = "ZZ\r" |
| 115 |
matches = [[1, 2]] |
| 116 |
anchored = true |
| 117 |
bounds = [1, 3] |