| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
var gTestfile = 'regress-85721.js'; |
| 18 |
var BUGNUMBER = 85721; |
| 19 |
var summary = 'Performance: execution of regular expression'; |
| 20 |
var FAST = 100; |
| 21 |
var MSG_FAST = 'Execution took less than ' + FAST + ' ms'; |
| 22 |
var MSG_SLOW = 'Execution took '; |
| 23 |
var MSG_MS = ' ms'; |
| 24 |
var str = ''; |
| 25 |
var re = ''; |
| 26 |
var status = ''; |
| 27 |
var actual = ''; |
| 28 |
var expect= ''; |
| 29 |
|
| 30 |
printBugNumber(BUGNUMBER); |
| 31 |
printStatus (summary); |
| 32 |
|
| 33 |
|
| 34 |
function elapsedTime(startTime) |
| 35 |
{ |
| 36 |
return new Date() - startTime; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
function isThisFast(ms) |
| 41 |
{ |
| 42 |
if (ms <= FAST) |
| 43 |
return MSG_FAST; |
| 44 |
return MSG_SLOW + ms + MSG_MS; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
str='<sql:connection id="conn1"> <sql:url>www.m.com</sql:url> <sql:driver>drive.class</sql:driver>\n<sql:userId>foo</sql:userId> <sql:password>goo</sql:password> </sql:connection>'; |
| 53 |
re = /<sql:connection id="([^\r\n]*?)">\s*<sql:url>\s*([^\r\n]*?)\s*<\/sql:url>\s*<sql:driver>\s*([^\r\n]*?)\s*<\/sql:driver>\s*(\s*<sql:userId>\s*([^\r\n]*?)\s*<\/sql:userId>\s*)?\s*(\s*<sql:password>\s*([^\r\n]*?)\s*<\/sql:password>\s*)?\s*<\/sql:connection>/; |
| 54 |
expect = Array("<sql:connection id=\"conn1\"> <sql:url>www.m.com</sql:url> <sql:driver>drive.class</sql:driver>\n<sql:userId>foo</sql:userId> <sql:password>goo</sql:password> </sql:connection>","conn1","www.m.com","drive.class","<sql:userId>foo</sql:userId> ","foo","<sql:password>goo</sql:password> ","goo"); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
status = inSection(1); |
| 60 |
var start = new Date(); |
| 61 |
var result = re.exec(str); |
| 62 |
actual = elapsedTime(start); |
| 63 |
reportCompare(isThisFast(FAST), isThisFast(actual), status); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
status = inSection(2); |
| 69 |
testRegExp([status], [re], [str], [result], [expect]); |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
$esc = '\\\\'; |
| 80 |
$Period = '\.'; |
| 81 |
$space = '\040'; $tab = '\t'; |
| 82 |
$OpenBR = '\\['; $CloseBR = '\\]'; |
| 83 |
$OpenParen = '\\('; $CloseParen = '\\)'; |
| 84 |
$NonASCII = '\x80-\xff'; $ctrl = '\000-\037'; |
| 85 |
$CRlist = '\n\015'; |
| 86 |
|
| 87 |
$qtext = '[^' + $esc + $NonASCII + $CRlist + '\"]'; |
| 88 |
$dtext = '[^' + $esc + $NonASCII + $CRlist + $OpenBR + $CloseBR + ']'; |
| 89 |
$quoted_pair = $esc + '[^' + $NonASCII + ']'; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
$ctext = '[^' + $esc + $NonASCII + $CRlist + '()]'; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
$Cnested = |
| 99 |
$OpenParen + |
| 100 |
$ctext + '*' + |
| 101 |
'(?:' + $quoted_pair + $ctext + '*)*' + |
| 102 |
$CloseParen; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
$comment = |
| 108 |
$OpenParen + |
| 109 |
$ctext + '*' + |
| 110 |
'(?:' + |
| 111 |
'(?:' + $quoted_pair + '|' + $Cnested + ')' + |
| 112 |
$ctext + '*' + |
| 113 |
')*' + |
| 114 |
$CloseParen; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
$X = |
| 120 |
'[' + $space + $tab + ']*' + |
| 121 |
'(?:' + $comment + '[' + $space + $tab + ']*)*'; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
$atom_char = '[^(' + $space + '<>\@,;:\".' + $esc + $OpenBR + $CloseBR + $ctrl + $NonASCII + ']'; |
| 126 |
$atom = |
| 127 |
$atom_char + '+' + |
| 128 |
'(?!' + $atom_char + ')'; |
| 129 |
|
| 130 |
|
| 131 |
$quoted_str = |
| 132 |
'\"' + |
| 133 |
$qtext + '*' + |
| 134 |
'(?:' + $quoted_pair + $qtext + '*)*' + |
| 135 |
'\"'; |
| 136 |
|
| 137 |
|
| 138 |
$word = |
| 139 |
'(?:' + |
| 140 |
$atom + |
| 141 |
'|' + |
| 142 |
$quoted_str + |
| 143 |
')' |
| 144 |
|
| 145 |
|
| 146 |
$domain_ref = $atom; |
| 147 |
|
| 148 |
|
| 149 |
$domain_lit = |
| 150 |
$OpenBR + |
| 151 |
'(?:' + $dtext + '|' + $quoted_pair + ')*' + |
| 152 |
$CloseBR; |
| 153 |
|
| 154 |
|
| 155 |
$sub_domain = |
| 156 |
'(?:' + |
| 157 |
$domain_ref + |
| 158 |
'|' + |
| 159 |
$domain_lit + |
| 160 |
')' + |
| 161 |
$X; |
| 162 |
|
| 163 |
|
| 164 |
$domain = |
| 165 |
$sub_domain + |
| 166 |
'(?:' + |
| 167 |
$Period + $X + $sub_domain + |
| 168 |
')*'; |
| 169 |
|
| 170 |
|
| 171 |
$route = |
| 172 |
'\@' + $X + $domain + |
| 173 |
'(?:,' + $X + '\@' + $X + $domain + ')*' + |
| 174 |
':' + |
| 175 |
$X; |
| 176 |
|
| 177 |
|
| 178 |
$local_part = |
| 179 |
$word + $X |
| 180 |
'(?:' + |
| 181 |
$Period + $X + $word + $X + |
| 182 |
')*'; |
| 183 |
|
| 184 |
|
| 185 |
$addr_spec = |
| 186 |
$local_part + '\@' + $X + $domain; |
| 187 |
|
| 188 |
|
| 189 |
$route_addr = |
| 190 |
'<' + $X + |
| 191 |
'(?:' + $route + ')?' + |
| 192 |
$addr_spec + |
| 193 |
'>'; |
| 194 |
|
| 195 |
|
| 196 |
$phrase_ctrl = '\000-\010\012-\037'; |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
$phrase_char = |
| 201 |
'[^()<>\@,;:\".' + $esc + $OpenBR + $CloseBR + $NonASCII + $phrase_ctrl + ']'; |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
$phrase = |
| 206 |
$word + |
| 207 |
$phrase_char + '*' + |
| 208 |
'(?:' + |
| 209 |
'(?:' + $comment + '|' + $quoted_str + ')' + |
| 210 |
$phrase_char + '*' + |
| 211 |
')*'; |
| 212 |
|
| 213 |
|
| 214 |
$mailbox = |
| 215 |
$X + |
| 216 |
'(?:' + |
| 217 |
$phrase + $route_addr + |
| 218 |
'|' + |
| 219 |
$addr_spec + |
| 220 |
')'; |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
re = new RegExp($mailbox, "g"); |
| 227 |
str = 'Jeffy<"That Tall Guy"@ora.com (this address is no longer active)>'; |
| 228 |
expect = Array('Jeffy<"That Tall Guy"@ora.com (this address is no longer active)>'); |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
status = inSection(3); |
| 234 |
var start = new Date(); |
| 235 |
var result = re.exec(str); |
| 236 |
actual = elapsedTime(start); |
| 237 |
reportCompare(isThisFast(FAST), isThisFast(actual), status); |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
status = inSection(4); |
| 243 |
testRegExp([status], [re], [str], [result], [expect]); |