summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--checkeol.py1
-rw-r--r--coverage/htmlfiles/coverage_html.js16
-rw-r--r--test/js/index.html68
-rw-r--r--test/js/tests.js48
-rw-r--r--test/qunit/jquery.tmpl.min.js10
5 files changed, 76 insertions, 67 deletions
diff --git a/checkeol.py b/checkeol.py
index 5d18d9e3..cc0cab3b 100644
--- a/checkeol.py
+++ b/checkeol.py
@@ -32,6 +32,7 @@ check_files("coverage", ["*.py", "*.c"])
check_files("coverage/htmlfiles", ["*.html", "*.css", "*.js"])
check_files("test", ["*.py"])
check_files("test", ["*,cover"], trail_white=False)
+check_files("test/js", ["*.js", "*.html"])
check_file("setup.py")
check_files("doc", ["*.rst"])
check_files(".", ["*.txt"])
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js
index 046a6120..84593271 100644
--- a/coverage/htmlfiles/coverage_html.js
+++ b/coverage/htmlfiles/coverage_html.js
@@ -131,6 +131,10 @@ coverage.num_elt = function(n) {
return $("#n" + n);
};
+coverage.code_container = function(n) {
+ return $(".linenos");
+}
+
coverage.set_sel = function(b, e) {
coverage.sel_begin = b;
coverage.sel_end = e;
@@ -147,7 +151,7 @@ coverage.to_first_chunk = function() {
};
coverage.to_next_chunk = function() {
- var c = coverage;
+ var c = coverage;
// Find the start of the next colored chunk.
var probe = c.sel_end;
@@ -170,7 +174,7 @@ coverage.to_next_chunk = function() {
var next_color = color;
while (next_color === color) {
probe++;
- probe_line = c.line_elt(probe);
+ probe_line = c.line_elt(probe);
next_color = probe_line.css("background-color");
}
c.sel_end = probe;
@@ -178,7 +182,7 @@ coverage.to_next_chunk = function() {
};
coverage.to_prev_chunk = function() {
- var c = coverage;
+ var c = coverage;
// Find the end of the prev colored chunk.
var probe = c.sel_begin-1;
@@ -214,7 +218,7 @@ coverage.show_selection = function() {
var c = coverage;
// Highlight the lines in the chunk
- $(".linenos p").removeClass("highlight");
+ c.code_container().find(".highlight").removeClass("highlight");
for (var probe = c.sel_begin; probe > 0 && probe < c.sel_end; probe++) {
c.num_elt(probe).addClass("highlight");
}
@@ -224,8 +228,8 @@ coverage.show_selection = function() {
coverage.scroll_to_selection = function() {
// Scroll the page if the chunk isn't fully visible.
- var top = coverage.line_elt(c.sel_begin);
- var next = coverage.line_elt(c.sel_end);
+ var top = coverage.line_elt(coverage.sel_begin);
+ var next = coverage.line_elt(coverage.sel_end);
if (!top.isOnScreen() || !next.isOnScreen()) {
// Need to move the page.
diff --git a/test/js/index.html b/test/js/index.html
index f89c57af..746dc374 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -4,15 +4,40 @@
<title>Coverage.py Javascript Test Suite</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="../../coverage/htmlfiles/jquery-1.4.3.min.js"></script>
+ <script type='text/javascript' src="../../coverage/htmlfiles/jquery.isonscreen.js"></script>
<script type="text/javascript" src="../../coverage/htmlfiles/coverage_html.js"></script>
<script type="text/javascript" src="../qunit/qunit.js"></script>
+ <script type="text/javascript" src="../qunit/jquery.tmpl.min.js"></script>
<style>
- .red { background-color: red; }
- .white { }
- .blue { background-color: blue; }
+ .r { background-color: red; }
+ .w { }
+ .b { background-color: blue; }
</style>
+ <!-- Templates for the coverage report output -->
+ <script id="fixture-template" type="text/x-jquery-tmpl">
+ <table cellspacing='0' cellpadding='0'>
+ <tr>
+ <td class='linenos' valign='top'>
+ <!-- #lineno-template goes here -->
+ </td>
+ <td class='text' valign='top'>
+ <!-- #text-template goes here -->
+ </td>
+ </tr>
+ </table>
+ </script>
+
+ <script id="lineno-template" type="text/x-jquery-tmpl">
+ <p id='n${number}' class='${klass}'><a href='#n${number}'>${number}</a></p>
+ </script>
+
+ <script id="text-template" type="text/x-jquery-tmpl">
+ <p id='t${number}' class='${klass}'>Hello, world!</p>
+ </script>
+
+ <!-- Pull in the tests -->
<script type="text/javascript" src="tests.js"></script>
</head>
@@ -22,41 +47,6 @@
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
- <div id="qunit-fixture">
-
- <div id='rrwwrr'>
- <p class='t1 red'>red</p>
- <p class='t2 red'>red</p>
- <p class='t3 white'>white</p>
- <p class='t4 white'>white</p>
- <p class='t5 red'>red</p>
- <p class='t6 red'>red</p>
- </div>
-
- <div id='rb'>
- <p class='t1 red'>red</p>
- <p class='t2 blue'>blue</p>
- </div>
-
- <div id='wrrwrrw'>
- <p class='t1 white'>white</p>
- <p class='t2 red'>red</p>
- <p class='t3 red'>red</p>
- <p class='t4 white'>white</p>
- <p class='t5 red'>red</p>
- <p class='t6 red'>red</p>
- <p class='t7 white'>white</p>
- </div>
-
- <div id='rrrbbb'>
- <p class='t1 red'>red</p>
- <p class='t2 red'>red</p>
- <p class='t3 red'>red</p>
- <p class='t4 blue'>blue</p>
- <p class='t5 blue'>blue</p>
- <p class='t6 blue'>blue</p>
- </div>
-
- </div>
+ <div id="qunit-fixture"></div>
</body>
</html>
diff --git a/test/js/tests.js b/test/js/tests.js
index d298cebe..cd4f9d58 100644
--- a/test/js/tests.js
+++ b/test/js/tests.js
@@ -1,53 +1,57 @@
-// To make the code more testable, we monkeypatch some of it.
-$.extend(coverage, {
- line_elt: function(n) {
- return $(coverage.fixture + " .t" + n);
- },
- num_elt: function(n) {
- return $(coverage.fixture + " .n" + n);
- },
- scroll_to_selection: function() {}
-});
+// Tests of coverage.py HTML report chunk navigation.
// Test helpers
function selection_is(sel) {
- equals(coverage.sel_begin, sel[0]);
- equals(coverage.sel_end, sel[1]);
+ var beg = sel[0], end = sel[1];
+ equals(coverage.sel_begin, beg);
+ equals(coverage.sel_end, end);
+ equals(coverage.code_container().find(".highlight").length, end-beg);
+}
+
+function build_fixture(spec) {
+ $("#fixture-template").tmpl().appendTo("#qunit-fixture");
+ for (var i = 0; i < spec.length; i++) {
+ var data = {number: i+1, klass: spec.substr(i, 1)};
+ $("#lineno-template").tmpl(data).appendTo("#qunit-fixture .linenos");
+ $("#text-template").tmpl(data).appendTo("#qunit-fixture .text");
+ }
}
// Tests
$.each([
- ['rrwwrr', [1,3], [5,7]],
+ ['rrwwrrrr', [1,3], [5,9]],
['rb', [1,2], [2,3]],
- ['wrrwrrw', [2,4], [5,7]],
+ ['wrrwrrrrw', [2,4], [5,9]],
['rrrbbb', [1,4], [4,7]]
], function(i, params) {
+ // Each of these tests uses a fixture with two highlighted chunks.
+
var id = params[0];
var fixture = "#"+id;
var c1 = params[1];
var c2 = params[2];
function setup() {
- coverage.fixture = fixture;
+ build_fixture(id);
};
- test("first chunk on line 1 "+id, function() {
+ test("first chunk on line 1: "+id, function() {
setup();
coverage.to_first_chunk();
selection_is(c1);
});
- test("move to next chunk "+id, function() {
+ test("move to next chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
selection_is(c2);
});
- test("move to first chunk "+id, function() {
+ test("move to first chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
@@ -55,7 +59,7 @@ $.each([
selection_is(c1);
});
- test("move to previous chunk "+id, function() {
+ test("move to previous chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
@@ -63,7 +67,7 @@ $.each([
selection_is(c1);
});
- test("next doesn't move after last chunk "+id, function() {
+ test("next doesn't move after last chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
@@ -71,7 +75,7 @@ $.each([
selection_is(c2);
});
- test("prev doesn't move before first chunk "+id, function() {
+ test("prev doesn't move before first chunk: "+id, function() {
setup();
coverage.to_first_chunk();
coverage.to_next_chunk();
@@ -83,7 +87,7 @@ $.each([
});
test("jump from a line selected", function() {
- coverage.fixture = "#rrwwrr";
+ build_fixture("rrwwrr");
coverage.set_sel(3, 4);
coverage.to_next_chunk();
selection_is([5,7]);
diff --git a/test/qunit/jquery.tmpl.min.js b/test/qunit/jquery.tmpl.min.js
new file mode 100644
index 00000000..7438b2ca
--- /dev/null
+++ b/test/qunit/jquery.tmpl.min.js
@@ -0,0 +1,10 @@
+/*
+ * jQuery Templates Plugin 1.0.0pre
+ * http://github.com/jquery/jquery-tmpl
+ * Requires jQuery 1.4.2
+ *
+ * Copyright Software Freedom Conservancy, Inc.
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ */
+(function(a){var r=a.fn.domManip,d="_tmplitem",q=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,b={},f={},e,p={key:0,data:{}},i=0,c=0,l=[];function g(g,d,h,e){var c={data:e||(e===0||e===false)?e:d?d.data:{},_wrap:d?d._wrap:null,tmpl:null,parent:d||null,nodes:[],calls:u,nest:w,wrap:x,html:v,update:t};g&&a.extend(c,g,{nodes:[],parent:d});if(h){c.tmpl=h;c._ctnt=c._ctnt||c.tmpl(a,c);c.key=++i;(l.length?f:b)[i]=c}return c}a.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(f,d){a.fn[f]=function(n){var g=[],i=a(n),k,h,m,l,j=this.length===1&&this[0].parentNode;e=b||{};if(j&&j.nodeType===11&&j.childNodes.length===1&&i.length===1){i[d](this[0]);g=this}else{for(h=0,m=i.length;h<m;h++){c=h;k=(h>0?this.clone(true):this).get();a(i[h])[d](k);g=g.concat(k)}c=0;g=this.pushStack(g,f,i.selector)}l=e;e=null;a.tmpl.complete(l);return g}});a.fn.extend({tmpl:function(d,c,b){return a.tmpl(this[0],d,c,b)},tmplItem:function(){return a.tmplItem(this[0])},template:function(b){return a.template(b,this[0])},domManip:function(d,m,k){if(d[0]&&a.isArray(d[0])){var g=a.makeArray(arguments),h=d[0],j=h.length,i=0,f;while(i<j&&!(f=a.data(h[i++],"tmplItem")));if(f&&c)g[2]=function(b){a.tmpl.afterManip(this,b,k)};r.apply(this,g)}else r.apply(this,arguments);c=0;!e&&a.tmpl.complete(b);return this}});a.extend({tmpl:function(d,h,e,c){var i,k=!c;if(k){c=p;d=a.template[d]||a.template(null,d);f={}}else if(!d){d=c.tmpl;b[c.key]=c;c.nodes=[];c.wrapped&&n(c,c.wrapped);return a(j(c,null,c.tmpl(a,c)))}if(!d)return[];if(typeof h==="function")h=h.call(c||{});e&&e.wrapped&&n(e,e.wrapped);i=a.isArray(h)?a.map(h,function(a){return a?g(e,c,d,a):null}):[g(e,c,d,h)];return k?a(j(c,null,i)):i},tmplItem:function(b){var c;if(b instanceof a)b=b[0];while(b&&b.nodeType===1&&!(c=a.data(b,"tmplItem"))&&(b=b.parentNode));return c||p},template:function(c,b){if(b){if(typeof b==="string")b=o(b);else if(b instanceof a)b=b[0]||{};if(b.nodeType)b=a.data(b,"tmpl")||a.data(b,"tmpl",o(b.innerHTML));return typeof c==="string"?(a.template[c]=b):b}return c?typeof c!=="string"?a.template(null,c):a.template[c]||a.template(null,q.test(c)?c:a(c)):null},encode:function(a){return(""+a).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}});a.extend(a.tmpl,{tag:{tmpl:{_default:{$2:"null"},open:"if($notnull_1){__=__.concat($item.nest($1,$2));}"},wrap:{_default:{$2:"null"},open:"$item.calls(__,$1,$2);__=[];",close:"call=$item.calls();__=call._.concat($item.wrap(call,__));"},each:{_default:{$2:"$index, $value"},open:"if($notnull_1){$.each($1a,function($2){with(this){",close:"}});}"},"if":{open:"if(($notnull_1) && $1a){",close:"}"},"else":{_default:{$1:"true"},open:"}else if(($notnull_1) && $1a){"},html:{open:"if($notnull_1){__.push($1a);}"},"=":{_default:{$1:"$data"},open:"if($notnull_1){__.push($.encode($1a));}"},"!":{open:""}},complete:function(){b={}},afterManip:function(f,b,d){var e=b.nodeType===11?a.makeArray(b.childNodes):b.nodeType===1?[b]:[];d.call(f,b);m(e);c++}});function j(e,g,f){var b,c=f?a.map(f,function(a){return typeof a==="string"?e.key?a.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+d+'="'+e.key+'" $2'):a:j(a,e,a._ctnt)}):e;if(g)return c;c=c.join("");c.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(f,c,e,d){b=a(e).get();m(b);if(c)b=k(c).concat(b);if(d)b=b.concat(k(d))});return b?b:k(c)}function k(c){var b=document.createElement("div");b.innerHTML=c;return a.makeArray(b.childNodes)}function o(b){return new Function("jQuery","$item","var $=jQuery,call,__=[],$data=$item.data;with($data){__.push('"+a.trim(b).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,function(m,l,k,g,b,c,d){var j=a.tmpl.tag[k],i,e,f;if(!j)throw"Unknown template tag: "+k;i=j._default||[];if(c&&!/\w$/.test(b)){b+=c;c=""}if(b){b=h(b);d=d?","+h(d)+")":c?")":"";e=c?b.indexOf(".")>-1?b+h(c):"("+b+").call($item"+d:b;f=c?e:"(typeof("+b+")==='function'?("+b+").call($item):("+b+"))"}else f=e=i.$1||"null";g=h(g);return"');"+j[l?"close":"open"].split("$notnull_1").join(b?"typeof("+b+")!=='undefined' && ("+b+")!=null":"true").split("$1a").join(f).split("$1").join(e).split("$2").join(g||i.$2||"")+"__.push('"})+"');}return __;")}function n(c,b){c._wrap=j(c,true,a.isArray(b)?b:[q.test(b)?b:a(b).html()]).join("")}function h(a){return a?a.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function s(b){var a=document.createElement("div");a.appendChild(b.cloneNode(true));return a.innerHTML}function m(o){var n="_"+c,k,j,l={},e,p,h;for(e=0,p=o.length;e<p;e++){if((k=o[e]).nodeType!==1)continue;j=k.getElementsByTagName("*");for(h=j.length-1;h>=0;h--)m(j[h]);m(k)}function m(j){var p,h=j,k,e,m;if(m=j.getAttribute(d)){while(h.parentNode&&(h=h.parentNode).nodeType===1&&!(p=h.getAttribute(d)));if(p!==m){h=h.parentNode?h.nodeType===11?0:h.getAttribute(d)||0:0;if(!(e=b[m])){e=f[m];e=g(e,b[h]||f[h]);e.key=++i;b[i]=e}c&&o(m)}j.removeAttribute(d)}else if(c&&(e=a.data(j,"tmplItem"))){o(e.key);b[e.key]=e;h=a.data(j.parentNode,"tmplItem");h=h?h.key:0}if(e){k=e;while(k&&k.key!=h){k.nodes.push(j);k=k.parent}delete e._ctnt;delete e._wrap;a.data(j,"tmplItem",e)}function o(a){a=a+n;e=l[a]=l[a]||g(e,b[e.parent.key+n]||e.parent)}}}function u(a,d,c,b){if(!a)return l.pop();l.push({_:a,tmpl:d,item:this,data:c,options:b})}function w(d,c,b){return a.tmpl(a.template(d),c,b,this)}function x(b,d){var c=b.options||{};c.wrapped=d;return a.tmpl(a.template(b.tmpl),b.data,c,b.item)}function v(d,c){var b=this._wrap;return a.map(a(a.isArray(b)?b.join(""):b).filter(d||"*"),function(a){return c?a.innerText||a.textContent:a.outerHTML||s(a)})}function t(){var b=this.nodes;a.tmpl(null,null,null,this).insertBefore(b[0]);a(b).remove()}})(jQuery); \ No newline at end of file