summaryrefslogtreecommitdiff
path: root/test/js/tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js/tests.js')
-rw-r--r--test/js/tests.js105
1 files changed, 86 insertions, 19 deletions
diff --git a/test/js/tests.js b/test/js/tests.js
index cd4f9d58..bb751a9e 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]);
});