Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

1.7 KB
Raw Blame
package opensuite.ui;

import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

/** Tests the editor delete-line transform used by the Ctrl+D shortcut. */
public final class EditorKeysTest {

    public void run() {
        Harness.suite("editor keys");

        Harness.test("delete-line removes the caret's line and its newline", () -> {
            EditorKeys.Result r = EditorKeys.deleteLine("one\ntwo\nthree", 5); // caret at column 1 of "two"
            Expect.equal(r.text(), "one\nthree", "middle line removed");
            Expect.equal(r.caret(), 5, "caret keeps column 1 on the line that moved up ('three')");
        });

        Harness.test("delete-line on the first and last lines", () -> {
            Expect.equal(EditorKeys.deleteLine("a\nb\nc", 0).text(), "b\nc", "first line");
            EditorKeys.Result last = EditorKeys.deleteLine("a\nb\nc", 4); // caret in "c"
            Expect.equal(last.text(), "a\nb\n", "last line removed, trailing newline kept");
        });

        Harness.test("delete-line keeps the column, clamped to the new line length", () -> {
            EditorKeys.Result r = EditorKeys.deleteLine("longline\nhi\nx", 6); // column 6 on line 1
            Expect.equal(r.text(), "hi\nx", "first line gone");
            Expect.equal(r.caret(), 2, "column 6 clamped to the 2-char line 'hi'");
        });

        Harness.test("delete-line copes with a single line and empty text", () -> {
            Expect.equal(EditorKeys.deleteLine("only", 2).text(), "", "the one line is removed");
            Expect.equal(EditorKeys.deleteLine("", 0).text(), "", "empty text stays empty");
            Expect.equal(EditorKeys.deleteLine(null, 5).text(), "", "null is handled");
        });
    }
}