diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2011-04-16 23:20:35 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2011-04-16 23:20:35 -0400 |
commit | 76d8a659bd63b9c1f12daf5d594d8be725589c3c (patch) | |
tree | 07b691bbc0ae9635b0b028d95849f9ceb0ce1290 /test/js | |
parent | 40ac04235ae802caa74215157cab3f0b77c48e8d (diff) | |
download | python-coveragepy-git-76d8a659bd63b9c1f12daf5d594d8be725589c3c.tar.gz |
Javascript tests
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/index.html | 62 | ||||
-rw-r--r-- | test/js/tests.js | 90 |
2 files changed, 152 insertions, 0 deletions
diff --git a/test/js/index.html b/test/js/index.html new file mode 100644 index 00000000..f89c57af --- /dev/null +++ b/test/js/index.html @@ -0,0 +1,62 @@ +<!DOCTYPE html> +<html> +<head> + <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/coverage_html.js"></script> + <script type="text/javascript" src="../qunit/qunit.js"></script> + + <style> + .red { background-color: red; } + .white { } + .blue { background-color: blue; } + </style> + + <script type="text/javascript" src="tests.js"></script> + +</head> +<body> + <h1 id="qunit-header">Coverage.py Javascript Test Suite</h1> + <h2 id="qunit-banner"></h2> + <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> +</body> +</html> diff --git a/test/js/tests.js b/test/js/tests.js new file mode 100644 index 00000000..d298cebe --- /dev/null +++ b/test/js/tests.js @@ -0,0 +1,90 @@ +// 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() {} +}); + +// Test helpers + +function selection_is(sel) { + equals(coverage.sel_begin, sel[0]); + equals(coverage.sel_end, sel[1]); +} + +// Tests + +$.each([ + ['rrwwrr', [1,3], [5,7]], + ['rb', [1,2], [2,3]], + ['wrrwrrw', [2,4], [5,7]], + ['rrrbbb', [1,4], [4,7]] +], function(i, params) { + + var id = params[0]; + var fixture = "#"+id; + var c1 = params[1]; + var c2 = params[2]; + + function setup() { + coverage.fixture = fixture; + }; + + test("first chunk on line 1 "+id, function() { + setup(); + coverage.to_first_chunk(); + selection_is(c1); + }); + + 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() { + setup(); + coverage.to_first_chunk(); + coverage.to_next_chunk(); + coverage.to_first_chunk(); + selection_is(c1); + }); + + test("move to previous chunk "+id, function() { + setup(); + 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(); + 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(); + coverage.to_first_chunk(); + coverage.to_next_chunk(); + coverage.to_prev_chunk(); + coverage.to_prev_chunk(); + selection_is(c1); + }); + +}); + +test("jump from a line selected", function() { + coverage.fixture = "#rrwwrr"; + coverage.set_sel(3, 4); + coverage.to_next_chunk(); + selection_is([5,7]); +}); |