import "./cljs_env.js";
goog.provide('clojure_eval.test_utils');
var module$node_modules$$codemirror$state$dist$index_cjs=shadow.js.require("module$node_modules$$codemirror$state$dist$index_cjs", {});
clojure_eval.test_utils.make_state = (function clojure_eval$test_utils$make_state(extensions,doc){
var vec__55539 = cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (p__55542,match){
var vec__55543 = p__55542;
var doc__$1 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55543,(0),null);
var ranges = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55543,(1),null);
if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(match,"|")){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [doc__$1,cljs.core.conj.cljs$core$IFn$_invoke$arity$2(ranges,module$node_modules$$codemirror$state$dist$index_cjs.EditorSelection.cursor(((doc__$1).length)))], null);
} else {
if(clojure.string.starts_with_QMARK_(match,"<")){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [[doc__$1,cljs.core.subs.cljs$core$IFn$_invoke$arity$3(match,(1),(cljs.core.count(match) - (1)))].join(''),cljs.core.conj.cljs$core$IFn$_invoke$arity$2(ranges,module$node_modules$$codemirror$state$dist$index_cjs.EditorSelection.range(((doc__$1).length),(((doc__$1).length) + (cljs.core.count(match) - (2)))))], null);
} else {
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [[doc__$1,cljs.core.str.cljs$core$IFn$_invoke$arity$1(match)].join(''),ranges], null);

}
}
}),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["",cljs.core.PersistentVector.EMPTY], null),cljs.core.re_seq(/\||<[^>]*?>|[^<>|]+/,doc));
var doc__$1 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55539,(0),null);
var ranges = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55539,(1),null);
return module$node_modules$$codemirror$state$dist$index_cjs.EditorState.create(({"doc": doc__$1, "selection": ((cljs.core.seq(ranges))?module$node_modules$$codemirror$state$dist$index_cjs.EditorSelection.create(cljs.core.to_array(ranges)):undefined), "extensions": (function (){var G__55546 = [module$node_modules$$codemirror$state$dist$index_cjs.EditorState.allowMultipleSelections.of(true)];
if(cljs.core.truth_(extensions)){
var array55548 = G__55546;
array55548.push(extensions);

return array55548;
} else {
return G__55546;
}
})()}));
});
clojure_eval.test_utils.state_str = (function clojure_eval$test_utils$state_str(state){
var doc = cljs.core.str.cljs$core$IFn$_invoke$arity$1(state.doc);
return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (doc__$1,p__55555){
var map__55556 = p__55555;
var map__55556__$1 = (((((!((map__55556 == null))))?(((((map__55556.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__55556.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__55556):map__55556);
var empty = (function (){var obj55564 = map__55556__$1;
var k55565 = "empty";
if((function (){var obj55566 = obj55564;
return (((!((obj55566 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55565,obj55566)));
})()){
return (obj55564[k55565]);
} else {
return undefined;
}
})();
var from = (function (){var obj55578 = map__55556__$1;
var k55579 = "from";
if((function (){var obj55582 = obj55578;
return (((!((obj55582 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55579,obj55582)));
})()){
return (obj55578[k55579]);
} else {
return undefined;
}
})();
var to = (function (){var obj55587 = map__55556__$1;
var k55588 = "to";
if((function (){var obj55589 = obj55587;
return (((!((obj55589 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55588,obj55589)));
})()){
return (obj55587[k55588]);
} else {
return undefined;
}
})();
if(cljs.core.truth_(empty)){
return [cljs.core.subs.cljs$core$IFn$_invoke$arity$3(doc__$1,(0),from),"|",cljs.core.subs.cljs$core$IFn$_invoke$arity$2(doc__$1,from)].join('');
} else {
return [cljs.core.subs.cljs$core$IFn$_invoke$arity$3(doc__$1,(0),from),"<",cljs.core.subs.cljs$core$IFn$_invoke$arity$3(doc__$1,from,to),">",cljs.core.subs.cljs$core$IFn$_invoke$arity$2(doc__$1,to)].join('');
}
}),doc,cljs.core.reverse(state.selection.ranges));
});
clojure_eval.test_utils.apply_cmd = (function clojure_eval$test_utils$apply_cmd(extensions,cmd,doc){
var state = clojure_eval.test_utils.make_state(extensions,doc);
var _BANG_tr = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(null);
var _ = (function (){var G__55597 = ({"state": state, "dispatch": (function (p1__55594_SHARP_){
return cljs.core.reset_BANG_(_BANG_tr,p1__55594_SHARP_);
})});
return (cmd.cljs$core$IFn$_invoke$arity$1 ? cmd.cljs$core$IFn$_invoke$arity$1(G__55597) : cmd.call(null,G__55597));
})();
var tr = cljs.core.deref(_BANG_tr);
return clojure_eval.test_utils.state_str((function (){var obj55600 = tr;
var k55601 = "state";
if((function (){var obj55605 = obj55600;
return (((!((obj55605 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55601,obj55605)));
})()){
return (obj55600[k55601]);
} else {
return undefined;
}
})());
});
clojure_eval.test_utils.apply_f = (function clojure_eval$test_utils$apply_f(extensions,cmd,doc){
if(cljs.core.array_QMARK_(extensions)){
} else {
throw (new Error("Assert failed: (array? extensions)"));
}

if(cljs.core.fn_QMARK_(cmd)){
} else {
throw (new Error("Assert failed: (fn? cmd)"));
}

if(typeof doc === 'string'){
} else {
throw (new Error("Assert failed: (string? doc)"));
}

var state = clojure_eval.test_utils.make_state(extensions,doc);
var tr = (cmd.cljs$core$IFn$_invoke$arity$1 ? cmd.cljs$core$IFn$_invoke$arity$1(state) : cmd.call(null,state));
return clojure_eval.test_utils.state_str((cljs.core.truth_(tr)?tr.state:state));
});

//# sourceMappingURL=clojure_eval.test_utils.js.map
