Ejemplo n.º 1
0
def test_json():
    test = ["key: [86, 95, 12] # json 1.r"]
    line = 0
    index = 1
    anal = ChangeAnalyzer(line, index, test)
    #init class
    assert anal._area[0] == test[0]
    #key possition
    assert anal.get_pos_type() is PosType.in_key
    index = 5
    anal = ChangeAnalyzer(line, index, test)
    #value possition 1
    assert anal.get_pos_type() is PosType.in_value
    index = 8
    anal = ChangeAnalyzer(line, index, test)
    #value possition 2
    assert anal.get_pos_type() is PosType.in_value
    index = 20
    anal = ChangeAnalyzer(line, index, test)
    #comment possition
    assert anal.get_pos_type() is PosType.comment
    index = 7
    anal = ChangeAnalyzer(line, index, test)
    #inner possition
    assert anal.get_pos_type() is PosType.in_inner
    # uncomment function
    assert LineAnalyzer.strip_comment(test[0]) == "key: [86, 95, 12]"
    assert LineAnalyzer.strip_comment(
        "key: [86, 95, 12]     # json 1.r") == "key: [86, 95, 12]"
    # identation
    assert LineAnalyzer.indent_changed("test1", "test2") is False
    assert LineAnalyzer.indent_changed("   test1", "  test2") is True

    test = ["key: {key1: 86,key2: 95, key3: 12} # json 1.r"]
    line = 0
    index = 3
    anal = ChangeAnalyzer(line, index, test)
    #init class
    assert anal._area[0] == test[0]
    #key possition
    assert anal.get_pos_type() is PosType.in_key
    index = 5
    anal = ChangeAnalyzer(line, index, test)
    #value possition 1
    assert anal.get_pos_type() is PosType.in_value
    index = 11
    anal = ChangeAnalyzer(line, index, test)
    #value possition 2
    assert anal.get_pos_type() is PosType.in_value
    index = 40
    anal = ChangeAnalyzer(line, index, test)
    #comment possition
    assert anal.get_pos_type() is PosType.comment
    index = 7
    anal = ChangeAnalyzer(line, index, test)
    #inner possition
    assert anal.get_pos_type() is PosType.in_inner
Ejemplo n.º 2
0
    def _item_selected(self, start_line, start_column, end_line, end_column):
        """Handle when an item is selected from tree or error tab.

        :param int start_line: line where the selection starts
        :param int start_column: column where the selection starts
        :param int end_line: line where the selection ends
        :param int end_column: column where the selection ends
        """
        self.editor.setFocus()

        # remove empty line and whitespaces at the end of selection
        if end_line > start_line and end_line > 1:
            last_line_text = self.editor.text(end_line-1)
            if end_column > len(last_line_text):
                end_column = len(last_line_text) + 1
            last_line_text_selected = last_line_text[:end_column-1]
            if LineAnalyzer.is_empty(last_line_text_selected):
                end_line -= 1
                end_line_text = self.editor.text(end_line-1)
                end_column = len(end_line_text)

        # select in reversed order - move cursor to the beginning of selection
        self.editor.mark_selected(end_line, end_column, start_line, start_column)
Ejemplo n.º 3
0
def test_is_empty(line, expected):
    assert LineAnalyzer.is_empty(line) == expected
Ejemplo n.º 4
0
def test_get_autocomplete_context(line, index, expected):
    assert LineAnalyzer.get_autocomplete_context(line, index) == expected
Ejemplo n.º 5
0
def test_strip_comment(line, expected):
    assert LineAnalyzer.strip_comment(line) == expected
Ejemplo n.º 6
0
def test_get_node_start(line, expected):
    assert LineAnalyzer.get_node_start(line) == expected
Ejemplo n.º 7
0
def test_uncomment(line, expected):
    """Test if uncomment removes the leading comment symbol."""
    assert LineAnalyzer.uncomment(line) == expected
Ejemplo n.º 8
0
def test_begins_with_comment(line, expected):
    """Test :py:meth:`begins_with_comment`."""
    assert LineAnalyzer.begins_with_comment(line) == expected
Ejemplo n.º 9
0
def test_get_str_position(line, string, expected):
    assert LineAnalyzer.get_str_position(line, string) == expected
Ejemplo n.º 10
0
def test_get_after_key_area_end(line, expected):
    assert LineAnalyzer.get_after_key_area_end(line) == expected
Ejemplo n.º 11
0
def test_get_autocompletion_word(line, start_index, expected):
    assert LineAnalyzer.get_autocompletion_word(line, start_index) == expected
Ejemplo n.º 12
0
def test_get_indent(line, expected):
    assert LineAnalyzer.get_indent(line) == expected