1 Regex literals are enclosed in forward slashes and may contain zero 2 or more trailing flag characters. Interpretation of escape sequences 3 within regular expression literals is subject of the underlying 4 regular expression engine. 5 6 -- Expect stdout -- 7 [ "/Hello world/", "/test/gis", "/test/g", "/test1 / test2/", "/1\n\\.\u0007\\bc☀\\\\/" ] 8 -- End -- 9 10 -- Testcase -- 11 {% 12 print([ 13 /Hello world/, // A very simple expression 14 /test/gsi, // Regular expression flags 15 /test/gg, // Repeated flags 16 /test1 \/ test2/, // Escaped forward slash 17 /\x31\n\.\a\b\c\u2600\\/ // Ensure that escape sequences are passed as-is 18 ], "\n"); 19 %} 20 -- End -- 21 22 23 Testing regular expression type. 24 25 -- Expect stdout -- 26 regexp 27 -- End -- 28 29 -- Testcase -- 30 {{ type(/foo/) }} 31 -- End -- 32 33 34 Testing invalid flag characters. 35 36 -- Expect stderr -- 37 Syntax error: Unexpected token 38 Expecting ';' 39 In line 2, byte 8: 40 41 ` /test/x` 42 ^-- Near here 43 44 45 -- End -- 46 47 -- Testcase -- 48 {% 49 /test/x 50 %} 51 -- End -- 52 53 54 Testing unclosed regular expression. 55 56 -- Expect stderr -- 57 Syntax error: Unterminated string 58 In line 2, byte 2: 59 60 ` /foo \/` 61 ^-- Near here 62 63 64 -- End -- 65 66 -- Testcase -- 67 {% 68 /foo \/ 69 %} 70 -- End -- 71 72 73 Testing regex compilation errors. 74 75 -- Expect stderr -- 76 Catched syntax error 77 In line 7, byte 30: 78 79 ` die("Catched syntax error");` 80 Near here ----------------------------^ 81 82 83 -- End -- 84 85 -- Testcase -- 86 {% 87 try { 88 /foo (/ 89 } 90 catch (e) { 91 if (e.type == "Syntax error") 92 die("Catched syntax error"); 93 } 94 %} 95 -- End -- 96 97 98 Testing that slashes within character classes are not treated as regex 99 literal delimitters. 100 101 -- Expect stdout -- 102 [ 103 "/[/]/", 104 "/[[./.]/]/", 105 "/[[:alpha:]/]/", 106 "/[[=/=]/]/" 107 ] 108 -- End -- 109 110 -- Testcase -- 111 {% 112 printf("%.J\n", [ 113 /[/]/, 114 /[[./.]/]/, 115 /[[:alpha:]/]/, 116 /[[=/=]/]/ 117 ]); 118 %} 119 -- End -- 120 121 122 Testing that regex extension macros are substituted only outside of 123 bracket set expressions. 124 125 -- Expect stdout -- 126 [ 127 "/ \\b \\B [\b B] /", 128 "/ \\< \\> [< >] /", 129 "/ [[:digit:]] [^[:digit:]] [d D] /", 130 "/ [[:space:]] [^[:space:]] [s S] /", 131 "/ [[:alnum:]_] [^[:alnum:]_] [w W] /" 132 ] 133 -- End -- 134 135 -- Testcase -- 136 {% 137 printf("%.J\n", [ 138 / \b \B [\b \B] /, // \b outside brackets is a word boundary, 139 // \b within brackets is backspace 140 / \< \> [\< \>] /, 141 / \d \D [\d \D] /, 142 / \s \S [\s \S] /, 143 / \w \W [\w \W] / 144 ]); 145 %} 146 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt