Beispiel #1
0
def test_replace_cs(qtbot):
    editor_ref = create_editor()
    editor_ref.text = "this gabo is Gabo a testGaBo aslkd laskd"
    editor_ref.moveCursor(editor_ref.textCursor().Start)
    editor_ref.find_match("Gabo", case_sensitive=True)
    editor_ref.replace_match("Gabo", "GABO", cs=True)
    assert editor_ref.text == "this gabo is GABO a testGaBo aslkd laskd"
Beispiel #2
0
def test_autocomplete_multiline_selection2(qtbot):
    editor_ref = create_editor()
    editor_ref.text = 'ninja-ide rocks!\nholaaaa\nkokoko'
    editor_ref.selectAll()
    for i in range(5):
        qtbot.keyPress(editor_ref, Qt.Key_Apostrophe)
    assert editor_ref.text == "'''''ninja-ide rocks!\nholaaaa\nkokoko'''''"
Beispiel #3
0
def test_comment(qtbot):
    editor_ref = create_editor("python")
    editor_ref.text = "# This is a comment\ndef foo():\n    # pass\n    pass"
    editor_ref.selectAll()
    helpers.comment_or_uncomment(editor_ref)
    assert editor_ref.text == ("# # This is a comment\n# def foo():\n#     "
                               "# pass\n#     pass")
Beispiel #4
0
def test_autocomplete_double_quote2(qtbot):
    editor_ref = create_editor()
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)
    assert editor_ref.text == '""'
    _, col = editor_ref.cursor_position
    assert col == 2
def test_4(qtbot):
    editor_ref = create_editor()
    qtbot.keyPress(editor_ref, Qt.Key_BracketLeft)
    assert editor_ref.text == '[]'
    qtbot.keyPress(editor_ref, Qt.Key_BracketRight)
    assert editor_ref.text == '[]'
    _, col = editor_ref.cursor_position
    assert col == 2
def test_5(qtbot):
    editor_ref = create_editor()
    qtbot.keyPress(editor_ref, Qt.Key_BraceLeft)
    assert editor_ref.text == '{}'
    qtbot.keyPress(editor_ref, Qt.Key_BraceRight)
    assert editor_ref.text == '{}'
    _, col = editor_ref.cursor_position
    assert col == 2
def test_6(qtbot):
    editor_ref = create_editor()
    qtbot.keyPress(editor_ref, Qt.Key_ParenLeft)
    assert editor_ref.text == '()'
    qtbot.keyPress(editor_ref, Qt.Key_ParenRight)
    assert editor_ref.text == '()'
    _, col = editor_ref.cursor_position
    assert col == 2
Beispiel #8
0
def test_move_up(qtbot):
    editor_ref = create_editor()
    editor_ref.text = 'print\ntype(str)'
    cursor = editor_ref.textCursor()
    cursor.movePosition(cursor.End)
    editor_ref.setTextCursor(cursor)
    editor_ref.move_up_down(up=True)
    assert editor_ref.text == 'type(str)\nprint\n'
def test_19():
    a_text = "d = ['one', 'two']"
    editor_ref = create_editor('python')
    editor_ref.text = a_text
    editor_ref.cursor_position = 1, 5
    editor_ref._indenter.indent_block(editor_ref.textCursor())
    expected = "d = [\n    'one', 'two']"
    assert editor_ref.text == expected
Beispiel #10
0
def test_replace(qtbot):
    editor_ref = create_editor()
    editor_ref.text = "this gabo is Gabo a testGaBo aslkd laskd"
    editor_ref.moveCursor(editor_ref.textCursor().Start)
    editor_ref.find_match("gabo")
    editor_ref.replace_match("gabo", "gaboxx")
    editor_ref.find_match("gabo")
    editor_ref.replace_match("gabo", "gaboxx")
    assert editor_ref.text == "this gaboxx is gaboxx a testGaBo aslkd laskd"
