示例#1
0
def LocationsOfEnclosingTags_UnbalancedOpeningTag_test():
    # this is the reason why we need to continue looking for a different opening
    # tag if the closing tag we found does not match
    html = "<ul><li>foo</ul>"
    eq_((1, 1, 1, 12), mta_core.LocationsOfEnclosingTags(html, 1, 9))

    html = "<ul><li></ul></ul>"
    eq_((1, 1, 1, 9), mta_core.LocationsOfEnclosingTags(html, 1, 1))

    # this is the reason why we need to be able to skip over orphan open tags
    html = "<ul><ul><li></ul>x<ul><li></ul>\n</ul>"
    eq_((1, 1, 2, 1), mta_core.LocationsOfEnclosingTags(html, 1, 2))
    eq_((1, 1, 2, 1), mta_core.LocationsOfEnclosingTags(html, 1, 18))
示例#2
0
def LocationOfEnclosingTagsInWindowView():
    # 1-based line numbers
    first_window_line = int(vim.eval("line('w0')"))
    last_window_line = int(vim.eval("line('w$')"))

    # -1 because vim.current.buffer is 0-based whereas vim lines are 1-based
    visible_text = '\n'.join(vim.current.buffer[first_window_line -
                                                1:last_window_line])

    cursor_line, cursor_column = CurrentLineAndColumn()
    adapted_cursor_line = cursor_line - first_window_line + 1

    if not CanAccessCursorColumn(cursor_column):
        # We need to do this because when the cursor is on the last column in insert
        # mode, that column *doesn't exist yet*. Not until the user actually types
        # something in and moves the cursor forward.
        cursor_column -= 1

    (opening_tag_line, opening_tag_column, closing_tag_line,
     closing_tag_column) = mta_core.LocationsOfEnclosingTags(
         visible_text, adapted_cursor_line, cursor_column)

    return [
        opening_tag_line + first_window_line - 1, opening_tag_column,
        closing_tag_line + first_window_line - 1, closing_tag_column
    ]
示例#3
0
def LocationsOfEnclosingTags_Fail_test():
    html = ""
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 2))

    html = "foo bar baz qux"
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 8))

    html = "<div>"
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 2))

    html = "</div>"
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 2))

    html = "<div></div>"
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 10, 10))
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 20))

    html = "<div><div>"
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 5))

    html = "<div><br/><div>"
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 8))

    html = "</div><div/>"
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 5))

    html = "</div></div>"
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 5))

    html = "<div></foo>"
    eq_((0, 0, 0, 0), mta_core.LocationsOfEnclosingTags(html, 1, 5))
示例#4
0
 def gen(column):
     eq_((1, 1, 1, 12), mta_core.LocationsOfEnclosingTags(html, 1, column))
示例#5
0
def LocationsOfEnclosingTags_CursorInTag_test():
    html = "<\ndiv\t \nid='foo' \n>baz <p>qux<br/></p></div>"
    eq_((1, 1, 4, 21), mta_core.LocationsOfEnclosingTags(html, 3, 2))
示例#6
0
def LocationsOfEnclosingTags_Comments_test():
    html = "<div><p><!-- <div> --><br/></p> foo </div>"
    eq_((1, 1, 1, 37), mta_core.LocationsOfEnclosingTags(html, 1, 34))
示例#7
0
def LocationsOfEnclosingTags_MultiLine_test():
    html = "<\ndiv><\n\np>\n<br/></p>\n foo </div>"
    eq_((1, 1, 6, 6), mta_core.LocationsOfEnclosingTags(html, 6, 2))

    html = "<\ndiv><\n\np>\n<br/></p>\n foo <\ta>\tbar\n<br/><\n/a> </div>"
    eq_((1, 1, 8, 5), mta_core.LocationsOfEnclosingTags(html, 6, 2))
示例#8
0
def LocationsOfEnclosingTags_Nested_test():
    html = "<div><p><br/></p> foo </div>"
    eq_((1, 1, 1, 23), mta_core.LocationsOfEnclosingTags(html, 1, 19))
示例#9
0
def LocationsOfEnclosingTags_Basic_test():
    html = "<div> foo </div>"
    eq_((1, 1, 1, 11), mta_core.LocationsOfEnclosingTags(html, 1, 7))