jush.create_links = 'target="_blank"';
jush.custom_links = {sql: {'?table=$&': /\b(tab2?)\b/g}};
jush.custom_links.bac = jush.custom_links.sql;

const tests = {};
tests.highlight = [
	['htm', '<a href="">HTML</a> <!-- comment --> &amp;', '<span class="jush"><span class="jush-tag"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a" class="jush-help" target="_blank">a</a><span class="jush-att"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a#href" class="jush-help" target="_blank">href</a><span class="jush-att_quo"><span class="jush-op">="</span><span class="jush-op">"</span></span></span><span class="jush-op">&gt;</span></span>HTML<span class="jush-tag"><span class="jush-op">&lt;</span>/a<span class="jush-op">&gt;</span></span> <span class="jush-htm_com"><span class="jush-op">&lt;!--</span> comment <span class="jush-op">--&gt;</span></span> <span class="jush-ent"><span class="jush-op">&amp;</span>amp<span class="jush-op">;</span></span></span>'],
	['htm', '<a href="" onclick="alert(\'\');">', '<span class="jush"><span class="jush-tag"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a" class="jush-help" target="_blank">a</a><span class="jush-att"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a#href" class="jush-help" target="_blank">href</a><span class="jush-att_quo"><span class="jush-op">="</span><span class="jush-op">"</span></span></span><span class="jush-att_js"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event" class="jush-help" target="_blank">onclick</a><span class="jush-op">=</span><span class="jush-att_quo"><span class="jush-op">"</span><span class="jush-js_code"><a href="https://developer.mozilla.org/en/DOM/window.alert" class="jush-help" target="_blank">alert</a><span class="jush-op">(</span></span><span class="jush-js_code"><span class="jush-apo"><span class="jush-op">\'</span><span class="jush-op">\'</span></span>)<span class="jush-op">;</span></span><span class="jush-op">"</span></span></span><span class="jush-op">&gt;</span></span></span>'],
	['htm', '<a href="" style="color: red;">', '<span class="jush"><span class="jush-tag"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a" class="jush-help" target="_blank">a</a><span class="jush-att"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a#href" class="jush-help" target="_blank">href</a><span class="jush-att_quo"><span class="jush-op">="</span><span class="jush-op">"</span></span></span><span class="jush-att_css"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/style" class="jush-help" target="_blank">style</a><span class="jush-op">=</span><span class="jush-att_quo"><span class="jush-op">"</span><span class="jush-css_val"><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/color" class="jush-help" target="_blank">color</a><span class="jush-op">:</span> red<span class="jush-op">;</span></span><span class="jush-op">"</span></span></span><span class="jush-op">&gt;</span></span></span>'],
	['htm', '<script type="text/javascript">alert("");</script> SCRIPT', '<span class="jush"><span class="jush-tag_js"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script" class="jush-help" target="_blank">script</a><span class="jush-att"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script#type" class="jush-help" target="_blank">type</a><span class="jush-att_quo"><span class="jush-op">="</span>text/javascript<span class="jush-op">"</span></span></span><span class="jush-js"><span class="jush-op">&gt;</span><span class="jush-js_code"><a href="https://developer.mozilla.org/en/DOM/window.alert" class="jush-help" target="_blank">alert</a><span class="jush-op">(</span></span><span class="jush-js_code"><span class="jush-quo"><span class="jush-op">"</span><span class="jush-op">"</span></span>)<span class="jush-op">;</span></span><span class="jush-js_code"><span class="jush-op">&lt;</span>/script<span class="jush-op">&gt;</span></span></span></span> SCRIPT</span>'],
	['htm', '<style type="text/css">a { color: red; }</style> STYLE', '<span class="jush"><span class="jush-tag_css"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/style" class="jush-help" target="_blank">style</a><span class="jush-att"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/style#type" class="jush-help" target="_blank">type</a><span class="jush-att_quo"><span class="jush-op">="</span>text/css<span class="jush-op">"</span></span></span><span class="jush-css"><span class="jush-op">&gt;</span>a <span class="jush-css_pro"><span class="jush-op">{</span><span class="jush-css_val"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/color" class="jush-help" target="_blank">color</a><span class="jush-op">:</span> red<span class="jush-op">;</span></span> <span class="jush-op">}</span></span><span class="jush-op">&lt;</span>/style<span class="jush-op">&gt;</span></span></span> STYLE</span>'],
	['htm', '<a href=index.php title=\'Quoting\'>', '<span class="jush"><span class="jush-tag"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a" class="jush-help" target="_blank">a</a><span class="jush-att"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a#href" class="jush-help" target="_blank">href</a><span class="jush-att_val"><span class="jush-op">=</span>index.php</span></span><span class="jush-att"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/title" class="jush-help" target="_blank">title</a><span class="jush-att_apo"><span class="jush-op">=\'</span>Quoting<span class="jush-op">\'</span></span></span><span class="jush-op">&gt;</span></span></span>'],
	['htm', '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">', '<span class="jush"><span class="jush-tag"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta" class="jush-help" target="_blank">meta</a><span class="jush-att_http"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta#http-equiv" class="jush-help" target="_blank">http-equiv</a><span class="jush-op">=</span><span class="jush-att_quo"><span class="jush-op">"</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Type" class="jush-help" target="_blank">Content-Type</a><span class="jush-op">"</span></span></span><span class="jush-att"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta#content" class="jush-help" target="_blank">content</a><span class="jush-att_quo"><span class="jush-op">="</span>text/html; charset=utf-8<span class="jush-op">"</span></span></span><span class="jush-op">&gt;</span></span></span>'],

	['tag', 'title=""', '<span class="jush"><span class="jush-att"><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/title" class="jush-help" target="_blank">title</a><span class="jush-att_quo"><span class="jush-op">="</span><span class="jush-op">"</span></span></span></span>'],

	['xml', '<rss version="0.91">', '<span class="jush"><span class="jush-xml_tag"><span class="jush-op">&lt;</span>rss<span class="jush-xml_att"><span class="jush-op"> </span>version<span class="jush-att_quo"><span class="jush-op">="</span>0.91<span class="jush-op">"</span></span></span><span class="jush-op">&gt;</span></span></span>'],

	['css', 'a { color: red } /* </style> comment */ b { font-weight: bold; color: black; }', '<span class="jush">a <span class="jush-css_pro"><span class="jush-op">{</span><span class="jush-css_val"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/color" class="jush-help" target="_blank">color</a><span class="jush-op">:</span> red <span class="jush-op">}</span></span></span> <span class="jush-com"><span class="jush-op">/*</span> &lt;/style&gt; comment <span class="jush-op">*/</span></span> b <span class="jush-css_pro"><span class="jush-op">{</span><span class="jush-css_val"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-weight" class="jush-help" target="_blank">font-weight</a><span class="jush-op">:</span> bold<span class="jush-op">;</span></span><span class="jush-css_val"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/color" class="jush-help" target="_blank">color</a><span class="jush-op">:</span> black<span class="jush-op">;</span></span> <span class="jush-op">}</span></span></span>'],

	['css', 'a:hover::after, p:first-child::first-line { color: red }', '<span class="jush">a:<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:hover" class="jush-help" target="_blank">hover</a>::<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/::after" class="jush-help" target="_blank">after</a>, p:<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:first-child" class="jush-help" target="_blank">first-child</a>::<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/::first-line" class="jush-help" target="_blank">first-line</a> <span class="jush-css_pro"><span class="jush-op">{</span><span class="jush-css_val"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/color" class="jush-help" target="_blank">color</a><span class="jush-op">:</span> red <span class="jush-op">}</span></span></span></span>'], // pseudo-classes and pseudo-elements are distinguished by the number of colons

	['css', '@media print { a { color: red } }', '<span class="jush"><span class="jush-css_at"><span class="jush-op">@</span><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media" class="jush-help" target="_blank">media</a> print <span class="jush-css_at2"><span class="jush-op">{</span> a <span class="jush-css_pro"><span class="jush-op">{</span><span class="jush-css_val"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/color" class="jush-help" target="_blank">color</a><span class="jush-op">:</span> red <span class="jush-op">}</span></span></span> <span class="jush-op">}</span></span></span></span>'],

	['js', 'if (/.+@.+/.test(email)) { /* </script> */ alert(email); }', '<span class="jush"><span class="jush-js_code"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Statements/if...else" class="jush-help" target="_blank">if</a> <span class="jush-op">(</span></span><span class="jush-js_reg"><span class="jush-op">/</span>.+@.+<span class="jush-op">/</span></span><span class="jush-js_code">.<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp/test" class="jush-help" target="_blank">test</a><span class="jush-op">(</span></span><span class="jush-js_code">email)) <span class="jush-js"><span class="jush-op">{</span><span class="jush-js_code"> <span class="jush-com"><span class="jush-op">/*</span> &lt;/script&gt; <span class="jush-op">*/</span></span> <a href="https://developer.mozilla.org/en/DOM/window.alert" class="jush-help" target="_blank">alert</a><span class="jush-op">(</span></span><span class="jush-js_code">email)<span class="jush-op">;</span></span><span class="jush-js_code"> <span class="jush-op">}</span></span></span></span></span>'],
	['js', '/[/\\]]/.test("/");', '<span class="jush"><span class="jush-js_reg"><span class="jush-op">/</span><span class="jush-js_reg_bra"><span class="jush-op">[</span>/<span class="jush-esc"><span class="jush-op">\\</span><span class="jush-op">]</span></span><span class="jush-op">]</span></span><span class="jush-op">/</span></span><span class="jush-js_code">.<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp/test" class="jush-help" target="_blank">test</a><span class="jush-op">(</span></span><span class="jush-js_code"><span class="jush-quo"><span class="jush-op">"</span>/<span class="jush-op">"</span></span>)<span class="jush-op">;</span></span></span>'],
	['js', 'var s = `a ${x} b`; // comment', '<span class="jush"><span class="jush-js_code"><a href="https://developer.mozilla.org/en/JavaScript/Reference/Statements/var" class="jush-help" target="_blank">var</a> s <span class="jush-op">=</span></span><span class="jush-js_code"> <span class="jush-js_bac"><span class="jush-op">`</span>a <span class="jush-js"><span class="jush-op">${</span><span class="jush-js_code">x<span class="jush-op">}</span></span></span> b<span class="jush-op">`</span></span><span class="jush-op">;</span></span><span class="jush-js_code"> <span class="jush-js_one"><span class="jush-op">//</span> comment</span></span></span>'],
	['js', 'x.name = a.at(1);', '<span class="jush"><span class="jush-js_code">x.<a href="https://developer.mozilla.org/en/DOM/element.name" class="jush-help" target="_blank">name</a> <span class="jush-op">=</span></span><span class="jush-js_code"> a.<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/at" class="jush-help" target="_blank">at</a><span class="jush-op">(</span></span><span class="jush-js_code"><span class="jush-num"><span class="jush-op">1</span></span>)<span class="jush-op">;</span></span></span>'], // a member is linked only after a dot, .name prefers the DOM property
	['js', 'xhr.getResponseHeader("Content-Type");', '<span class="jush"><span class="jush-js_code">xhr<span class="jush-js_http"><span class="jush-op">.</span><a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getResponseHeader" class="jush-help" target="_blank">getResponseHeader</a><span class="jush-op">(</span><span class="jush-js_http_code"><span class="jush-quo"><span class="jush-op">"</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Type" class="jush-help" target="_blank">Content-Type</a><span class="jush-op">"</span></span><span class="jush-op">)</span></span></span><span class="jush-op">;</span></span></span>'],
	['js', '{ a: [ 1, { "b": "c" }, 3 ], \'d\': 4 }', '<span class="jush"><span class="jush-js_obj"><span class="jush-op">{</span><span class="jush-js_key"> a</span><span class="jush-js_val"><span class="jush-op">:</span> <span class="jush-js_arr"><span class="jush-op">[</span> <span class="jush-num"><span class="jush-op">1</span></span>, <span class="jush-js_obj"><span class="jush-op">{</span><span class="jush-js_key"> <span class="jush-quo"><span class="jush-op">"</span>b<span class="jush-op">"</span></span></span><span class="jush-js_val"><span class="jush-op">:</span> <span class="jush-quo"><span class="jush-op">"</span>c<span class="jush-op">"</span></span> </span><span class="jush-op">}</span></span>, <span class="jush-num"><span class="jush-op">3</span></span> <span class="jush-op">]</span></span><span class="jush-op">,</span></span><span class="jush-js_key"> <span class="jush-apo"><span class="jush-op">\'</span>d<span class="jush-op">\'</span></span></span><span class="jush-js_val"><span class="jush-op">:</span> <span class="jush-num"><span class="jush-op">4</span></span> </span><span class="jush-op">}</span></span></span>'],
	['js', '/** @param {string} s */', '<span class="jush"><span class="jush-js_code"><span class="jush-js_doc"><span class="jush-op">/**</span> <a href="https://jsdoc.app/tags-param" class="jush-help" target="_blank">@param</a> {string} s <span class="jush-op">*/</span></span></span></span>'],

	['js_doc', '@return {@link Foo}', '<span class="jush"><a href="https://jsdoc.app/tags-returns" class="jush-help" target="_blank">@return</a> <a href="https://jsdoc.app/tags-inline-link" class="jush-help" target="_blank">{@link</a> Foo}</span>'],

	['json', '{"a": [1, {"b": "c"}, -2.5e3], "d": true, "e": null}', '<span class="jush"><span class="jush-json_obj"><span class="jush-op">{</span><span class="jush-json_key"><span class="jush-quo"><span class="jush-op">"</span>a<span class="jush-op">"</span></span></span><span class="jush-json_val"><span class="jush-op">:</span> <span class="jush-json_arr"><span class="jush-op">[</span><span class="jush-num"><span class="jush-op">1</span></span>, <span class="jush-json_obj"><span class="jush-op">{</span><span class="jush-json_key"><span class="jush-quo"><span class="jush-op">"</span>b<span class="jush-op">"</span></span></span><span class="jush-json_val"><span class="jush-op">:</span> <span class="jush-quo"><span class="jush-op">"</span>c<span class="jush-op">"</span></span></span><span class="jush-op">}</span></span>, <span class="jush-num"><span class="jush-op">-2.5e3</span></span><span class="jush-op">]</span></span><span class="jush-op">,</span></span><span class="jush-json_key"> <span class="jush-quo"><span class="jush-op">"</span>d<span class="jush-op">"</span></span></span><span class="jush-json_val"><span class="jush-op">:</span> <a target="_blank">true</a><span class="jush-op">,</span></span><span class="jush-json_key"> <span class="jush-quo"><span class="jush-op">"</span>e<span class="jush-op">"</span></span></span><span class="jush-json_val"><span class="jush-op">:</span> <a target="_blank">null</a></span><span class="jush-op">}</span></span></span>'],
	['json', '{"esc": "a\\"b", "empty": {}, "arr": []}', '<span class="jush"><span class="jush-json_obj"><span class="jush-op">{</span><span class="jush-json_key"><span class="jush-quo"><span class="jush-op">"</span>esc<span class="jush-op">"</span></span></span><span class="jush-json_val"><span class="jush-op">:</span> <span class="jush-quo"><span class="jush-op">"</span>a<span class="jush-esc"><span class="jush-op">\\</span><span class="jush-op">"</span></span>b<span class="jush-op">"</span></span><span class="jush-op">,</span></span><span class="jush-json_key"> <span class="jush-quo"><span class="jush-op">"</span>empty<span class="jush-op">"</span></span></span><span class="jush-json_val"><span class="jush-op">:</span> <span class="jush-json_obj"><span class="jush-op">{</span><span class="jush-op">}</span></span><span class="jush-op">,</span></span><span class="jush-json_key"> <span class="jush-quo"><span class="jush-op">"</span>arr<span class="jush-op">"</span></span></span><span class="jush-json_val"><span class="jush-op">:</span> <span class="jush-json_arr"><span class="jush-op">[</span><span class="jush-op">]</span></span></span><span class="jush-op">}</span></span></span>'],
	['json', '[}', '<span class="jush"><span class="jush-json_arr"><span class="jush-op">[</span>}</span></span>'], // invalid JSON must not loop

	['htm', '<?php echo "<a href=\'$href\'>";', '<span class="jush"><span class="jush-php"><span class="jush-op">&lt;?php</span><span class="jush-php2"> <span class="jush-php_echo"><a href="https://www.php.net/function.echo" class="jush-help" target="_blank">echo</a> <span class="jush-php_quo"><span class="jush-op">"</span><span class="jush-tag"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a" class="jush-help" target="_blank">a</a><span class="jush-att"><span class="jush-op"> </span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a#href" class="jush-help" target="_blank">href</a><span class="jush-att_apo"><span class="jush-op">=\'</span></span></span></span><span class="jush-php_var">$href</span><span class="jush-tag"><span class="jush-att"><span class="jush-att_apo"><span class="jush-op">\'</span></span></span><span class="jush-op">&gt;</span></span><span class="jush-op">"</span></span><span class="jush-op">;</span></span></span></span></span>'],
	['htm', '<?="<a>";log()?><b>', '<span class="jush"><span class="jush-php"><span class="jush-op">&lt;?</span><span class="jush-php_echo"><span class="jush-op">=</span><span class="jush-php_quo"><span class="jush-op">"</span><span class="jush-tag"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a" class="jush-help" target="_blank">a</a><span class="jush-op">&gt;</span></span><span class="jush-op">"</span></span><span class="jush-op">;</span></span><span class="jush-php2"><a href="https://www.php.net/function.log" class="jush-help" target="_blank">log</a>()<span class="jush-op">?&gt;</span></span></span><span class="jush-tag"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/b" class="jush-help" target="_blank">b</a><span class="jush-op">&gt;</span></span></span>'],
	['php', 'echo "Test" . $_SERVER["PHP_SELF"]; /* ?> comment */ mysql_free_result($result);', '<span class="jush"><span class="jush-php2"><span class="jush-php_echo"><a href="https://www.php.net/function.echo" class="jush-help" target="_blank">echo</a> <span class="jush-php_quo"><span class="jush-op">"</span>Test<span class="jush-op">"</span></span> . <span class="jush-php_var"><a href="https://www.php.net/reserved.variables.server" class="jush-help" target="_blank">$_SERVER</a></span>[<span class="jush-php_quo"><span class="jush-op">"</span>PHP_SELF<span class="jush-op">"</span></span>]<span class="jush-op">;</span></span> <span class="jush-php_com"><span class="jush-op">/*</span> ?&gt; comment <span class="jush-op">*/</span></span> mysql_free_result(<span class="jush-php_var">$result</span>);</span></span>'],
	['php', 'mysql_query("SELECT 1");', '<span class="jush"><span class="jush-php2"><span class="jush-php_sql"><a href="https://www.php.net/function.mysql_query" class="jush-help" target="_blank">mysql_query</a><span class="jush-op">(</span><span class="jush-php_quo"><span class="jush-op">"</span><span class="jush-sql_code"><a href="https://dev.mysql.com/doc/mysql/en/select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span></span><span class="jush-op">"</span></span><span class="jush-op">)</span></span>;</span></span>'],
	['php', 'mssql_query("SELECT TOP 1 * FROM t");', '<span class="jush"><span class="jush-php2"><span class="jush-php_mssql"><a href="https://www.php.net/function.mssql_query" class="jush-help" target="_blank">mssql_query</a><span class="jush-op">(</span><span class="jush-php_quo"><span class="jush-op">"</span><a href="https://msdn.microsoft.com/library/ms189499.aspx" class="jush-help" target="_blank">SELECT</a> <a href="https://msdn.microsoft.com/library/ms189463.aspx" class="jush-help" target="_blank">TOP</a> <span class="jush-num"><span class="jush-op">1</span></span> * <a href="https://msdn.microsoft.com/library/ms177634.aspx" class="jush-help" target="_blank">FROM</a> t<span class="jush-op">"</span></span><span class="jush-op">)</span></span>;</span></span>'],
	['php', '/** @return bool */ ini_set("display_errors", true);', '<span class="jush"><span class="jush-php2"><span class="jush-php_doc"><span class="jush-op">/**</span> <a href="https://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.return.pkg.html" class="jush-help" target="_blank">@return</a> bool <span class="jush-op">*/</span></span> <span class="jush-php_phpini"><a href="https://www.php.net/function.ini_set" class="jush-help" target="_blank">ini_set</a><span class="jush-op">(</span><span class="jush-php_quo"><span class="jush-op">"</span><a href="https://www.php.net/errorfunc.configuration#ini.display-errors" class="jush-help" target="_blank">display_errors</a><span class="jush-op">"</span></span><span class="jush-op">,</span></span> <a href="https://www.php.net/language.types.singleton" class="jush-help" target="_blank">true</a>);</span></span>'],
	['php', 'header("HTTP/1.1 404 Not Found");', '<span class="jush"><span class="jush-php2"><span class="jush-php_http"><a href="https://www.php.net/function.header" class="jush-help" target="_blank">header</a><span class="jush-op">(</span><span class="jush-php_quo"><span class="jush-op">"</span>HTTP/1.1 <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/404" class="jush-help" target="_blank">404 Not Found</a><span class="jush-op">"</span></span><span class="jush-op">)</span></span>;</span></span>'],
	['php', 'header("Content-Type: text/html; charset=utf-8");', '<span class="jush"><span class="jush-php2"><span class="jush-php_http"><a href="https://www.php.net/function.header" class="jush-help" target="_blank">header</a><span class="jush-op">(</span><span class="jush-php_quo"><span class="jush-op">"</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Type" class="jush-help" target="_blank">Content-Type</a>: text/html; charset=utf-8<span class="jush-op">"</span></span><span class="jush-op">)</span></span>;</span></span>'],
	['php', 'mail("", "", "", "From: info@example.com\\nMIME-Version: 1.0");', '<span class="jush"><span class="jush-php2"><span class="jush-php_mail"><a href="https://www.php.net/function.mail" class="jush-help" target="_blank">mail</a><span class="jush-op">(</span><span class="jush-php_quo"><span class="jush-op">"</span><span class="jush-op">"</span></span>, <span class="jush-php_quo"><span class="jush-op">"</span><span class="jush-op">"</span></span>, <span class="jush-php_quo"><span class="jush-op">"</span><span class="jush-op">"</span></span>, <span class="jush-php_quo"><span class="jush-op">"</span><a href="https://tools.ietf.org/html/rfc2076#section-3.4" class="jush-help" target="_blank">From</a>: info@example.com<span class="jush-esc"><span class="jush-op">\\</span><span class="jush-op">n</span></span><a href="https://tools.ietf.org/html/rfc2076#section-3.3" class="jush-help" target="_blank">MIME-Version</a>: 1.0<span class="jush-op">"</span></span><span class="jush-op">)</span></span>;</span></span>'],
	['php', 'echo <<<EOT\ntext $x\nEOT\n. <<<\'EOT\'\ntext $x\nEOT;\necho 1;', '<span class="jush"><span class="jush-php2"><span class="jush-php_echo"><a href="https://www.php.net/function.echo" class="jush-help" target="_blank">echo</a> <span class="jush-php_eot"><span class="jush-op">&lt;&lt;&lt;</span><span class="jush-php_eot2"><span class="jush-op">EOT</span>\ntext <span class="jush-php_var">$x</span><span class="jush-op">\n</span>EOT</span></span>\n. <span class="jush-php_eot"><span class="jush-op">&lt;&lt;&lt;</span>\'<span class="jush-php_eot2"><span class="jush-op">EOT</span>\'\ntext $x<span class="jush-op">\n</span>EOT</span></span><span class="jush-op">;</span></span>\n<span class="jush-php_echo"><a href="https://www.php.net/function.echo" class="jush-help" target="_blank">echo</a> <span class="jush-num"><span class="jush-op">1</span></span><span class="jush-op">;</span></span></span></span>'],
	['php', 'echo \'apo\'; // line\n# hash\necho "a $var b";', '<span class="jush"><span class="jush-php2"><span class="jush-php_echo"><a href="https://www.php.net/function.echo" class="jush-help" target="_blank">echo</a> <span class="jush-php_apo"><span class="jush-op">\'</span>apo<span class="jush-op">\'</span></span><span class="jush-op">;</span></span> <span class="jush-php_one"><span class="jush-op">//</span> line<span class="jush-op">\n</span></span><span class="jush-php_one"><span class="jush-op">#</span> hash<span class="jush-op">\n</span></span><span class="jush-php_echo"><a href="https://www.php.net/function.echo" class="jush-help" target="_blank">echo</a> <span class="jush-php_quo"><span class="jush-op">"</span>a <span class="jush-php_var">$var</span> b<span class="jush-op">"</span></span><span class="jush-op">;</span></span></span></span>'],

	['sql', 'SELECT 1, \'MySQL\'', '<span class="jush"><span class="jush-sql_code"><a href="https://dev.mysql.com/doc/mysql/en/select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span>, <span class="jush-sql_apo"><span class="jush-op">\'</span>MySQL<span class="jush-op">\'</span></span></span></span>'],
	['sql', 'SELECT 1 -- comment\n# hash\n/* block */', '<span class="jush"><span class="jush-sql_code"><a href="https://dev.mysql.com/doc/mysql/en/select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span> <span class="jush-one"><span class="jush-op">-- </span>comment</span>\n<span class="jush-one"><span class="jush-op">#</span> hash</span>\n<span class="jush-com"><span class="jush-op">/*</span> block <span class="jush-op">*/</span></span></span></span>'],
	['sql', '/*!40101 SELECT 1 */', '<span class="jush"><span class="jush-com_code"><span class="jush-op">/*!40101</span></span><span class="jush-sql_code"> <a href="https://dev.mysql.com/doc/mysql/en/select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span> <span class="jush-com_code"><span class="jush-op">*/</span></span></span></span>'],
	['sql', 'SELECT `col`, @var, \'It\'\'s\'', '<span class="jush"><span class="jush-sql_code"><a href="https://dev.mysql.com/doc/mysql/en/select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-bac"><span class="jush-op">`</span>col<span class="jush-op">`</span></span>, <span class="jush-sql_var"><span class="jush-op">@</span>var</span>, <span class="jush-sql_apo"><span class="jush-op">\'</span>It<span class="jush-op">\'\'</span>s<span class="jush-op">\'</span></span></span></span>'],
	['sql', 'SELECT * FROM tab JOIN `tab2`', '<span class="jush"><span class="jush-sql_code"><a href="https://dev.mysql.com/doc/mysql/en/select.html" class="jush-help" target="_blank">SELECT</a> * <a target="_blank">FROM</a> <a href="?table=tab" class="jush-custom">tab</a> <a href="https://dev.mysql.com/doc/mysql/en/join.html" class="jush-help" target="_blank">JOIN</a> <span class="jush-bac"><span class="jush-op">`</span><a href="?table=tab2" class="jush-custom">tab2</a><span class="jush-op">`</span></span></span></span>'],
	['sql', 'AUTO_INCREMENT inet4 CLONE LIMIT', '<span class="jush"><span class="jush-sql_code"><a href="https://dev.mysql.com/doc/mysql/en/example-auto-increment.html" class="jush-help" target="_blank">AUTO_INCREMENT</a> inet4 <a href="https://dev.mysql.com/doc/mysql/en/clone.html" class="jush-help" target="_blank">CLONE</a> <a target="_blank">LIMIT</a></span></span>'],
	['sql', 'SHOW ERRORS; SHOW CREATE TABLE t', '<span class="jush"><span class="jush-sql_code"><a href="https://dev.mysql.com/doc/mysql/en/show-errors.html" class="jush-help" target="_blank">SHOW ERRORS</a><span class="jush-op">;</span></span><span class="jush-sql_code"> <a href="https://dev.mysql.com/doc/mysql/en/show-create-table.html" class="jush-help" target="_blank">SHOW CREATE TABLE</a> t</span></span>'], // a longer phrase wins over SHOW alone
	['sql', 'WHILE x DO SET a = 1; END WHILE', '<span class="jush"><span class="jush-sql_code"><a href="https://dev.mysql.com/doc/mysql/en/while-statement.html" class="jush-help" target="_blank">WHILE</a> x <a href="https://dev.mysql.com/doc/mysql/en/do.html" class="jush-help" target="_blank">DO</a></span><span class="jush-sql_sqlset"><span class="jush-op"> </span><a href="https://dev.mysql.com/doc/mysql/en/set-statement.html" class="jush-help" target="_blank">SET</a><span class="jush-op"> </span>a <span class="jush-sqlset_val"><span class="jush-op">=</span> <span class="jush-num"><span class="jush-op">1</span></span><span class="jush-op">;</span></span></span><span class="jush-sql_code"> <a href="https://dev.mysql.com/doc/mysql/en/begin-end.html" class="jush-help" target="_blank">END</a> <a href="https://dev.mysql.com/doc/mysql/en/while-statement.html" class="jush-help" target="_blank">WHILE</a></span></span>'], // DO leaves the state and is still linked
	['sql', 'LOAD DATA INFILE \'f\'', '<span class="jush"><span class="jush-sql_code"><a href="https://dev.mysql.com/doc/mysql/en/load-data.html" class="jush-help" target="_blank">LOAD DATA</a> INFILE <span class="jush-sql_apo"><span class="jush-op">\'</span>f<span class="jush-op">\'</span></span></span></span>'], // MySQL documents only the beginning of the MariaDB phrase
	['sqlite', 'SELECT 1, \'SQLite\'', '<span class="jush"><a href="https://www.sqlite.org/lang_select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span>, <span class="jush-sqlite_apo"><span class="jush-op">\'</span>SQLite<span class="jush-op">\'</span></span></span>'],
	['sqlite', 'CREATE TABLE t (id INTEGER) STRICT, WITHOUT ROWID', '<span class="jush"><a href="https://www.sqlite.org/lang_createtable.html" class="jush-help" target="_blank">CREATE TABLE</a> t (id <a href="https://www.sqlite.org/datatype3.html" class="jush-help" target="_blank">INTEGER</a>) <a href="https://www.sqlite.org/stricttables.html" class="jush-help" target="_blank">STRICT</a>, <a href="https://www.sqlite.org/withoutrowid.html" class="jush-help" target="_blank">WITHOUT ROWID</a></span>'],
	['sqlite', 'WITH RECURSIVE cte AS (SELECT 1) SELECT * FROM cte', '<span class="jush"><a href="https://www.sqlite.org/lang_with.html" class="jush-help" target="_blank">WITH</a> <a target="_blank">RECURSIVE</a> cte <a target="_blank">AS</a> (<a href="https://www.sqlite.org/lang_select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span>) <a href="https://www.sqlite.org/lang_select.html" class="jush-help" target="_blank">SELECT</a> * <a target="_blank">FROM</a> cte</span>'],
	['sqlite', 'SELECT row_number() OVER (PARTITION BY x ORDER BY y) FROM t', '<span class="jush"><a href="https://www.sqlite.org/lang_select.html" class="jush-help" target="_blank">SELECT</a> <a href="https://www.sqlite.org/windowfunctions.html#row_number" class="jush-help" target="_blank">row_number</a>() <a href="https://www.sqlite.org/windowfunctions.html" class="jush-help" target="_blank">OVER</a> (<a href="https://www.sqlite.org/windowfunctions.html" class="jush-help" target="_blank">PARTITION BY</a> x <a target="_blank">ORDER</a> <a target="_blank">BY</a> y) <a target="_blank">FROM</a> t</span>'],
	['sqlite', 'INSERT INTO t VALUES (1) ON CONFLICT DO UPDATE SET x = excluded.x RETURNING id', '<span class="jush"><a href="https://www.sqlite.org/lang_insert.html" class="jush-help" target="_blank">INSERT</a> <a target="_blank">INTO</a> t <a target="_blank">VALUES</a> (<span class="jush-num"><span class="jush-op">1</span></span>) <a target="_blank">ON</a> <a href="https://www.sqlite.org/lang_conflict.html" class="jush-help" target="_blank">CONFLICT</a> <a target="_blank">DO</a> <a href="https://www.sqlite.org/lang_update.html" class="jush-help" target="_blank">UPDATE</a> <a target="_blank">SET</a> x = <a target="_blank">excluded</a>.x <a target="_blank">RETURNING</a> id</span>'],
	['sqlite', 'SELECT json_extract(data, \'$.x\') FROM t', '<span class="jush"><a href="https://www.sqlite.org/lang_select.html" class="jush-help" target="_blank">SELECT</a> <a href="https://www.sqlite.org/json1.html#json_extract" class="jush-help" target="_blank">json_extract</a>(data, <span class="jush-sqlite_apo"><span class="jush-op">\'</span>$.x<span class="jush-op">\'</span></span>) <a target="_blank">FROM</a> t</span>'],
	['sqlite', 'SELECT sqrt(4), unixepoch()', '<span class="jush"><a href="https://www.sqlite.org/lang_select.html" class="jush-help" target="_blank">SELECT</a> <a href="https://www.sqlite.org/lang_mathfunc.html#sqrt" class="jush-help" target="_blank">sqrt</a>(<span class="jush-num"><span class="jush-op">4</span></span>), <a href="https://www.sqlite.org/lang_datefunc.html#unixepoch" class="jush-help" target="_blank">unixepoch</a>()</span>'],
	['pgsql', 'SELECT 1, $tag$ \'text\' $tag$, /* WHERE */ \'PostgreSQL\'', '<span class="jush"><a href="https://www.postgresql.org/docs/current/sql-select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span>, <span class="jush-pgsql_eot"><span class="jush-op">$</span><span class="jush-pgsql_eot2"><span class="jush-op">tag$</span> \'text\' <span class="jush-op">$tag$</span></span></span>, <span class="jush-com_nest"><span class="jush-op">/*</span> WHERE <span class="jush-op">*/</span></span> <span class="jush-sql_apo"><span class="jush-op">\'</span>PostgreSQL<span class="jush-op">\'</span></span></span>'],
	['pgsql', 'DO $$ BEGIN SELECT 1; END $$', '<span class="jush"><a href="https://www.postgresql.org/docs/current/sql-do.html" class="jush-help" target="_blank">DO</a> <span class="jush-pgsql_eot"><span class="jush-op">$</span><span class="jush-pgsql_eot2"><span class="jush-op">$</span> <a href="https://www.postgresql.org/docs/current/sql-begin.html" class="jush-help" target="_blank">BEGIN</a> <a href="https://www.postgresql.org/docs/current/sql-select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span>; <a href="https://www.postgresql.org/docs/current/sql-end.html" class="jush-help" target="_blank">END</a> <span class="jush-op">$$</span></span></span></span>'],
	['pgsql', 'CREATE FUNCTION f() RETURNS int AS $x$ SELECT \'a\' $x$ LANGUAGE sql', '<span class="jush"><a href="https://www.postgresql.org/docs/current/sql-createfunction.html" class="jush-help" target="_blank">CREATE FUNCTION</a> f() RETURNS int <a target="_blank">AS</a> <span class="jush-pgsql_eot"><span class="jush-op">$</span><span class="jush-pgsql_eot2"><span class="jush-op">x$</span> <a href="https://www.postgresql.org/docs/current/sql-select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-sql_apo"><span class="jush-op">\'</span>a<span class="jush-op">\'</span></span> <span class="jush-op">$x$</span></span></span> LANGUAGE sql</span>'],
	['pgsql', 'DO $$ SELECT \'a\'', '<span class="jush"><a href="https://www.postgresql.org/docs/current/sql-do.html" class="jush-help" target="_blank">DO</a> <span class="jush-pgsql_eot"><span class="jush-op">$</span><span class="jush-pgsql_eot2"><span class="jush-op">$</span> <a href="https://www.postgresql.org/docs/current/sql-select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-sql_apo"><span class="jush-op">\'</span>a<span class="jush-op">\'</span></span></span></span></span>'], // not terminated yet
	['pgsql', 'DO $o$ SELECT $i$ raw $i$ $o$', '<span class="jush"><a href="https://www.postgresql.org/docs/current/sql-do.html" class="jush-help" target="_blank">DO</a> <span class="jush-pgsql_eot"><span class="jush-op">$</span><span class="jush-pgsql_eot2"><span class="jush-op">o$</span> <a href="https://www.postgresql.org/docs/current/sql-select.html" class="jush-help" target="_blank">SELECT</a> <span class="jush-pgsql_eot"><span class="jush-op">$</span><span class="jush-pgsql_eot2"><span class="jush-op">i$</span> raw <span class="jush-op">$i$</span></span></span> <span class="jush-op">$o$</span></span></span></span>'],
	['pgsql', 'ALTER DATABASE "x"; DROP OWNED BY CURRENT_USER', '<span class="jush"><a href="https://www.postgresql.org/docs/current/sql-alterdatabase.html" class="jush-help" target="_blank">ALTER DATABASE</a> <span class="jush-sqlite_quo"><span class="jush-op">"</span>x<span class="jush-op">"</span></span>; <a href="https://www.postgresql.org/docs/current/sql-drop-owned.html" class="jush-help" target="_blank">DROP OWNED</a> BY <a href="https://www.postgresql.org/docs/current/functions-info.html" class="jush-help" target="_blank">CURRENT_USER</a></span>'],
	['mssql', 'SELECT 1, \'MS SQL\'', '<span class="jush"><a href="https://msdn.microsoft.com/library/ms189499.aspx" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span>, <span class="jush-sqlite_apo"><span class="jush-op">\'</span>MS SQL<span class="jush-op">\'</span></span></span>'],
	['oracle', 'SELECT 1, \'Oracle\'', '<span class="jush"><a href="https://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span>, <span class="jush-sqlite_apo"><span class="jush-op">\'</span>Oracle<span class="jush-op">\'</span></span></span>'],

	['sql', 'SET foreign_key_checks = 0', '<span class="jush"><span class="jush-sql_sqlset"><a href="https://dev.mysql.com/doc/mysql/en/set-statement.html" class="jush-help" target="_blank">SET</a><span class="jush-op"> </span><a href="https://dev.mysql.com/doc/mysql/en/server-system-variables.html#sysvar_foreign_key_checks" class="jush-help" target="_blank">foreign_key_checks</a> <span class="jush-sqlset_val"><span class="jush-op">=</span> <span class="jush-num"><span class="jush-op">0</span></span></span></span></span>'],
	['sqlstatus', 'Qcache_hits', '<span class="jush"><a href="https://dev.mysql.com/doc/mysql/en/server-status-variables.html#statvar_Qcache_hits" class="jush-help" target="_blank">Qcache_hits</a></span>'],
	['pgsqlset', 'autovacuum', '<span class="jush"><a href="https://www.postgresql.org/docs/current/runtime-config-vacuum.html#GUC-AUTOVACUUM" class="jush-help" target="_blank">autovacuum</a></span>'],

	['cnf', 'Listen 80\nphp_flag display_errors On', '<span class="jush"><a href="https://httpd.apache.org/docs/current/mod/mpm_common.html#listen" class="jush-help" target="_blank">Listen</a> 80<span class="jush-cnf_phpini"><span class="jush-op">\n</span><a href="https://www.php.net/configuration.changes#configuration.changes.apache" class="jush-help" target="_blank">php_flag</a><span class="jush-op"> </span><a href="https://www.php.net/errorfunc.configuration#ini.display-errors" class="jush-help" target="_blank">display_errors</a><span class="jush-cnf_phpini_val"><span class="jush-op"> </span>On</span></span></span>'],
	['http', 'HTTP/1.1 302 Found\nLocation: /', '<span class="jush">HTTP/1.1 <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/302" class="jush-help" target="_blank">302 Found</a>\n<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Location" class="jush-help" target="_blank">Location</a>: /</span>'],
	['http', 'GET / HTTP/1.1\nHost: example.com', '<span class="jush"><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/GET" class="jush-help" target="_blank">GET</a> / HTTP/1.1\n<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Host" class="jush-help" target="_blank">Host</a>: example.com</span>'],
	['phpini', 'display_errors = On\n; comment', '<span class="jush"><a href="https://www.php.net/errorfunc.configuration#ini.display-errors" class="jush-help" target="_blank">display_errors</a> = On\n<span class="jush-one"><span class="jush-op">;</span> comment</span></span>'],
	['txt', 'plain <?php echo 1; ?> text', '<span class="jush">plain &lt;?php echo 1; ?&gt; text</span>'],

	['simpledb', 'SELECT * FROM domain WHERE id = 1', '<span class="jush"><a href="https://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/QuotingRulesSelect.html" class="jush-help" target="_blank">SELECT</a> * <a target="_blank">FROM</a> domain <a href="https://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/SimpleQueriesSelect.html" class="jush-help" target="_blank">WHERE</a> id = 1</span>'],
	['igdb', 'POST games; fields *;', '<span class="jush"><a href="https://api-docs.igdb.com/#endpoints" class="jush-help" target="_blank">POST</a> games; <a href="https://api-docs.igdb.com/#fields" class="jush-help" target="_blank">fields</a> *;</span>'],

	['redis', 'GET user:1\nRESTORE-ASKING key 0 dump', '<span class="jush"><a href="https://redis.io/docs/latest/commands/get/" class="jush-help" target="_blank">GET</a> user:1\n<a href="https://redis.io/docs/latest/commands/restore-asking/" class="jush-help" target="_blank">RESTORE-ASKING</a> key 0 dump</span>'],
	['redis', 'CONFIG SET appendonly "yes"', '<span class="jush"><a href="https://redis.io/docs/latest/commands/config-set/" class="jush-help" target="_blank">CONFIG SET</a> appendonly <span class="jush-quo"><span class="jush-op">"</span>yes<span class="jush-op">"</span></span></span>'],
	['redis', "SET key 'a\\'b' GET", '<span class="jush"><a href="https://redis.io/docs/latest/commands/set/" class="jush-help" target="_blank">SET</a> key <span class="jush-apo"><span class="jush-op">\'</span>a<span class="jush-esc"><span class="jush-op">\\</span><span class="jush-op">\'</span></span>b<span class="jush-op">\'</span></span> <a href="https://redis.io/docs/latest/commands/get/" class="jush-help" target="_blank">GET</a></span>'], // GET is not a command here but it is linked anyway
];