def test_8(qtbot):
    editor_ref = create_editor()
    repeat = 10
    for i in range(repeat):
        qtbot.keyPress(editor_ref, Qt.Key_BraceLeft)
    assert editor_ref.text == '{{{{{{{{{{}}}}}}}}}}'
    for i in range(repeat - 1):
        qtbot.keyPress(editor_ref, Qt.Key_Backspace)
    assert editor_ref.text == '{}'
Beispiel #12
0
def test_9(qtbot):
    editor_ref = create_editor()
    editor_ref.text = "test content"
    cursor = editor_ref.textCursor()
    cursor.movePosition(cursor.EndOfBlock)
    editor_ref.setTextCursor(cursor)
    # Press '('
    qtbot.keyPress(editor_ref, Qt.Key_ParenLeft)
    assert editor_ref.text == "test content()"
Beispiel #13
0
def test_autocomplete_triple_simple_quotes(qtbot):
    editor_ref = create_editor()
    qtbot.keyPress(editor_ref, Qt.Key_Apostrophe)
    qtbot.keyPress(editor_ref, Qt.Key_Apostrophe)
    qtbot.keyPress(editor_ref, Qt.Key_Apostrophe)
    qtbot.keyPress(editor_ref, Qt.Key_Apostrophe)
    assert editor_ref.text == "''''''"
    _, col = editor_ref.cursor_position
    assert col == 3
Beispiel #14
0
def make_indent(text, language=None):
    """Indent last line of text"""
    editor_ref = create_editor(language)

    editor_ref.text = text
    cursor = editor_ref.textCursor()
    cursor.movePosition(cursor.End)
    editor_ref.setTextCursor(cursor)
    editor_ref._indenter.indent_block(editor_ref.textCursor())
    return editor_ref.text
Beispiel #15
0
def make_indent_with_tab(text, selection=False, n=1):
    editor_ref = create_editor()
    editor_ref.text = text
    for i in range(n):
        if selection:
            editor_ref.selectAll()
            editor_ref._indenter.indent_selection()
        else:
            editor_ref._indenter.indent()
    return editor_ref.text
Beispiel #16
0
def test_move_down_selection(qtbot):
    editor_ref = create_editor()
    editor_ref.text = 'print\nprint\nprint\nninja\nninja'
    cursor = editor_ref.textCursor()
    cursor.movePosition(cursor.Start)
    cursor.movePosition(cursor.EndOfBlock, cursor.KeepAnchor)
    cursor.movePosition(cursor.Down, cursor.KeepAnchor)
    cursor.movePosition(cursor.Down, cursor.KeepAnchor)
    editor_ref.setTextCursor(cursor)
    editor_ref.move_up_down()
    editor_ref.move_up_down()
    assert editor_ref.text == 'ninja\nninja\nprint\nprint\nprint'
Beispiel #17
0
def test_autocomplete_triple_double_quotes3(qtbot):
    editor_ref = create_editor()
    qtbot.keyPress(editor_ref, Qt.Key_Return)
    qtbot.keyPress(editor_ref, Qt.Key_Return)
    for i in range(4):
        qtbot.keyPress(editor_ref, Qt.Key_Space)
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)

    assert editor_ref.text == '\n\n    """"""'
    _, col = editor_ref.cursor_position
    assert col == 7
def test_23():
    """
    x = [0, 1, 2,
         [3, 4, 5,
          6, 7, 8],
         9, 10, 11]
    """

    a_text = "x = [0, 1, 2,\n     [3, 4, 5,\n      6, 7, 8],"
    editor_ref = create_editor("python")
    editor_ref.text = a_text
    editor_ref.cursor_position = 3, 15
    editor_ref._indenter.indent_block(editor_ref.textCursor())
    expected = "x = [0, 1, 2,\n     [3, 4, 5,\n      6, 7, 8],\n     "
    assert editor_ref.text == expected
def test_20():
    """
    {
        {
        },
        | <-- cursor
    }
    """
    a_text = "{\n    {\n    },\n}"
    editor_ref = create_editor("python")
    editor_ref.text = a_text
    editor_ref.cursor_position = 2, 6
    editor_ref._indenter.indent_block(editor_ref.textCursor())
    expected = '{\n    {\n    },\n    \n}'
    assert editor_ref.text == expected
    assert editor_ref.cursor_position == (3, 4)
