blob: 24c0d20be652323b79af4a3e6d8e1106eac11d16 [file] [log] [blame]
suite('text', function() {
function fromLatex(latex) {
var block = latexMathParser.parse(latex);
block.jQize();
return block;
}
function assertSplit(jQ, prev, next) {
var dom = jQ[0];
if (prev) {
assert.ok(dom.previousSibling instanceof Text);
assert.equal(prev, dom.previousSibling.data);
}
else {
assert.ok(!dom.previousSibling);
}
if (next) {
assert.ok(dom.nextSibling instanceof Text);
assert.equal(next, dom.nextSibling.data);
}
else {
assert.ok(!dom.nextSibling);
}
}
test('changes the text nodes as the cursor moves around', function() {
var block = fromLatex('\\text{abc}');
var ctrlr = Controller({ __options: 0 }, block);
var cursor = ctrlr.cursor.insAtRightEnd(block);
ctrlr.moveLeft();
assertSplit(cursor.jQ, 'abc', null);
ctrlr.moveLeft();
assertSplit(cursor.jQ, 'ab', 'c');
ctrlr.moveLeft();
assertSplit(cursor.jQ, 'a', 'bc');
ctrlr.moveLeft();
assertSplit(cursor.jQ, null, 'abc');
ctrlr.moveRight();
assertSplit(cursor.jQ, 'a', 'bc');
ctrlr.moveRight();
assertSplit(cursor.jQ, 'ab', 'c');
ctrlr.moveRight();
assertSplit(cursor.jQ, 'abc', null);
});
});