function textWithSelection(e,t){if(!t.length)return e;function n(e,t,n){return e.substring(0,t)+n+e.substring(t)}const r=e.split("\n");t.sort(TextUtils.TextRange.comparator);for(let o=t.length-1;o>=0;--o){let e=t[o];e=e.normalize();const s=e.isEmpty()?"|":"<";r[e.endLine]=n(r[e.endLine],e.endColumn,s),e.isEmpty()||(r[e.startLine]=n(r[e.startLine],e.startColumn,">"))}return r.join("\n")}self.SourcesTestRunner=self.SourcesTestRunner||{},SourcesTestRunner.createTestEditor=function(e,t){const n=new SourceFrame.SourcesTextEditor(t||new SourceFrame.SourcesTextEditorDelegate);return e=e||100,n.element.style.height=e+"px",n.element.style.flex="none",n.show(self.UI.inspectorView.element),n},SourcesTestRunner.dumpTextWithSelection=function(e,t){let n=textWithSelection(e.text(),e.selections());t&&(n=n.replace(/ /g,".")),TestRunner.addResult(n)},SourcesTestRunner.setLineSelections=function(e,t){const n=[];for(let r=0;r<t.length;++r){const e=t[r];"number"===typeof e.column&&(e.from=e.column,e.to=e.column),n.push(new TextUtils.TextRange(e.line,e.from,e.line,e.to))}e.setSelections(n)},SourcesTestRunner.typeIn=function(e,t,n){n=n||new Function;const r=new Function;for(let o=0;o<t.length;++o){const s=o+1===t.length?n:r;switch(t[o]){case"\n":SourcesTestRunner.fakeKeyEvent(e,"Enter",null,s);break;case"L":SourcesTestRunner.fakeKeyEvent(e,"ArrowLeft",null,s);break;case"R":SourcesTestRunner.fakeKeyEvent(e,"ArrowRight",null,s);break;case"U":SourcesTestRunner.fakeKeyEvent(e,"ArrowUp",null,s);break;case"D":SourcesTestRunner.fakeKeyEvent(e,"ArrowDown",null,s);break;default:SourcesTestRunner.fakeKeyEvent(e,t[o],null,s)}}};const eventCodes={Enter:13,Home:36,ArrowLeft:37,ArrowUp:38,ArrowRight:39,ArrowDown:40};function createCodeMirrorFakeEvent(e,t,n,r,o){const s={_handled:!1,type:t,keyCode:n,charCode:r,preventDefault:function(){this._handled=!0},stopPropagation:function(){},target:e._codeMirror.display.input.textarea};if(o)for(let i=0;i<o.length;++i)s[o[i]]=!0;return s}function fakeCodeMirrorKeyEvent(e,t,n,r,o){const s=createCodeMirrorFakeEvent(e,t,n,r,o);switch(t){case"keydown":e._codeMirror.triggerOnKeyDown(s);break;case"keypress":e._codeMirror.triggerOnKeyPress(s);break;case"keyup":e._codeMirror.triggerOnKeyUp(s);break;default:throw new Error("Unknown KeyEvent type")}return s._handled}function fakeCodeMirrorInputEvent(e,t){if("string"!==typeof t)return;const n=e._codeMirror.display.input,r=n.textarea.value,o=r.substring(0,n.textarea.selectionStart)+t+r.substring(n.textarea.selectionEnd),s=n.textarea.selectionStart+t.length;n.textarea.value=o,n.textarea.setSelectionRange(s,s),n.poll()}SourcesTestRunner.fakeKeyEvent=function(e,t,n,r){let o,s;if(n=n||[],"'"===t?(o=222,s=0):'"'===t?(o=222,n.push("shiftKey"),s=34):"("===t&&(o="9".charCodeAt(0),n.push("shiftKey"),s=t.charCodeAt(0)),o=o||eventCodes[t]||t,"string"===typeof o&&(o=o.charCodeAt(0)),fakeCodeMirrorKeyEvent(e,"keydown",o,s,n))return void r();if(fakeCodeMirrorKeyEvent(e,"keypress",o,s,n))return void r();const i=new Promise((t=>e._codeMirror.on("inputRead",t)));fakeCodeMirrorInputEvent(e,t),fakeCodeMirrorKeyEvent(e,"keyup",o,s,n),i.then(r)},SourcesTestRunner.dumpSelectionStats=function(e){const t={},n=[],r=e.selections();for(let o=0;o<r.length;++o){const s=r[o],i=e.text(s);t[i]?++t[i]:(t[i]=1,n.push(i))}for(let o=0;o<n.length;++o){let e=n[o];e=e.length?"'"+e+"'":"<Empty string>",TestRunner.addResult(e+": "+t[n[o]])}};