tests.highlight_html = [
	['htm', '&lt;a<b>re</b>a <i>href</i>=""&gt;', '<span class="jush"><span class="jush-tag"><span class="jush-op">&lt;</span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/area" class="jush-help" target="_blank">a<b>re</b>a</a><span class="jush-att"><span class="jush-op"> <i></span><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/area#href" class="jush-help" target="_blank">href</i></a><span class="jush-att_quo"><span class="jush-op">="</span><span class="jush-op">"</span></span></span><span class="jush-op">&gt;</span></span></span>']
];

const html = [];

for (const callback in tests) {
	for (const test of tests[callback]) {
		const highlighted = jush[callback](test[0], test[1]);
		if (highlighted !== test[2]) {
			console.log(highlighted.replace(/['\\]/g, '\\$&').replace(/\n/g, '\\n'));
			html.push('<b class="error">error:</b>');
		}
		html.push('<p><b class="lang">' + test[0] + '</b> <code class="jush-' + test[0] + '">' + highlighted + '</code></p>');
  }
}

// MariaDB flavor - Adminer's syntaxHighlighting() replaces the base URL at runtime
const mariaTests = [
	['sql', 'SELECT 1', '<span class="jush"><span class="jush-sql_code"><a href="https://mariadb.com/kb/en/select/" class="jush-help" target="_blank">SELECT</a> <span class="jush-num"><span class="jush-op">1</span></span></span></span>'],
	['sql', 'AUTO_INCREMENT inet4 CLONE LIMIT', '<span class="jush"><span class="jush-sql_code"><a href="https://mariadb.com/kb/en/auto_increment/" class="jush-help" target="_blank">AUTO_INCREMENT</a> <a href="https://mariadb.com/kb/en/inet4/" class="jush-help" target="_blank">inet4</a> CLONE <a href="https://mariadb.com/kb/en/limit/" class="jush-help" target="_blank">LIMIT</a></span></span>'],
	['sql', 'LOAD DATA INFILE \'f\'', '<span class="jush"><span class="jush-sql_code"><a href="https://mariadb.com/kb/en/load-data-infile/" class="jush-help" target="_blank">LOAD DATA INFILE</a> <span class="jush-sql_apo"><span class="jush-op">\'</span>f<span class="jush-op">\'</span></span></span></span>'],
	['sqlset', 'foreign_key_checks', '<span class="jush"><a href="https://mariadb.com/kb/en/server-system-variables/#foreign_key_checks" class="jush-help" target="_blank">foreign_key_checks</a></span>'],
	['sqlstatus', 'Aborted_clients', '<span class="jush"><a href="https://mariadb.com/kb/en/server-status-variables/#aborted_clients" class="jush-help" target="_blank">Aborted_clients</a></span>'],
];

for (const state of ['sql', 'sqlset', 'sqlstatus']) {
	jush.urls[state][0] = jush.urls[state][0].replace('dev.mysql.com/doc/mysql', 'mariadb.com/kb');
}
for (const test of mariaTests) {
	const highlighted = jush.highlight(test[0], test[1]);
	if (highlighted !== test[2]) {
		console.log(highlighted.replace(/['\\]/g, '\\$&').replace(/\n/g, '\\n'));
		html.push('<b class="error">error:</b>');
	}
	html.push('<p><b class="lang">' + test[0] + ' (MariaDB)</b> <code class="jush-' + test[0] + '">' + highlighted + '</code></p>');
}
for (const state of ['sql', 'sqlset', 'sqlstatus']) {
	jush.urls[state][0] = jush.urls[state][0].replace('mariadb.com/kb', 'dev.mysql.com/doc/mysql');
}

// SQL autocomplete
const tables = {
	albums: ['id', 'interpret', 'title'],
	songs: ['id', 'album', 'title'],
};
const quotedTables = { 'my albums': ['my id', 'title'], songs: ['id', 'album'] }; // names which are not identifiers are always quoted
const autocompleteEsc = { pgsql: '""', mssql: '[]' }; // escaped empty identifier, the other states use ``
const autocompleteTests = [ // state, text before and after the caret, expected words with the length of the typed prefix, tables with columns
	['sql', 'SELECT * FROM ', '', '{"albums ":0,"songs ":0}', tables], // all tables are offered after FROM
	['sql', 'SELECT id,\ntitle\nFROM albums\n', '', '{"INNER JOIN ":0,"LEFT JOIN ":0,"WHERE ":0,"GROUP BY ":0,"HAVING ":0,"ORDER BY ":0,"LIMIT ":0,"OFFSET ":0}', tables], // the query can span lines
	['sql', '/* WHERE\nin a comment */\nSELECT * FROM albums\n', '', '{"INNER JOIN ":0,"LEFT JOIN ":0,"WHERE ":0,"GROUP BY ":0,"HAVING ":0,"ORDER BY ":0,"LIMIT ":0,"OFFSET ":0}', tables], // a multi-line comment is ignored
	['sql', 'SELECT * FROM albums\nWHERE id = 1\n;\n', '', '{"SELECT ":0,"INSERT INTO ":0,"UPDATE ":0,"DELETE FROM ":0,"TRUNCATE ":0,"EXPLAIN ":0}', tables], // the previous query is stripped
	['sql', 'SELECT * FROM albums\n', '\nWHERE id = 1;\nSELECT * FROM songs ORDER BY x ', '{"INNER JOIN ":0,"LEFT JOIN ":0,"GROUP BY ":0,"HAVING ":0,"ORDER BY ":0,"LIMIT ":0,"OFFSET ":0}', tables], // the next query is stripped, the rest of the current one is not
	['sql', 'SELECT *\nFROM albums\nJOIN songs ON albums.id = songs.album\nWHERE ', '', '{"id":0,"interpret":0,"title":0,"album":0,"albums.":0,"songs.":0,"GROUP BY ":0,"HAVING ":0,"ORDER BY ":0,"LIMIT ":0,"OFFSET ":0}', tables], // columns of all joined tables
	['sql', 'SELECT * FROM albums a\nWHERE a.', '', '{"id":0,"interpret":0,"title":0}', tables], // columns of an aliased table
	['sql', 'SELECT * FROM albums\nWHERE ti', '', '{"title":2}', tables], // the value is the length of the typed prefix
	['com', 'SELECT ', '', '{}', tables], // no autocomplete in a comment
	['sql', 'SELECT * FROM ', '', '{"`my albums` ":0,"songs ":0}', quotedTables], // MySQL quotes a name which is not an identifier
	['sql', 'SELECT * FROM `albums`\nWHERE ', '', '{"`id`":0,"`interpret`":0,"`title`":0,"GROUP BY ":0,"HAVING ":0,"ORDER BY ":0,"LIMIT ":0,"OFFSET ":0}', tables], // a backtick anywhere quotes everything, the table name is found inside it
	['pgsql', 'SELECT * FROM ', '', '{"\\"my albums\\" ":0,"songs ":0}', quotedTables], // PostgreSQL quotes by ""
	['mssql', 'SELECT * FROM [my albums]\nWHERE ', '', '{"[my id]":0,"[title]":0,"GROUP BY ":0,"HAVING ":0,"ORDER BY ":0,"LIMIT ":0,"OFFSET ":0}', quotedTables], // MS SQL quotes by [], the table name is found inside it
];

for (const test of autocompleteTests) {
	const completed = JSON.stringify(jush.autocompleteSql(autocompleteEsc[test[0]] || '``', test[4])(test[0], test[1], test[2]));
	if (completed !== test[3]) {
		console.log(completed.replace(/['\\]/g, '\\$&'));
		html.push('<b class="error">error:</b>');
	}
	html.push('<p><b class="lang">' + test[0] + ' (autocomplete)</b> <code class="jush-' + test[0] + '">' + jush.highlight(test[0], test[1] + '\u2038' + test[2]) + '\n' + jush.highlight('json', completed) + '</code></p>');
}

document.getElementById('result').innerHTML = html.join('\n');