Beispiel #20
0
def test_last(qtbot):
    editor_ref = create_editor()
    editor_ref.text = "class NINJA(object):"
    cur = editor_ref.textCursor()
    cur.movePosition(cur.End)
    editor_ref.setTextCursor(cur)
    qtbot.keyPress(editor_ref, Qt.Key_Return)
    for i in range(4):
        qtbot.keyPress(editor_ref, Qt.Key_Space)
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)

    assert editor_ref.text == 'class NINJA(object):\n    """"""'
    _, col = editor_ref.cursor_position
    assert col == 7
    editor_ref.textCursor().insertText('docstring')
    assert editor_ref.text == 'class NINJA(object):\n    """docstring"""'
Beispiel #21
0
def test_uncomment_selected_lines(qtbot):
    editor_ref = create_editor("python")
    editor_ref.text = "# this\n# is\n# a\n# text"
    editor_ref.selectAll()
    helpers.comment_or_uncomment(editor_ref)
    assert editor_ref.text == "this\nis\na\ntext"
Beispiel #22
0
def test_uncomment2(qtbot):
    editor_ref = create_editor("python")
    editor_ref.text = "print\n# print"
    editor_ref.selectAll()
    helpers.comment_or_uncomment(editor_ref)
    assert editor_ref.text == "# print\n# # print"
Beispiel #23
0
def test_replace_all(qtbot):
    editor_ref = create_editor()
    editor_ref.text = "this gabo is Gabo a testGaBo aslkd laskd"
    editor_ref.moveCursor(editor_ref.textCursor().Start)
    editor_ref.replace_all("gabo", "gabox")
    assert editor_ref.text == "this gabox is gabox a testgabox aslkd laskd"
Beispiel #24
0
def test_replace_wo(qtbot):
    editor_ref = create_editor()
    editor_ref.text = "this gabo is Gabo a testGaBo aslkd laskd"
    editor_ref.moveCursor(editor_ref.textCursor().Start)
    editor_ref.replace_all("gabo", "GABO", wo=True)
    assert editor_ref.text == "this GABO is GABO a testGaBo aslkd laskd"
Beispiel #25
0
def test_simple_uncomment(qtbot):
    editor_ref = create_editor("python")
    editor_ref.text = "# this\nis\na\ntext"
    helpers.comment_or_uncomment(editor_ref)
    assert editor_ref.text == "this\nis\na\ntext"
def test_7(qtbot):
    editor_ref = create_editor()
    qtbot.keyPress(editor_ref, Qt.Key_BracketLeft)
    qtbot.keyPress(editor_ref, Qt.Key_Backspace)
    assert editor_ref.text == ''
Beispiel #27
0
def test_autocomplete_single_selection(qtbot):
    editor_ref = create_editor()
    editor_ref.text = 'ninja-ide rocks!'
    editor_ref.selectAll()
    qtbot.keyPress(editor_ref, Qt.Key_QuoteDbl)
    assert editor_ref.text == '"ninja-ide rocks!"'
Beispiel #28
0
def get_marker_area():
    editor = create_editor()
    return marker_area.MarkerArea(editor)
Beispiel #29
0
from ninja_tests.gui import editor

editor_ref = editor.create_editor()
widget = editor_ref.side_widgets.get("MarkerWidget")


def test_1(qtbot):
    widget.add_bookmark(2)
    widget.add_bookmark(5)
    assert widget.bookmarks == [2, 5]


def test_2(qtbot):
    for i in range(100):
        editor_ref.textCursor().insertBlock()
    widget.add_bookmark(57)
    widget.add_bookmark(20)
    widget.add_bookmark(5)
    widget.add_bookmark(97)
    widget.add_bookmark(100)
    editor_ref.cursor_position = 16, 0
    widget.next_bookmark()
    line, _ = editor_ref.cursor_position
    assert line == 20
    widget.previous_bookmark()
    line, _ = editor_ref.cursor_position
    assert line == 5


def test_3():
    for i in range(190):