fix virtual renderer test

This commit is contained in:
nightwing 2012-05-08 19:25:15 +04:00
commit 766af2388e

View file

@ -50,34 +50,36 @@ var assert = require("./test/assertions");
module.exports = {
"test: screen2text the column should be rounded to the next character edge" : function() {
var el = document.createElement("div");
if (!el.getBoundingClientRect) {
console.log("Skipping test: This test only runs in the browser");
return;
}
el.style.left = "0px";
el.style.top = "0px";
el.style.width = "100px";
el.style.left = "20px";
el.style.top = "30px";
el.style.width = "300px";
el.style.height = "100px";
document.body.style.margin = "0px";
document.body.style.padding = "0px";
document.body.appendChild(el);
var renderer = new VirtualRenderer(el);
renderer.setPadding(0);
renderer.setSession(new EditSession("1234"));
var r = renderer.scroller.getBoundingClientRect();
function testPixelToText(x, y, row, column) {
assert.position(renderer.screenToTextCoordinates(x+r.left, y+r.top), row, column);
}
renderer.characterWidth = 10;
renderer.lineHeight = 15;
assert.position(renderer.screenToTextCoordinates(0, 0), 0, 0);
assert.position(renderer.screenToTextCoordinates(4, 0), 0, 0);
assert.position(renderer.screenToTextCoordinates(5, 0), 0, 1);
assert.position(renderer.screenToTextCoordinates(9, 0), 0, 1);
assert.position(renderer.screenToTextCoordinates(10, 0), 0, 1);
assert.position(renderer.screenToTextCoordinates(14, 0), 0, 1);
assert.position(renderer.screenToTextCoordinates(15, 0), 0, 2);
testPixelToText(4, 0, 0, 0);
testPixelToText(5, 0, 0, 1);
testPixelToText(9, 0, 0, 1);
testPixelToText(10, 0, 0, 1);
testPixelToText(14, 0, 0, 1);
testPixelToText(15, 0, 0, 2);
document.body.removeChild(el);
}