diff --git a/.gitignore b/.gitignore
index 1dbeeb3..a626d07 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,17 +1,16 @@
classes
.cljsbuild
.lein-deps-sum
-public/build_no_opt
-public/test_*.js
-public/domina.js
-domina-tests
+.lein-repl-history
lib
+out
+dev-resources/public/js/*.js
*.jar
.repl
pom.xml
.lein-plugins
.lein-failures
-/target
+target
*.*~
\#*#
.#*
diff --git a/dev-resources/clj/ring/server.clj b/dev-resources/clj/ring/server.clj
new file mode 100644
index 0000000..948e2ab
--- /dev/null
+++ b/dev-resources/clj/ring/server.clj
@@ -0,0 +1,23 @@
+(ns ring.server
+ (:require [cemerick.austin.repls :refer (browser-connected-repl-js)]
+ [net.cgrand.enlive-html :as enlive]
+ [compojure.route :refer (resources)]
+ [compojure.core :refer (GET defroutes)]
+ ring.adapter.jetty
+ [clojure.java.io :as io]))
+
+(enlive/deftemplate page
+ (io/resource "public/index.html")
+ []
+ [:body] (enlive/append
+ (enlive/html [:script (browser-connected-repl-js)])))
+
+(defroutes site
+ (resources "/")
+ (GET "/*" req (page)))
+
+(defn run
+ []
+ (defonce server
+ (ring.adapter.jetty/run-jetty #'site {:port 8080 :join? false}))
+ server)
diff --git a/dev-resources/cljs/domina/brepl.cljs b/dev-resources/cljs/domina/brepl.cljs
new file mode 100644
index 0000000..5216834
--- /dev/null
+++ b/dev-resources/cljs/domina/brepl.cljs
@@ -0,0 +1,6 @@
+(ns domina.brepl
+ (:require [clojure.browser.repl]))
+
+(defn whoami
+ []
+ (.-userAgent js/navigator))
diff --git a/dev-resources/public/index.html b/dev-resources/public/index.html
new file mode 100644
index 0000000..ee6d793
--- /dev/null
+++ b/dev-resources/public/index.html
@@ -0,0 +1,36 @@
+
+
+
+
+ bREPL Connection
+
+
+
+
+ BREPL connection
+ Running the brepl
+
+ cd
to
+ $DOMINA
, and run:
+ $ lein do compile, repl This will compile the domina cljs code.
+ Once you're in the REPL evaluate
+ (run)
. That just starts jetty on port
+ 8080
; if you open a browser to
+ that server , you'll
+ see this page.
+
+ Activate the browser-connected REPL like so:
+ (browser-repl)
+
+ Now that the ClojureScript REPL is ready, you need to load
+ http://localhost:8080 , or
+ reload it if you brought it up before the REPL environment was
+ created. Once you do that, evaluate some ClojureScript to make
+ sure your shiny new REPL is working, e.g.
+ (js/alert "Hello, Domina!")
+
+
+
+
diff --git a/profiles.clj b/profiles.clj
new file mode 100644
index 0000000..15b25e9
--- /dev/null
+++ b/profiles.clj
@@ -0,0 +1,45 @@
+{:dev {:resource-paths ["dev-resources"]
+ :test-paths ["dev-resources/clj" "test/cljs" "dev-resources/cljs"]
+ :dependencies [[hiccups "0.2.0"]
+ [ring "1.2.1"]
+ [compojure "1.1.6"]
+ [enlive "1.1.4"]]
+ :plugins [[com.cemerick/clojurescript.test "0.2.1"]
+ [com.cemerick/austin "0.1.3"]]
+ :cljsbuild {:builds {#_:none
+ #_{:source-paths ["src/cljs" "test/cljs"]
+ :compiler {:libs ["goog/dom/query.js"]
+ :pretty-print true
+ :optimizations :none
+ :output-to "dev-resources/public/js/none.js"}}
+ :whitespace
+ {:source-paths ["src/cljs" "test/cljs" "dev-resources/cljs"]
+ :compiler {:libs ["goog/dom/query.js"]
+ :optimizations :whitespace
+ :pretty-print true
+ :output-to "dev-resources/public/js/whitespace.js"}}
+ #_:simple
+ #_{:source-paths ["src/cljs" "test/cljs"]
+ :compiler {:libs ["goog/dom/query.js"]
+ :optimizations :simple
+ :pretty-print true
+ :output-to "dev-resources/public/js/simple.js"}}
+ #_:advanced
+ #_{:source-paths ["src/cljs" "test/cljs"]
+ :compiler {:libs ["goog/dom/query.js"]
+ :optimizations :advanced
+ :pretty-print true
+ :output-to "dev-resources/public/js/advanced.js"}}}
+ :test-commands {"whitespace"
+ ["phantomjs" :runner "dev-resources/public/js/whitespace.js"]
+
+ #_"simple"
+ #_["phantomjs" :runner "dev-resources/public/js/simple.js"]
+
+ #_"advanced"
+ #_["phantomjs" :runner "dev-resources/public/js/advanced.js"]}}
+ :injections [(require '[ring.server :as http :refer [run]]
+ 'cemerick.austin.repls)
+ (defn browser-repl []
+ (cemerick.austin.repls/cljs-repl (reset! cemerick.austin.repls/browser-repl-env
+ (cemerick.austin/repl-env))))]}}
diff --git a/project.clj b/project.clj
index a2d954c..e84f7f0 100644
--- a/project.clj
+++ b/project.clj
@@ -1,47 +1,10 @@
(defproject domina "1.0.3-SNAPSHOT"
:description "A DOM manipulation library for ClojureScript inspired by JQuery"
- :source-paths ["src/cljs"]
- :dependencies [[org.clojure/clojure "1.4.0"]]
- :plugins [[lein-cljsbuild "0.3.0"]
- [lein-clojars "0.9.1"]]
+ :source-paths ["src/clj" "src/cljs"]
+ :dependencies [[org.clojure/clojure "1.7.0"]
+ [org.clojure/clojurescript "0.0-3308"]]
+ :plugins [[lein-cljsbuild "1.1.0"]]
:hooks [leiningen.cljsbuild]
- :cljsbuild {:builds [{:jar true
- :compiler {:libs ["goog/dom/query.js"]
- :pretty-print true
- :output-dir ".cljsbuild/domina"
- :output-to "public/domina.js"}}
- {:source-paths ["test/cljs"]
- :compiler {:libs ["goog/dom/query.js"]
- :pretty-print true
- :optimizations :none
- :output-dir "public/build_no_opt"
- :output-to "public/test_no_opt.js"}}
- {:source-paths ["test/cljs"]
- :compiler {:libs ["goog/dom/query.js"]
- :optimizations :whitespace
- :pretty-print true
- :output-dir ".cljsbuild/whitespace"
- :output-to "public/test_whitespace.js"}}
- {:source-paths ["test/cljs"]
- :compiler {:libs ["goog/dom/query.js"]
- :optimizations :simple
- :pretty-print true
- :output-dir ".cljsbuild/simple"
- :output-to "public/test_simple.js"}}
- {:source-paths ["test/cljs"]
- :compiler {:libs ["goog/dom/query.js"]
- :optimizations :advanced
- :pretty-print true
- :output-dir ".cljsbuild/advanced"
- :output-to "public/test_advanced.js"}}]}
- :repositories {"sonatype-staging"
- "https://oss.sonatype.org/content/groups/staging/"})
-
-(comment
- (do
- (require '[cljs.repl :as repl])
- (require '[cljs.repl.browser :as browser])
- (def env (browser/repl-env))
- (repl/repl env))
-
- )
+ :cljsbuild {:builds {:useless
+ {:source-paths ["src/cljs"]}}}
+ :clean-targets ^{:protect false} ["dev-resources/public/js" :target-path])
diff --git a/public/test_advanced.html b/public/test_advanced.html
deleted file mode 100644
index 623ce24..0000000
--- a/public/test_advanced.html
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
- Domina Test Page (advanced optimizations)
-
-
-
-
-
-
-
-
diff --git a/public/test_ie.html b/public/test_ie.html
deleted file mode 100644
index 47cca56..0000000
--- a/public/test_ie.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
- Domina Test Page (IE tests)
-
-
-
-
-
-
-
diff --git a/public/test_no_opt.html b/public/test_no_opt.html
deleted file mode 100644
index 8167ea3..0000000
--- a/public/test_no_opt.html
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
- Domina Test Page (no optimizations)
-
-
-
-
-
-
-
-
-
-
diff --git a/public/test_simple.html b/public/test_simple.html
deleted file mode 100644
index 160ac83..0000000
--- a/public/test_simple.html
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
- Domina Test Page (simple optimizations)
-
-
-
-
-
-
-
-
diff --git a/public/test_whitespace.html b/public/test_whitespace.html
deleted file mode 100644
index effbd85..0000000
--- a/public/test_whitespace.html
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
- Domina Test Page (whitespace optimizations)
-
-
-
-
-
-
-
-
diff --git a/public/tests.css b/public/tests.css
deleted file mode 100644
index 9999483..0000000
--- a/public/tests.css
+++ /dev/null
@@ -1,44 +0,0 @@
-#test-summary {
- font-size: 1.5em;
- font-weight: bold;
- text-align: center;
-}
-
-#test-summary.failed {
- color: darkred;
-}
-
-#test-summary.passed {
- color: darkgreen;
-}
-
-#test-summary.passed {
- color: darkgreen;
-}
-
-.test-result {
- margin: 0.5em;
- padding: 0.5em;
- border: 1px solid black;
- border-radius: 7px;
-}
-
-.test-result.passed {
- background-color: lightgreen;
- color: darkgreen;
- border-color: darkgreen;
-}
-
-.test-result.failed {
- background-color: pink;
- color: darkred;
- border-color: darkred;
-}
-
-.message {
- background-color: white;
- border: 1px solid;
- border-radius: 7px;
- padding: 0.5em;
- margin-top: 0.5em;
-}
\ No newline at end of file
diff --git a/public/xpath.js b/public/xpath.js
deleted file mode 100644
index 7e8073a..0000000
--- a/public/xpath.js
+++ /dev/null
@@ -1,288 +0,0 @@
-(function(){var ca=void(0);var da={targetFrame:ca,exportInstaller:false,useNative:true,useInnerText:true};var ea;if(window.jsxpath){ea=window.jsxpath;}
-else{var fa=document.getElementsByTagName('script');var ga=fa[fa.length-1];var ha=ga.src;ea={};var ia=ha.match(/\?(.*)$/);if(ia){var ja=ia[1].split('&');for(var i=0,l=ja.length;i=0){this.opera=true;}
-else if(ua.indexOf("Netscape")>=0){this.netscape=true;}
-else if(ua.indexOf("Mozilla/")==0){this.mozilla=true;}
-else{this.unknown=true;}
-if(ua.indexOf("Gecko/")>=0){this.gecko=true;}
-if(ua.indexOf("Win")>=0){this.windows=true;}
-else if(ua.indexOf("Mac")>=0){this.mac=true;}
-else if(ua.indexOf("Linux")>=0){this.linux=true;}
-else if(ua.indexOf("BSD")>=0){this.bsd=true;}
-else if(ua.indexOf("SunOS")>=0){this.sunos=true;}}
-else{ /*@cc_on @if(@_jscript)function jscriptVersion(){switch(@_jscript_version){case 3.0:return "4.0";case 5.0:return "5.0";case 5.1:return "5.01";case 5.5:return "5.5";case 5.6:if("XMLHttpRequest" in window)return "7.0";return "6.0";case 5.7:return "7.0";default:return true;}}
-if(@_win16||@_win32||@_win64){this.windows=true;this.trident=jscriptVersion();}
-else if(@_mac||navigator.platform.indexOf("Mac")>=0){this.mac=true;this.tasman=jscriptVersion();}
-if(/MSIE (\d+\.\d+)b?;/.test(ua)){this.ie=RegExp.$1;this['ie'+RegExp.$1.charAt(0)]=true;}@else @*/
-if(/AppleWebKit\/(\d+(?:\.\d+)*)/.test(ua)){this.applewebkit=RegExp.$1;if(RegExp.$1.charAt(0)==4){this.applewebkit2=true;}
-else{this.applewebkit3=true;}}
-else if(typeof Components=="object"&&(/Gecko\/(\d{8})/.test(ua)||navigator.product=="Gecko"&&/^(\d{8})$/.test(navigator.productSub))){this.gecko=RegExp.$1;}/*@end @*/
-if(typeof(opera)=="object"&&typeof(opera.version)=="function"){this.opera=opera.version();this['opera'+this.opera[0]+this.opera[2]]=true;}
-else if(typeof opera=="object"&&(/Opera[\/ ](\d+\.\d+)/.test(ua))){this.opera=RegExp.$1;}
-else if(this.ie){}
-else if(/Safari\/(\d+(?:\.\d+)*)/.test(ua)){this.safari=RegExp.$1;}
-else if(/NetFront\/(\d+(?:\.\d+)*)/.test(ua)){this.netfront=RegExp.$1;}
-else if(/Konqueror\/(\d+(?:\.\d+)*)/.test(ua)){this.konqueror=RegExp.$1;}
-else if(ua.indexOf("(compatible;")<0&&(/^Mozilla\/(\d+\.\d+)/.test(ua))){this.mozilla=RegExp.$1;if(/\([^(]*rv:(\d+(?:\.\d+)*).*?\)/.test(ua))this.mozillarv=RegExp.$1;if(/Firefox\/(\d+(?:\.\d+)*)/.test(ua)){this.firefox=RegExp.$1;}
-else if(/Netscape\d?\/(\d+(?:\.\d+)*)/.test(ua)){this.netscape=RegExp.$1;}}
-else{this.unknown=true;}
-if(ua.indexOf("Win 9x 4.90")>=0){this.windows="ME";}
-else if(/Win(?:dows)? ?(NT ?(\d+\.\d+)?|\d+|ME|Vista|XP)/.test(ua)){this.windows=RegExp.$1;if(RegExp.$2){this.winnt=RegExp.$2;}
-else switch(RegExp.$1){case "2000":this.winnt="5.0";break;case "XP":this.winnt="5.1";break;case "Vista":this.winnt="6.0";break;}}
-else if(ua.indexOf("Mac")>=0){this.mac=true;}
-else if(ua.indexOf("Linux")>=0){this.linux=true;}
-else if(/(\w*BSD)/.test(ua)){this.bsd=RegExp.$1;}
-else if(ua.indexOf("SunOS")>=0){this.sunos=true;}}};var Ea=function(Fa){var Ga=Ea.prototype;var Ha=Fa.match(Ga.regs.token);for(var i=0,l=Ha.length;i]=|(?![0-9-])[\w-]+:\*|\s+|./g,strip:/^\s/};Ea.prototype.peek=function(i){return this[this.index+(i||0)];};Ea.prototype.next=function(){return this[this.index++];};Ea.prototype.back=function(){this.index--;};Ea.prototype.empty=function(){return this.length<=this.index;};var Ia=function(Ja,Ka,La){this.node=Ja;this.position=Ka||1;this.last=La||1;};var Ma=function(){};Ma.prototype.number=function(Na){var Oa=this.evaluate(Na);if(Oa.isNodeSet)return Oa.number();return+Oa;};Ma.prototype.string=function(Pa){var Qa=this.evaluate(Pa);if(Qa.isNodeSet)return Qa.string();return ''+Qa;};Ma.prototype.bool=function(Ra){var Sa=this.evaluate(Ra);if(Sa.isNodeSet)return Sa.bool();return!!Sa;};var Ta=function(){};Ta.parsePredicates=function(Ua,Va){while(Ua.peek()=='['){Ua.next();if(Ua.empty()){throw Error('missing predicate expr');}
-var Wa=oa.parse(Ua);Va.predicate(Wa);if(Ua.empty()){throw Error('unclosed predicate expr');}
-if(Ua.next()!=']'){Ua.back();throw Error('bad token: '+Ua.next());}}};Ta.prototype=new Ma();Ta.prototype.evaluatePredicates=function(Xa,Ya){var Za,predicate,nodes,node,Xa,position,reverse;reverse=this.reverse;Za=this.predicates;Xa.sort();for(var i=Ya||0,l0=Za.length;i=l1;j--){Xa.del($a[j]);}}
-return Xa;};if(!window.BinaryExpr&&window.defaultConfig)window.BinaryExpr=null;oa=function(op,bb,cb,db){this.op=op;this.left=bb;this.right=cb;this.datatype=oa.ops[op][2];this.needContextPosition=bb.needContextPosition||cb.needContextPosition;this.needContextNode=bb.needContextNode||cb.needContextNode;if(this.op=='='){if(!cb.needContextNode&&!cb.needContextPosition&&cb.datatype!='nodeset'&&cb.datatype!='void'&&bb.quickAttr){this.quickAttr=true;this.attrName=bb.attrName;this.attrValueExpr=cb;}
-else if(!bb.needContextNode&&!bb.needContextPosition&&bb.datatype!='nodeset'&&bb.datatype!='void'&&cb.quickAttr){this.quickAttr=true;this.attrName=cb.attrName;this.attrValueExpr=bb;}}};oa.compare=function(op,eb,fb,gb,hb){var ib,lnodes,rnodes,nodes,nodeset,primitive;fb=fb.evaluate(hb);gb=gb.evaluate(hb);if(fb.isNodeSet&&gb.isNodeSet){lnodes=fb.list();rnodes=gb.list();for(var i=0,l0=lnodes.length;i':[4,function(Bb,Cb,Db){return oa.compare('>',function(a,b){return a>b},Bb,Cb,Db);},'boolean'],'<=':[4,function(Eb,Fb,Gb){return oa.compare('<=',function(a,b){return a<=b},Eb,Fb,Gb);},'boolean'],'>=':[4,function(Hb,Ib,Jb){return oa.compare('>=',function(a,b){return a>=b},Hb,Ib,Jb);},'boolean'],'=':[3,function(Kb,Lb,Mb){return oa.compare('=',function(a,b){return a==b},Kb,Lb,Mb);},'boolean'],'!=':[3,function(Nb,Ob,Pb){return oa.compare('!=',function(a,b){return a!=b},Nb,Ob,Pb);},'boolean'],'and':[2,function(Qb,Rb,Sb){return Qb.bool(Sb)&&Rb.bool(Sb);},'boolean'],'or':[1,function(Tb,Ub,Vb){return Tb.bool(Vb)||Ub.bool(Vb);},'boolean']};oa.parse=function(Wb){var op,precedence,info,expr,stack=[],index=Wb.index;while(true){if(Wb.empty()){throw Error('missing right expression');}
-expr=Aa.parse(Wb);op=Wb.next();if(!op){break;}
-info=this.ops[op];precedence=info&&info[0];if(!precedence){Wb.back();break;}
-while(stack.length&&precedence<=this.ops[stack[stack.length-1]][0]){expr=new oa(stack.pop(),stack.pop(),expr);}
-stack.push(expr,op);}
-while(stack.length){expr=new oa(stack.pop(),stack.pop(),expr);}
-return expr;};oa.prototype=new Ma();oa.prototype.evaluate=function(Xb){return oa.ops[this.op][1](this.left,this.right,Xb);};oa.prototype.show=function(Yb){Yb=Yb||'';var t='';t+=Yb+'binary: '+this.op+'\n';Yb+=' ';t+=this.left.show(Yb);t+=this.right.show(Yb);return t;};if(!window.UnaryExpr&&window.defaultConfig)window.UnaryExpr=null;Aa=function(op,Zb){this.op=op;this.expr=Zb;this.needContextPosition=Zb.needContextPosition;this.needContextNode=Zb.needContextNode;};Aa.ops={'-':1};Aa.parse=function($b){var ac;if(this.ops[$b.peek()])return new Aa($b.next(),Aa.parse($b));else return Ba.parse($b);};Aa.prototype=new Ma();Aa.prototype.datatype='number';Aa.prototype.evaluate=function(bc){return-this.expr.number(bc);};Aa.prototype.show=function(cc){cc=cc||'';var t='';t+=cc+'unary: '+this.op+'\n';cc+=' ';t+=this.expr.show(cc);return t;};if(!window.UnionExpr&&window.defaultConfig)window.UnionExpr=null;Ba=function(){this.paths=[];};Ba.ops={'|':1};Ba.parse=function(dc){var ec,expr;expr=ya.parse(dc);if(!this.ops[dc.peek()])return expr;ec=new Ba();ec.path(expr);while(true){if(!this.ops[dc.next()])break;if(dc.empty()){throw Error('missing next union location path');}
-ec.path(ya.parse(dc));}
-dc.back();return ec;};Ba.prototype=new Ma();Ba.prototype.datatype='nodeset';Ba.prototype.evaluate=function(fc){var gc=this.paths;var hc=new ta();for(var i=0,l=gc.length;ideep2){while(deep1--!=deep2)gf=gf.parentNode;if(gf==node2)return 1;}
-else if(deep2>deep1){while(deep2--!=deep1)node2=node2.parentNode;if(gf==node2)return -1;}
-while((ancestor1=gf.parentNode)!=(ancestor2=node2.parentNode)){gf=ancestor1;node2=ancestor2;}
-while(gf=gf.nextSibling)if(gf==node2)return -1;return 1;}});}}; /*@cc_on @if(@_jscript)ta.prototype.sourceOffset=1;ta.prototype.subOffset=2;ta.prototype.createWrapper=function(hf){var jf,child,attributes,attributesLength,sourceIndex,subIndex,attributeName;sourceIndex=hf.sourceIndex;if(typeof sourceIndex!='number'){type=hf.nodeType;switch(type){case 2:jf=hf.parentNode;sourceIndex=hf.parentSourceIndex;subIndex=-1;attributeName=hf.nodeName;break;case 9:subIndex=-2;sourceIndex=-1;break;default:child=hf;subIndex=0;do{subIndex++;sourceIndex=child.sourceIndex;if(sourceIndex){jf=child;child=child.lastChild;if(!child){child=jf;break;}
-subIndex++;}}
-while(child=child.previousSibling);if(!sourceIndex){sourceIndex=hf.parentNode.sourceIndex;}
-break;}}
-else{subIndex=-2;}
-sourceIndex+=this.sourceOffset;subIndex+=this.subOffset;return new Ue(hf,sourceIndex,subIndex,attributeName);};ta.prototype.reserveDelBySourceIndexAndSubIndex=function(kf,lf,mf,nf){var of=this.createIdIndexMap();var pf;if((of=of[kf])&&(pf=of[lf])){if(nf&&(this.length-mf-1)>pf||!nf&&mfuf||!sf&&rf=0x10000||subIndex>=0x10000){this.shortcut=false;}
-if(this._first||this.nodes.length==0){Pf=this._first;firstSourceIndex=this._firstSourceIndex;firstSubIndex=this._firstSubIndex;if(!Pf||firstSourceIndex>sourceIndex||(firstSourceIndex==sourceIndex&&firstSubIndex>subIndex)){this._first=Nf;this._firstSourceIndex=sourceIndex;this._firstSubIndex=subIndex}}@else @*/
-var Qf=this.seen;var id=Ze.get(Nf);if(Qf[id])return true;Qf[id]=true;/*@end @*/
-this.length++;if(Of)this.nodes.unshift(Nf);else this.nodes.push(Nf);};ta.prototype.unshift=function(Rf){if(!this.length){this.length++;this.only=Rf;return}
-if(this.only){var Sf=this.only;delete this.only;this.unshift(Sf);this.length--;} /*@cc_on
-Rf=this.createWrapper(Rf);@*/return this._add(Rf,true);};ta.prototype.push=function(Tf){if(!this.length){this.length++;this.only=Tf;return;}
-if(this.only){var Uf=this.only;delete this.only;this.push(Uf);this.length--;} /*@cc_on
-Tf=this.createWrapper(Tf);@*/return this._add(Tf);};ta.prototype.first=function(){if(this.only)return this.only; /*@cc_on
-if(this._first)return this._first.node;if(this.nodes.length>1)this.sort();var Vf=this.nodes[0];return Vf?Vf.node:ca;@*/if(this.nodes.length>1)this.sort();return this.nodes[0];};ta.prototype.list=function(){if(this.only)return[this.only];this.sort(); /*@cc_on
-var i,l,Mf,results;Mf=this.nodes;results=[];for(i=0,l=Mf.length;i (sel ".d1")
(sel "p"))))))))
-(add-test "extended CSS chaining"
+#_(add-test "extended CSS chaining"
#(do (reset)
(append! (sel "body")
"")
@@ -101,28 +101,28 @@
;;;;;; DOM Manipulation Tests
-(add-test "basic xpath selection"
+#_(add-test "basic xpath selection"
#(do (reset)
(standard-fixture)
(assert (= 3 (count (nodes (xpath "//p")))))))
-(add-test "basic xpath selection (single node)"
+#_(add-test "basic xpath selection (single node)"
#(do (reset)
(standard-fixture)
(assert (not (nil? (single-node (xpath "//p")))))))
-(add-test "xpath selection with class specification"
+#_(add-test "xpath selection with class specification"
#(do (reset)
(standard-fixture)
(assert (= 1 (count (nodes (xpath "//div[@class='d1']")))))))
-(add-test "a relative xpath expression"
+#_(add-test "a relative xpath expression"
#(do (reset)
(standard-fixture)
(assert (= 3 (count (nodes (-> (xpath "//body/div[@class='d1']")
(xpath "p"))))))))
-(add-test "extended selection chaining"
+#_(add-test "extended selection chaining"
#(do (reset)
(append! (xpath "//body")
"")
@@ -130,17 +130,17 @@
(xpath "./div")
(xpath "./p")
(xpath "./span"))))))))
-(add-test "advanced xpath"
+#_(add-test "advanced xpath"
#(do (reset)
(standard-fixture)
(assert (= 2 (count (nodes (xpath "//p[following-sibling::p[@class='p3']]")))))))
-(add-test "look up node by id"
+#_(add-test "look up node by id"
#(do (reset)
(standard-fixture)
(assert (= 1 (count (nodes (by-id "id1")))))))
-(add-test "look up node by id with context"
+#_(add-test "look up node by id with context"
#(do (reset)
(append! (sel "body")
"")
@@ -149,58 +149,58 @@
(sel "p")
(sel "span"))))))))
-(add-test "look up nodes by class"
+#_(add-test "look up nodes by class"
#(do (reset)
(standard-fixture)
(assert (= 1 (count (nodes (by-class "p3")))))))
-(add-test "look up multiple nodes by class"
+#_(add-test "look up multiple nodes by class"
#(do (reset)
(append! (xpath "//body") "test1
test2
")
(assert (= 2 (count (nodes (by-class "tc")))))))
-(add-test "child selection"
+#_(add-test "child selection"
#(do (reset)
(standard-fixture)
(assert (= 3 (count (children (xpath "//div[@class='d1']")))))))
-(add-test "clone a single node"
+#_(add-test "clone a single node"
#(do (reset)
(standard-fixture)
(assert (= 1 (count (clone (single-node (xpath "//p"))))))))
-(add-test "clone multiple nodes"
+#_(add-test "clone multiple nodes"
#(do (reset)
(standard-fixture)
(assert (= 3 (count (clone (nodes (xpath "//p"))))))))
-(add-test "append a single child to a single parent"
+#_(add-test "append a single child to a single parent"
#(do (reset)
(append! (xpath "//body") "test
")
(assert (= 1 (count (nodes (xpath "//body/p[@class='appended1']")))))))
-(add-test "append multiple children to a single parent"
+#_(add-test "append multiple children to a single parent"
#(do (reset)
(append! (xpath "//body")
"test2-1
test2-2
")
(assert (= 2 (count (nodes (xpath "//body/p[@class='appended2']")))))))
-(add-test "append a single child to multiple parents"
+#_(add-test "append a single child to multiple parents"
#(do (reset)
(standard-fixture)
(append! (xpath "//body/div/p")
"!! ")
(assert (= 3 (count (nodes (xpath "//div/p/span")))))))
-(add-test "append multiple children to multiple parents"
+#_(add-test "append multiple children to multiple parents"
#(do (reset)
(standard-fixture)
(append! (xpath "//body/div/p")
"some more text")
(assert (= 3 (count (nodes (xpath "//div/p/span[@class='foo']")))))))
-(add-test "prepend a single child to a single parent"
+#_(add-test "prepend a single child to a single parent"
#(do (reset)
(append! (xpath "//body") "2
3
")
(prepend! (xpath "//body") "1
")
@@ -208,13 +208,13 @@
(assert (= "2" (text (xpath "//body/div[2]"))))
(assert (= "3" (text (xpath "//body/div[3]"))))))
-(add-test "prepend a single child to multiple parents"
+#_(add-test "prepend a single child to multiple parents"
#(do (reset)
(append! (xpath "//body") "")
(prepend! (xpath "//body/div") "1
")
(assert (= 2 (count (nodes (xpath "//body/div/p[text()='2']")))))))
-(add-test "Insert a single child to a single parent"
+#_(add-test "Insert a single child to a single parent"
#(do (reset)
(append! (xpath "//body")
"
")
@@ -248,14 +248,14 @@
(assert (= 1 (count (nodes (xpath children
"p[@class='i2']/following-sibling::*"))))))))
-(add-test "destroy a single node"
+#_(add-test "destroy a single node"
#(do (reset)
(append! (xpath "//body") "app1
")
(assert (= 1 (count (nodes (xpath "//body/p[@class='appended1']")))))
(destroy! (xpath "//body/p[@class='appended1']"))
(assert (= 0 (count (nodes (xpath "//body/p[@class='appended1']")))))))
-(add-test "destroy multiple nodes"
+#_(add-test "destroy multiple nodes"
#(do (reset)
(append! (xpath "//body")
"app1
app2
")
@@ -263,7 +263,7 @@
(destroy! (xpath "//body/p[@class='appended2']"))
(assert (= 0 (count (nodes (xpath "//body/p[@class='appended2']")))))))
-(add-test "detach and reattach a single node"
+#_(add-test "detach and reattach a single node"
#(do (reset)
(standard-fixture)
(let [n (detach! (xpath "//p[@class='p3']"))]
@@ -271,7 +271,7 @@
(append! (xpath "//div[@class='d1']") n)
(assert (= 1 (count (nodes (xpath "//p[@class='p3']"))))))))
-(add-test "detach and reattach multiple nodes"
+#_(add-test "detach and reattach multiple nodes"
#(do (reset)
(standard-fixture)
(let [n (detach! (xpath "//div[@class='d1']/p"))]
@@ -279,7 +279,7 @@
(append! (xpath "//div[@class='d1']") n)
(assert (= 3 (count (nodes (xpath "//div[@class='d1']/p"))))))))
-(add-test "detach child nodes"
+#_(add-test "detach child nodes"
#(do (reset)
(standard-fixture)
(let [parent (xpath "//div[@class='d1']")
@@ -287,27 +287,27 @@
(assert (= 0 (count (nodes (xpath "//div[@class='d1']/p")))))
(assert (= 3 (count detached-children))))))
-(add-test "clear a node's contents"
+#_(add-test "clear a node's contents"
#(do (reset)
(standard-fixture)
(destroy-children! (xpath "//div[@class='d1']"))
(assert (= 1 (count (nodes (xpath "//div[@class='d1']")))))
(assert (= 0 (count (nodes (xpath "//div[@class='d1']/*")))))))
-(add-test "insert-before! with a single reference and single new node"
+#_(add-test "insert-before! with a single reference and single new node"
#(do (reset)
(append! (xpath "//body") "Some content
")
(insert-before! (nodes (by-id "ref")) "before
")
(assert (= 1 (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before']")))))))
-(add-test "insert-before! with a single reference and multiple new nodes"
+#_(add-test "insert-before! with a single reference and multiple new nodes"
#(do (reset)
(append! (xpath "//body") "Some content
")
(insert-before! (nodes (by-id "ref")) "before1
before2
")
(assert (= 1 (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before2' and position()=1]")))))
(assert (= 1 (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before1' and position()=2]")))))))
-(add-test "insert-before! with multiple reference nodes and a single new node"
+#_(add-test "insert-before! with multiple reference nodes and a single new node"
#(do (reset)
(append! (xpath "//body") "content1
")
(append! (xpath "//body") "content2
")
@@ -316,20 +316,20 @@
(assert (= 1 (count (nodes (xpath "//div[@id='ref1']/preceding-sibling::p")))))
(assert (= 2 (count (nodes (xpath "//div[@id='ref2']/preceding-sibling::p")))))))
-(add-test "insert-after! with a single reference and single new node"
+#_(add-test "insert-after! with a single reference and single new node"
#(do (reset)
(append! (xpath "//body") "Some content
")
(insert-after! (nodes (by-id "ref")) "after
")
(assert (= 1 (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after']")))))))
-(add-test "insert-after! with a single reference and multiple new nodes"
+#_(add-test "insert-after! with a single reference and multiple new nodes"
#(do (reset)
(append! (xpath "//body") "Some content
")
(insert-after! (nodes (by-id "ref")) "after1
after2
")
(assert (= 1 (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after1' and position()=1]")))))
(assert (= 1 (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after2' and position()=2]")))))))
-(add-test "insert-after! with multiple reference nodes and a single new node"
+#_(add-test "insert-after! with multiple reference nodes and a single new node"
#(do (reset)
(append! (xpath "//body") "content1
")
(append! (xpath "//body") "content2
")
@@ -338,21 +338,21 @@
(assert (= 2 (count (nodes (xpath "//div[@id='ref1']/following-sibling::p")))))
(assert (= 1 (count (nodes (xpath "//div[@id='ref2']/following-sibling::p")))))))
-(add-test "swap-content! with a single reference node and a single new node"
+#_(add-test "swap-content! with a single reference node and a single new node"
#(do (reset)
(append! (xpath "//body") "")
(swap-content! (xpath "//p[@id='before']") "fixed
")
(assert (= 0 (count (nodes (xpath "//p[@id='before']")))))
(assert (= 1 (count (nodes (xpath "//p[@id='after']")))))))
-(add-test "swap-content! with a single reference node and multiple new nodes"
+#_(add-test "swap-content! with a single reference node and multiple new nodes"
#(do (reset)
(append! (xpath "//body") "")
(swap-content! (xpath "//p[@id='before']") "fixed1
fixed2
")
(assert (= 0 (count (nodes (xpath "//p[@id='before']")))))
(assert (= 2 (count (nodes (xpath "//p[@class='after']")))))))
-(add-test "swap-content! with multiple reference nodes and multiple new nodes"
+#_(add-test "swap-content! with multiple reference nodes and multiple new nodes"
#(do (reset)
(append! (xpath "//body") "")
(append! (xpath "//body") "")
diff --git a/test/cljs/domina/css_edge_test.cljs b/test/cljs/domina/css_edge_test.cljs
new file mode 100644
index 0000000..5388c09
--- /dev/null
+++ b/test/cljs/domina/css_edge_test.cljs
@@ -0,0 +1,20 @@
+(ns domina.css-edge-test
+ (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)]
+ [domina.macros :as dm])
+ (:require [cemerick.cljs.test :as t]
+ [domina.core :as dom :refer (nodes)]
+ [domina.css :as css :refer (sel)]
+ [domina.fixtures :as fix :refer (base-fixture)]))
+
+(use-fixtures :each base-fixture)
+
+;;; sel
+(deftest sel-test
+ (testing "Unit Testing for (sel css-expr)\n"
+ (testing "Edge Cases\n"
+ (are [expected actual] (= expected actual)
+ false (nil? (sel nil))
+ false (nil? (sel ""))
+ false (nil? (sel " "))
+ 0 (count (nodes (sel ".not-existent-css-class")))
+ 0 (count (nodes (sel "#not-existent-css-id")))))))
diff --git a/test/cljs/domina/css_standard_test.cljs b/test/cljs/domina/css_standard_test.cljs
new file mode 100644
index 0000000..1789026
--- /dev/null
+++ b/test/cljs/domina/css_standard_test.cljs
@@ -0,0 +1,31 @@
+(ns domina.css-standard-test
+ (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)]
+ [domina.macros :as dm]
+ [hiccups.core :as hm])
+ (:require [cemerick.cljs.test :as t]
+ [domina.core :as dom :refer (nodes append!)]
+ [domina.css :as css :refer (sel)]
+ [domina.fixtures :as fix :refer (base-fixture)]
+ [hiccups.runtime :as hrt]))
+
+(use-fixtures :each base-fixture)
+
+;;; sel
+(deftest sel-test
+ (testing "Unit Testing for (sel css-expr)\n"
+ (testing "Standard Cases\n"
+ (are [expected actual] (= expected actual)
+ 3 (count (nodes (sel "p")))
+ 1 (count (nodes (sel ".d1")))
+ 1 (count (nodes (sel "#id1")))
+ 3 (count (nodes (-> (sel ".d1")
+ (sel "p"))))
+ 3 (count (nodes (sel ".d1 > p")))
+ 2 (do (append! (sel "body")
+ (hm/html [:div
+ [:p [:span "some text"]]
+ [:p [:span "more text"]]]))
+ (count (nodes (-> (sel "body")
+ (sel "div")
+ (sel "p")
+ (sel "span")))))))))
diff --git a/test/cljs/domina/fixtures.cljs b/test/cljs/domina/fixtures.cljs
new file mode 100644
index 0000000..bb91a7a
--- /dev/null
+++ b/test/cljs/domina/fixtures.cljs
@@ -0,0 +1,22 @@
+(ns domina.fixtures
+ (:require-macros [domina.macros :as dm]
+ [hiccups.core :as hm])
+ (:require [domina.core :as dom :refer (append! destroy!)]
+ [hiccups.runtime :as hrt]
+ [domina.xpath :as css :refer (xpath)]
+ [domina.events :as de :refer (unlisten!)]))
+
+(defn- initialize []
+ (append! (xpath "//body")
+ (hm/html [:div.d1
+ [:p.p1 "P1"]
+ [:p.p2 "P2"]
+ [:p#id1.p3 "P3"]])))
+(defn- reset[]
+ (destroy! (xpath "//body/*"))
+ (unlisten! (xpath "//*")))
+
+(defn base-fixture [f]
+ (initialize)
+ (f)
+ (reset))
diff --git a/test/cljs/domina/xpath_standard_test.cljs b/test/cljs/domina/xpath_standard_test.cljs
new file mode 100644
index 0000000..e1a4e53
--- /dev/null
+++ b/test/cljs/domina/xpath_standard_test.cljs
@@ -0,0 +1,32 @@
+(ns domina.xpath-standard-test
+ (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)]
+ [domina.macros :as dm]
+ [hiccups.core :as hm])
+ (:require [cemerick.cljs.test :as t]
+ [domina.core :as dom :refer (nodes single-node append!)]
+ [domina.xpath :as css :refer (xpath)]
+ [domina.fixtures :as fix :refer (base-fixture)]
+ [hiccups.runtime :as hrt]))
+
+(use-fixtures :each base-fixture)
+
+;;; xpath
+(deftest xpath-test
+ (testing "Unit Testing for (xpath xpath-expr)\n"
+ (testing "Standard Cases\n"
+ (are [expected actual] (= expected actual)
+ 3 (count (nodes (xpath "//p")))
+ false (nil? (single-node (xpath "//p")))
+ 1 (count (nodes (xpath "//div[@class='d1']")))
+ 3 (count (nodes (-> (xpath "//body/div[@class='d1']")
+ (xpath "p"))))
+ 2 (do
+ (append! (xpath "//body")
+ (hm/html [:div
+ [:p [:span "some text"]]
+ [:p [:span "more text"]]]))
+ (count (nodes (-> (xpath "//body")
+ (xpath "./div")
+ (xpath "./p")
+ (xpath "./span")))))
+ 2 (count (nodes (xpath "//p[following-sibling::p[@class='p3']]")))))))
diff --git a/test/cljs/domina_edge_test.cljs b/test/cljs/domina_edge_test.cljs
new file mode 100644
index 0000000..2b1b076
--- /dev/null
+++ b/test/cljs/domina_edge_test.cljs
@@ -0,0 +1,247 @@
+(ns domina-edge-test.test
+ (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)]
+ [domina.macros :as dm])
+ (:require [cemerick.cljs.test :as t]
+ [domina.core :as dom :refer (nodes
+ single-node
+ by-class
+ by-id
+ append!
+ prepend!
+ clone
+ ancestor?
+ common-ancestor
+ children
+ detach!
+ destroy!
+ destroy-children!
+ has-class?
+ value)]
+ [domina.xpath :as xp :refer (xpath)]
+ [domina.fixtures :as fix :refer (base-fixture)]))
+
+(use-fixtures :each base-fixture)
+
+;;; nodes
+(deftest nodes-test
+ (testing "Unit Testing for (nodes content)\n"
+ (testing "Edge Cases\n"
+ (testing "(nodes content)"
+ (are [expected actual] (= expected actual)
+ () (nodes nil)
+ false (nil? (nodes ""))
+ false (nil? (nodes " "))
+ false (nil? (nodes (by-id "not-an-existent-id")))
+ nil (nodes ())
+ nil (nodes [])
+ nil (nodes {})
+ nil (nodes #{}))))))
+
+;;; single-node
+(deftest single-node-test
+ (testing "Unit Testing for (single-node node)\n"
+ (testing "Edge Cases\n"
+ (testing "(single-node node)"
+ (are [expected actual] (= expected actual)
+ nil (single-node nil)
+ false (nil? (single-node ""))
+ false (nil? (single-node " "))
+ true (nil? (single-node (by-class "not-a-class")))
+ true (nil? (single-node (by-id "not-an-id")))
+ nil (single-node ())
+ nil (single-node [])
+ nil (single-node {})
+ nil (single-node #{}))))))
+
+;;; by-id
+(deftest by-id-test
+ (testing "Unit Testing for (by-id id)\n"
+ (testing "Edge Cases\n"
+ (testing "(by-id s)"
+ (are [expected actual] (= expected actual)
+ "Error" (try
+ (by-id nil)
+ (catch js/Error e
+ "Error"))
+ nil (by-id "")
+ nil (by-id "not-existent-id")
+ nil (by-id " "))))))
+
+;;; by-class
+(deftest by-class-test
+ (testing "Unit Testing for (by-class css-class)\n"
+ (testing "Edge Cases\n"
+ (testing "(by-class css-class)"
+ (are [expected actual] (= expected actual)
+ "Error" (try
+ (by-class nil)
+ (catch js/Error e
+ "Error"))
+ ;nil (by-class "")
+ ;nil (by-class " ")
+ nil (by-class "not-existent-class"))))))
+
+;;; append!
+(deftest append!-test
+ (testing "Unit Testing for (append! parent-content child-content)\n"
+ (testing "Edge Cases\n"
+ (testing "(append! single-parent single-child)"
+ (are [expected actual] (= expected actual)
+ nil (append! nil nil)
+ () (children (append! (by-id "id1") nil))
+ () (children (append! (by-id "id1") ""))
+ () (children (append! (by-id "id1") " "))
+ nil (append! nil "
")))
+ (testing "(append! multiple-parent child-content)"
+ (are [expected actual] (= expected actual)
+ () (children (append! (by-class "p1") nil))
+ () (children (append! (by-class "p1") ""))
+ () (children (append! (by-class "p1") " "))
+ () (children (append! (by-class "p1") ()))
+ () (children (append! (by-class "p1") []))
+ () (children (append! (by-class "p1") {}))
+ () (children (append! (by-class "p1") #{})))))))
+
+;;; detach
+(deftest detach!-test
+ (testing "Unit Testing for (detach! content)\n"
+ (testing "Edge Cases\n"
+ (testing "(detach! content)"
+ (are [expected actual] (= expected actual)
+ () (detach! nil)
+ '(nil) (detach! "")
+ '(nil) (detach! " ")
+ () (detach! ())
+ () (detach! [])
+ () (detach! {})
+ () (detach! #{})
+ () (detach! (by-class "not-a-class"))
+ () (detach! (by-id "not-an-id")))))))
+
+;;; children
+(deftest children-test
+ (testing "Unit Testing for (children content)\n"
+ (testing "Edge Cases\n"
+ (testing "(children content)"
+ (are [expected actual] (= expected actual)
+ () (children nil)
+ () (children "")
+ () (children " ")
+ () (children ())
+ () (children [])
+ () (children {})
+ () (children #{})
+ () (children "not-existent-parent")
+ () (children "not existent parent"))))))
+
+;;; destroy
+(deftest destroy!-test
+ (testing "Unit Testing for (destroy! content)\n"
+ (testing "Edge Cases\n"
+ (testing "(destroy! content)"
+ (are [expected actual] (= expected actual)
+ nil (destroy! nil)
+ nil (destroy! "")
+ nil (destroy! " ")
+ nil (destroy! "not-a-content")
+ nil (destroy! "not a content")
+ nil (destroy! ())
+ nil (destroy! [])
+ nil (destroy! {})
+ nil (destroy! #{}))))))
+
+;;; common-ancestor
+(deftest common-ancestor-test
+ (testing "Unit Testing for (common-ancestor &contents)\n"
+ (testing "Edge Cases\n"
+ (testing "(common-ancestor node-a)"
+ (are [expected actual] (= expected actual)
+ nil (common-ancestor nil)))
+ (testing "(common-ancestor node-a node-b)"
+ (are [expected actual] (= expected actual)
+ nil (common-ancestor nil nil)
+ nil (common-ancestor nil (by-id "id1"))
+ nil (common-ancestor (by-id "id1") nil)))
+ (testing "(common-ancestor node-a node-b node-c)"
+ (are [expected actual] (= expected actual)
+ nil (common-ancestor nil nil nil)
+ nil (common-ancestor nil (by-id "id1") nil)
+ nil (common-ancestor nil nil (by-id "id1"))
+ nil (common-ancestor (by-id "id1") nil nil))))))
+
+;;; ancestor?
+(deftest ancestor?-test
+ (testing "Unit Testing for (ancestor? ancestor-node descendant-node)\n"
+ (testing "Edge Cases\n"
+ (testing "(ancestor? ancestor descendant)"
+ (are [expected actual] (= expected actual)
+ true (ancestor? nil nil)
+ true (ancestor? nil (by-id "id1"))
+ false (ancestor? (by-id "id1") nil)
+
+ true (ancestor? () ())
+ true (ancestor? nil ())
+ true (ancestor? () nil)
+
+ true (ancestor? [] [])
+ true (ancestor? nil [])
+ true (ancestor? [] nil)
+
+ true (ancestor? {} {})
+ true (ancestor? nil {})
+ true (ancestor? {} nil)
+
+ true (ancestor? #{} #{})
+ true (ancestor? nil #{})
+ true (ancestor? #{} nil))))))
+
+;;; clone
+(deftest clone-test
+ (testing "Unit Testing for (clone node)\n"
+ (testing "Edge Cases\n"
+ (testing "(clone node)"
+ (are [expected actual] (= expected actual)
+ () (clone nil)
+ () (clone ())
+ () (clone [])
+ () (clone {})
+ () (clone #{}))))))
+
+;;; has-class?
+(deftest has-class?-test
+ (testing "Unit Testing for (has-class? content class)\n"
+ (testing "Edge Cases\n"
+ (testing "(has-class? content class)"
+ (are [expected actual] (= expected actual)
+ "Error" (try
+ (has-class? nil nil)
+ (catch js/Error e
+ "Error"))
+ "Error" (try
+ (has-class? nil "p1")
+ (catch js/Error e
+ "Error"))
+ false (has-class? (by-id "id1") nil))))))
+
+;;; value
+(deftest value-test
+ (testing "Unit Testing for (value content)\n"
+ (testing "Edge Cases\n"
+ (testing "(value single-node)"
+ (are [expected actual] (= expected actual)
+ "Error" (try
+ (value (by-id nil))
+ (catch js/Error e
+ "Error"))
+ "Error" (try
+ (value (by-id ""))
+ (catch js/Error e
+ "Error"))
+ "Error" (try
+ (value (by-id " "))
+ (catch js/Error e
+ "Error"))
+ "Error" (try
+ (value (by-id "not-existent-id"))
+ (catch js/Error e
+ "Error")))))))
diff --git a/test/cljs/domina_standard_test.cljs b/test/cljs/domina_standard_test.cljs
new file mode 100644
index 0000000..e83c1fd
--- /dev/null
+++ b/test/cljs/domina_standard_test.cljs
@@ -0,0 +1,310 @@
+(ns domina-standard-test.test
+ (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)]
+ [domina.macros :as dm]
+ [hiccups.core :as hm])
+ (:require [cemerick.cljs.test :as t]
+ [domina.core :as dom :refer (nodes
+ single-node
+ by-id
+ by-class
+ append!
+ clone
+ detach!
+ destroy!
+ destroy-children!
+ children
+ insert-before!
+ insert-after!
+ prepend!
+ insert!
+ swap-content!
+ text)]
+ [domina.fixtures :as fix :refer (base-fixture)]
+ [domina.xpath :as xp :refer (xpath)]
+ [hiccups.runtime :as hrt]))
+
+(use-fixtures :each base-fixture)
+
+;;; nodes
+(deftest nodes-test
+ (testing "Unit Testing for (nodes content)\n"
+ (testing "Standard Cases\n"
+ (testing "(nodes content)"
+ (are [expected actual] (= expected actual)
+ 1 (count (nodes (xpath "//body")))
+ 1 (count (nodes (xpath "//body/div")))
+ 1 (count (nodes (xpath "//div[@class='d1']"))))))))
+
+;;; single-node
+(deftest single-node-test
+ (testing "Unit Testing for (single-node node)\n"
+ (testing "Standard Cases\n"
+ (testing "(single-node node)"
+ (are [expected actual] (= expected actual)
+ false (nil? (single-node (xpath "//p")))
+ false (nil? (single-node (by-class "p1")))
+ false (nil? (single-node (by-id "id1"))))))))
+
+;;; by-id
+(deftest by-id-test
+ (testing "Unit Testing for (by-id id)\n"
+ (testing "Standard Cases\n"
+ (testing "(by-id id)"
+ (are [expected actual] (= expected actual)
+ false (nil? (by-id "id1")))))))
+
+;;; by-class
+(deftest by-class-test
+ (testing "Unit Testing for (by-class css-class)\n"
+ (testing "Standard Cases\n"
+ (testing "(by-class css-class)"
+ (are [expected actual] (= expected actual)
+ 1 (count (by-class "p3"))
+ 2 (do
+ (append! (xpath "//body")
+ (hm/html [:p.tc "test1"]
+ [:p.tc "test2"]))
+ (count (nodes (by-class "tc")))))))))
+
+;;; append!
+(deftest append!-test
+ (testing "Unit Testing for (append! parent-content child-content)\n"
+ (testing "Standard Cases\n"
+ (testing "(append! single-parent single-child)"
+ (are [expected actual] (= expected actual)
+ 1 (do
+ (children (append! (xpath "//body")
+ (hm/html [:p.appended1 "test"])))
+ (count (nodes (xpath "//body/p[@class='appended1']"))))))
+ (testing "Standard Cases\n"
+ (testing "(append! single-parent children)"
+ (are [expected actual] (= expected actual)
+ 2 (do
+ (append! (xpath "//body")
+ (hm/html [:p.appended2 "test2-1"]
+ [:p.appended2 "test2-2"]))
+ (count (nodes (xpath "//body/p[@class='appended2']"))))))
+ (testing "(append! multiple-parent single-child)"
+ (are [expected actual] (= expected actual)
+ 3 (do
+ (append! (xpath "//body/div/p")
+ (hm/html [:span "!!"]))
+ (count (nodes (xpath "//div/p/span"))))))
+ (testing "(append! multiple-parent children)"
+ (are [expected actual] (= expected actual)
+ 3 (do
+ (append! (xpath "//body/div/p")
+ (hm/html ["some " [:span.foo "more"] "text"]))
+ (count (nodes (xpath "//div/p/span[@class='foo']"))))))))))
+
+;;; detach!
+(deftest detach!-test
+ (testing "Unit Testing for (detach! content)\n"
+ (testing "Standard Cases\n"
+ (testing "(detach! single-node)"
+ (are [expected actual] (= expected actual)
+ 0 (do
+ (detach! (xpath "//p[@class='p3']"))
+ (count (nodes (xpath "//p[@class='p3']"))))))
+ (testing "(detach! multiple-nodes)"
+ (are [expected actual] (= expected actual)
+ 0 (do
+ (detach! (xpath "//div[@class='d1']/p"))
+ (count (nodes (xpath "//div[@class='d1']/p"))))
+ 0 (do
+ (detach! (children "//div[@class='d1']"))
+ (count (children "//div[@class='d1']"))))))))
+
+;;; children
+(deftest children-test
+ (testing "Unit Testing for (children content)\n"
+ (testing "Standard Cases\n"
+ (testing "(children content)"
+ (are [expected actual] (= expected actual)
+ 3 (count (children (xpath "//div[@class='d1']"))))))))
+
+;;; clone
+(deftest clone-test
+ (testing "Unit Testing for (clone single-node)\n"
+ (testing "Standard Cases\n"
+ (testing "(clone single-node)"
+ (are [expected actual] (= expected actual)
+ 1 (count (clone (single-node (xpath "//p"))))))
+ (testing "(clone multiple-nodes)"
+ (are [expected actual] (= expected actual)
+ 3 (count (clone (nodes (xpath "//p")))))))))
+
+;;; destroy!
+(deftest destroy!-test
+ (testing "Unit Testing for (destroy! content)\n"
+ (testing "Standard Cases\n"
+ (testing "(destroy! single-node)"
+ (are [expected actual] (= expected actual)
+ 0 (do (append! (xpath "//body")
+ (hm/html [:p.appended1 "app1"]))
+ (destroy! (xpath "//body/p[@class='appended1']"))
+ (count (nodes (xpath "//body/p[@class='appended1']"))))))
+ (testing "(destroy! multiple-nodes)"
+ (are [expected actual] (= expected actual)
+ 0 (do (append! (xpath "//body")
+ (hm/html [:p.appended2 "app1"]
+ [:p.appended2 "app2"]))
+ (destroy! (xpath "//body/p[@class='appended2']"))
+ (count (nodes (xpath "//body/p[@class='appended2']")))))))))
+
+;;; destroy-children!
+(deftest destroy-children!-test
+ (testing "Unit Testing for (destroy-children! content)\n"
+ (testing "Standard Cases\n"
+ (testing "(destroy-children! single-node)"
+ (are [expected actual] (= expected actual)
+ 0 (do
+ (destroy-children! (xpath "//div[@class='d1']"))
+ (count (nodes (xpath "//div[@class='d1']/*")))))))))
+
+;;; insert-before!
+(deftest insert-before!-test
+ (testing "Unit Testing for (insert-before! ref-nodes new-nodes)\n"
+ (testing "Standard Cases\n"
+ (testing "(insert-before! single-ref-node single-node)"
+ (are [expected actual] (= expected actual)
+ 1 (do
+ (append! (xpath "//body")
+ (hm/html [:div#ref "Some Content"]))
+ (insert-before! (nodes (by-id "ref")) "before
")
+ (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before']"))))))
+ (testing "(insert-before! single-ref-node multiple-nodes)"
+ (are [expected actual] (= expected actual)
+ 2 (do (append! (xpath "//body")
+ (hm/html [:div#ref "some content"]))
+ (insert-before! (nodes (by-id "ref"))
+ (hm/html [:p "before1"]
+ [:p "before2"]))
+ (+ (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before2' and position()=1]")))
+ (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before1' and position()=2]"))))))))))
+
+;;; insert-before!
+(deftest insert-before!!-test
+ (testing "Unit Testing for (insert-before! ref-nodes new-nodes)\n"
+ (testing "Standard Cases\n"
+ (testing "(insert-before! multiple-ref-nodes single-node)"
+ (are [expected actual] (= expected actual)
+ 5 (do
+ (append! (xpath "//body") (hm/html [:div#ref1.ref "content1"]))
+ (append! (xpath "//body") (hm/html [:div#ref2.ref "content2"]))
+ (insert-before! (nodes (by-class "ref")) (hm/html [:p "before"]))
+ (+ (count (nodes (xpath "//div[@class='ref']")))
+ (count (nodes (xpath "//div[@id='ref1']/preceding-sibling::p")))
+ (count (nodes (xpath "//div[@id='ref2']/preceding-sibling::p"))))))))))
+
+;;; prepend!
+(deftest prepend!-test
+ (testing "Unit Testing for (prepend! parents children)\n"
+ (testing "Standard Cases\n"
+ (testing "(prepend! single-parent single-child)"
+ (are [expected actual] (= expected actual)
+ "1" (do
+ (append! (xpath "//body") (hm/html [:div "2"] [:div "3"]))
+ (prepend! (xpath "//body") (hm/html [:div "1"]))
+ (text (xpath "//body/div[1]")))))
+ (testing "(prepend! parents single-child)"
+ (are [expected actual] (= expected actual)
+ 2 (do (append! (xpath "//body")
+ (hm/html [:div [:p "2"]]
+ [:div [:p "2"]])
+ #_"")
+ (prepend! (xpath "//body/div")
+ (hm/html [:p "1"])
+ #_"1
")
+ (count (nodes (xpath "//body/div/p[text()='2']")))))))))
+
+(deftest insert!-test
+ (testing "Unit Testing for (insert! parents children)\n"
+ (testing "Standard Cases\n"
+ (testing "(insert! parent child)"
+ (are [expected actual] (= expected actual)
+ 5 (do
+ (append! (xpath "//body")
+ (hm/html [:div.testInserts]))
+ (append! (xpath "//div[@class='testInserts']")
+ (hm/html [:p.i1]))
+ (append! (xpath "//div[@class='testInserts']")
+ (hm/html [:p.i3]))
+ (insert! (xpath "//div[@class='testInserts']")
+ (hm/html [:p.i2]) 1)
+ (+ (count (nodes (xpath "//div[@class='testInserts']/p")))
+ (count (nodes (xpath "//p[@class='i2']/preceding-sibling::*")))
+ (count (nodes (xpath "//p[@class='i2']/following-sibling::*")))))))
+ (testing "(insert! parents single-child)"
+ (are [expected actual] (= expected actual)
+ true false)))))
+
+;;; insert-after!
+(deftest insert-after!-test
+ (testing "Unit Testing for (insert-after! ref-nodes new-nodes)\n"
+ (testing "Standard Cases\n"
+ (testing "(insert-after! single-ref-node single-node)"
+ (are [expected actual] (= expected actual)
+ 1 (do
+ (append! (xpath "//body")
+ (hm/html [:div#ref "Some content"]))
+ (insert-after! (nodes (by-id "ref"))
+ (hm/html [:p "after"]))
+ (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after']"))))))
+ (testing "(insert-after! single-ref-node multiple-nodes)"
+ (are [expected actual] (= expected actual)
+ 2 (do
+ (append! (xpath "//body")
+ (hm/html [:div#ref "Some content"]))
+ (insert-after! (nodes (by-id "ref"))
+ (hm/html [:p "after1"]
+ [:p "after2"]))
+ (+ (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after1' and position()=1]")))
+ (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after2' and position()=2]")))))))
+ (testing "(insert-after! multiple-ref-node multiple-nodes)"
+ (are [expected actual] (= expected actual)
+ 3 (do
+ (append! (xpath "//body")
+ (hm/html [:div#ref1.ref "content1"]))
+ (append! (xpath "//body")
+ (hm/html [:div#ref2.ref "content2"]))
+ (insert-after! (nodes (by-class "ref"))
+ (hm/html [:p "after"]))
+ (+ (count (nodes (xpath "//div[@id='ref1']/following-sibling::p")))
+ (count (nodes (xpath "//div[@id='ref2']/following-sibling::p"))))))))))
+
+;;; swap-content!
+(deftest swap-content!-test
+ (testing "Unit Testing for (swap-content! old-content new-content)\n"
+ (testing "Standard Cases\n"
+ (testing "(swap-content! single-old-node single-new-node)"
+ (are [expected actual] (= expected actual)
+ 1 (do
+ (append! (xpath "//body")
+ (hm/html [:div [:p#before "TYPO"]]))
+ (swap-content! (xpath "//p[@id='before']")
+ (hm/html [:p#after "fixed"]))
+ (+ (count (nodes (xpath "//p[@id='before']")))
+ (count (nodes (xpath "//p[@id='after']")))))))
+ (testing "(swap-content! single-ref-node multiple-new-node)"
+ (are [expected actual] (= expected actual)
+ 2 (do
+ (append! (xpath "//body")
+ (hm/html [:div [:p#before "TYPE"]]))
+ (swap-content! (xpath "//p[@id='before']")
+ (hm/html [:p.after "fixed1"]
+ [:p.after "fixed2"]))
+ (+ (count (nodes (xpath "//p[@id='before']")))
+ (count (nodes (xpath "//p[@class='after']")))))))
+ (testing "(swap-content! multiple-ref-nodes multiple-new-node)"
+ (are [expected actual] (= expected actual)
+ 4 (do
+ (append! (xpath "//body")
+ (hm/html [:div [:p.before1 "TYPO-1"]]))
+ (append! (xpath "//body")
+ (hm/html [:div [:p.before1"TYPO-2"]]))
+ (swap-content! (xpath "//p[@class='before1']")
+ (hm/html [:p.after1 "fixed1"]
+ [:p.after1 "fixed2"]))
+ (+ (count (nodes (xpath "//p[@class='before1']")))
+ (count (nodes (xpath "//p[@class='after1']"))))))))))