summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2011-04-17 21:45:35 -0400
committerNed Batchelder <ned@nedbatchelder.com>2011-04-17 21:45:35 -0400
commite67ccb9a24b98143b02fc70de8f4ea2062001c8d (patch)
treed4d307f132a0bdf522e00bfa211639230bfa596b
parent7fb11b6a98d2ede8a82ac39576b707f6d1284c81 (diff)
downloadpython-coveragepy-e67ccb9a24b98143b02fc70de8f4ea2062001c8d.tar.gz
More tests, some refactoring of the code.
-rw-r--r--coverage/htmlfiles/coverage_html.js28
-rw-r--r--test/js/tests.js105
2 files changed, 100 insertions, 33 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js
index 8459327..281ce8b 100644
--- a/coverage/htmlfiles/coverage_html.js
+++ b/coverage/htmlfiles/coverage_html.js
@@ -90,8 +90,10 @@ coverage.pyfile_ready = function($) {
var frag = location.hash;
if (frag.length > 2 && frag[1] === 'n') {
$(frag).addClass('highlight');
- coverage.sel_begin = parseInt(frag.substr(2));
- coverage.sel_end = coverage.sel_begin + 1;
+ coverage.set_sel(parseInt(frag.substr(2)));
+ }
+ else {
+ coverage.set_sel(0);
}
$(document)
@@ -117,27 +119,26 @@ coverage.toggle_lines = function(btn, cls) {
}
};
-// The first line selected, and the next line not selected.
-coverage.sel_begin = 0;
-coverage.sel_end = 1;
-
-// Return the nth line. This function is overridden in the tests to allow use
-// of many fixtures.
+// Return the nth line.
coverage.line_elt = function(n) {
return $("#t" + n);
};
+// Return the nth line number.
coverage.num_elt = function(n) {
return $("#n" + n);
};
+// Return the container of all the code.
coverage.code_container = function(n) {
return $(".linenos");
}
coverage.set_sel = function(b, e) {
+ // The first line selected.
coverage.sel_begin = b;
- coverage.sel_end = e;
+ // The next line not selected.
+ coverage.sel_end = (e === undefined) ? b+1 : e;
};
coverage.to_top = function() {
@@ -168,7 +169,7 @@ coverage.to_next_chunk = function() {
}
// There's a next chunk, `probe` points to it.
- c.sel_begin = probe;
+ var begin = probe;
// Find the end of this chunk.
var next_color = color;
@@ -177,7 +178,7 @@ coverage.to_next_chunk = function() {
probe_line = c.line_elt(probe);
next_color = probe_line.css("background-color");
}
- c.sel_end = probe;
+ c.set_sel(begin, probe);
c.show_selection();
};
@@ -201,7 +202,7 @@ coverage.to_prev_chunk = function() {
}
// There's a prev chunk, `probe` points to its last line.
- c.sel_end = probe+1;
+ var end = probe+1;
// Find the beginning of this chunk.
var prev_color = color;
@@ -210,7 +211,7 @@ coverage.to_prev_chunk = function() {
probe_line = c.line_elt(probe);
prev_color = probe_line.css("background-color");
}
- c.sel_begin = probe+1;
+ c.set_sel(probe+1, end);
c.show_selection();
};
@@ -237,4 +238,3 @@ coverage.scroll_to_selection = function() {
$("html").animate({scrollTop: top_pos-30}, 300);
}
};
-
diff --git a/test/js/tests.js b/test/js/tests.js
index cd4f9d5..bb751a9 100644
--- a/test/js/tests.js
+++ b/test/js/tests.js
@@ -16,67 +16,132 @@ function build_fixture(spec) {
$("#lineno-template").tmpl(data).appendTo("#qunit-fixture .linenos");
$("#text-template").tmpl(data).appendTo("#qunit-fixture .text");
}
+ coverage.pyfile_ready(jQuery);
}
// Tests
+// Zero-chunk tests
+
+module("Zero-chunk navigation", {
+ setup: function() {
+ build_fixture("wwww");
+ }
+});
+
+test("set_sel defaults", function() {
+ coverage.set_sel(2);
+ equals(coverage.sel_begin, 2);
+ equals(coverage.sel_end, 3);
+});
+
+test("No first chunk to select", function() {
+ coverage.to_first_chunk();
+});
+
+// One-chunk tests
+
+$.each([
+ ['rrrrr', [1,6]],
+ ['r', [1,2]],
+ ['wwrrrr', [3,7]],
+ ['wwrrrrww', [3,7]],
+ ['rrrrww', [1,5]]
+], function(i, params) {
+
+ // Each of these tests uses a fixture with one highlighted chunks.
+ var id = params[0];
+ var c1 = params[1];
+
+ module("One-chunk navigation - " + id, {
+ setup: function() {
+ build_fixture(id);
+ }
+ });
+
+ test("First chunk", function() {
+ coverage.to_first_chunk();
+ selection_is(c1);
+ });
+
+ test("Next chunk is first chunk", function() {
+ coverage.to_next_chunk();
+ selection_is(c1);
+ });
+
+ test("There is no next chunk", function() {
+ coverage.to_first_chunk();
+ coverage.to_next_chunk();
+ selection_is(c1);
+ });
+
+ test("There is no prev chunk", function() {
+ coverage.to_first_chunk();
+ coverage.to_prev_chunk();
+ selection_is(c1);
+ });
+});
+
+// Two-chunk tests
+
$.each([
['rrwwrrrr', [1,3], [5,9]],
['rb', [1,2], [2,3]],
+ ['rbbbbbbbbbb', [1,2], [2,12]],
+ ['rrrrrrrrrrb', [1,11], [11,12]],
['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() {
- build_fixture(id);
- };
+ module("Two-chunk navigation - " + id, {
+ setup: function() {
+ build_fixture(id);
+ }
+ });
- test("first chunk on line 1: "+id, function() {
- setup();
+ test("First chunk", function() {
coverage.to_first_chunk();
selection_is(c1);
});
- test("move to next chunk: "+id, function() {
- setup();
+ test("Next chunk is first chunk", function() {
+ coverage.to_next_chunk();
+ selection_is(c1);
+ });
+
+ test("Move to next chunk", function() {
coverage.to_first_chunk();
coverage.to_next_chunk();
selection_is(c2);
});
- test("move to first chunk: "+id, function() {
- setup();
+ test("Move to first chunk", function() {
coverage.to_first_chunk();
coverage.to_next_chunk();
coverage.to_first_chunk();
selection_is(c1);
});
- test("move to previous chunk: "+id, function() {
- setup();
+ test("Move to previous chunk", function() {
coverage.to_first_chunk();
coverage.to_next_chunk();
coverage.to_prev_chunk();
selection_is(c1);
});
- test("next doesn't move after last chunk: "+id, function() {
- setup();
+ test("Next doesn't move after last chunk", function() {
coverage.to_first_chunk();
coverage.to_next_chunk();
coverage.to_next_chunk();
selection_is(c2);
});
- test("prev doesn't move before first chunk: "+id, function() {
- setup();
+ test("Prev doesn't move before first chunk", function() {
coverage.to_first_chunk();
coverage.to_next_chunk();
coverage.to_prev_chunk();
@@ -86,9 +151,11 @@ $.each([
});
-test("jump from a line selected", function() {
+module("Miscellaneous");
+
+test("Jump from a line selected", function() {
build_fixture("rrwwrr");
- coverage.set_sel(3, 4);
+ coverage.set_sel(3);
coverage.to_next_chunk();
selection_is([5,7]);
});