MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / testMoveBidi

Function testMoveBidi

lib/web/CodeMirror/test/test.js:2477–2534  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

2475}
2476
2477function testMoveBidi(str) {
2478 testCM("move_bidi_" + str, function(cm) {
2479 if (cm.getOption("inputStyle") != "textarea" || !cm.getOption("rtlMoveVisually")) return;
2480 cm.getScrollerElement().style.fontFamily = "monospace";
2481 makeItWrapAfter(cm, Pos(0, 5));
2482
2483 var steps = str.length - countIf(str.split(""), function(ch) { return extendingChars.test(ch) });
2484 var lineBreaks = {}
2485 lineBreaks[6 - countIf(str.substr(0, 5).split(""), function(ch) { return extendingChars.test(ch) })] = 'w';
2486 if (str.indexOf("\n") != -1) {
2487 lineBreaks[steps - 2] = 'n';
2488 }
2489
2490 // Make sure we are at the visual beginning of the first line
2491 cm.execCommand("goLineStart");
2492
2493 var prevCoords = cm.cursorCoords(), coords;
2494 for(var i = 0; i < steps; ++i) {
2495 cm.execCommand("goCharRight");
2496 coords = cm.cursorCoords();
2497 if ((i >= 10 && i <= 12) && !lineBreaks[i] && coords.left < prevCoords.left && coords.top > prevCoords.top) {
2498 // The first line wraps twice
2499 lineBreaks[i] = 'w';
2500 }
2501 if (!lineBreaks[i]) {
2502 is(coords.left > prevCoords.left, "In step " + i + ", cursor didn't move right");
2503 eq(coords.top, prevCoords.top, "In step " + i + ", cursor moved out of line");
2504 } else {
2505 is(coords.left < prevCoords.left, i);
2506 is(coords.top > prevCoords.top, i);
2507 }
2508 prevCoords = coords;
2509 }
2510
2511 cm.execCommand("goCharRight");
2512 coords = cm.cursorCoords();
2513 eq(coords.left, prevCoords.left, "Moving " + steps + " steps right didn't reach the end");
2514 eq(coords.top, prevCoords.top, "Moving " + steps + " steps right didn't reach the end");
2515
2516 for(i = steps - 1; i >= 0; --i) {
2517 cm.execCommand("goCharLeft");
2518 coords = cm.cursorCoords();
2519 if (!(lineBreaks[i] == 'n' || lineBreaks[i + 1] == 'w')) {
2520 is(coords.left < prevCoords.left, "In step " + i + ", cursor didn't move left");
2521 eq(coords.top, prevCoords.top, "In step " + i + ", cursor is not at the same line anymore");
2522 } else {
2523 is(coords.left > prevCoords.left, i);
2524 is(coords.top < prevCoords.top, i);
2525 }
2526 prevCoords = coords;
2527 }
2528
2529 cm.execCommand("goCharLeft");
2530 coords = cm.cursorCoords();
2531 eq(coords.left, prevCoords.left, "Moving " + steps + " steps left didn't reach the beginning");
2532 eq(coords.top, prevCoords.top, "Moving " + steps + " steps left didn't reach the beginning");
2533 }, {value: str, lineWrapping: true})
2534};

Callers 1

test.jsFile · 0.85

Calls 9

testCMFunction · 0.85
makeItWrapAfterFunction · 0.85
countIfFunction · 0.85
eqFunction · 0.85
indexOfMethod · 0.80
isFunction · 0.70
PosFunction · 0.50
splitMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected