Beispiel #1
0
def test_text_buffer_end_of_line_peek_char():
    tb = text_buffer.TextBuffer("abcdef")
    tb.column = 5

    assert tb.current_char == "f"
    with pytest.raises(text_buffer.EOLError):
        tb.peek_char
Beispiel #2
0
def test_text_buffer_nextline():
    tb = text_buffer.TextBuffer("abc\ndef\nghi")
    tb.line = 1
    tb.column = 2
    tb.nextline()

    assert tb.position == (2, 0)
Beispiel #3
0
def test_text_buffer_multiple_lines():
    tb = text_buffer.TextBuffer("abc\ndef\nghi")
    tb.line = 1
    tb.column = 1

    assert tb.current_line == "def"
    assert tb.current_char == "e"
    assert tb.peek_char == "f"
Beispiel #4
0
def test_current_char_and_line():
    lex = BaseLexer()
    buf = text_buffer.TextBuffer()
    buf.load("Just an example\nOn two lines")
    lex._text_buffer = buf

    assert lex._current_char == "J"
    assert lex._current_line == "Just an example"
Beispiel #5
0
def test_text_buffer_init_one_line():
    tb = text_buffer.TextBuffer("abcdef")

    assert tb.current_char == "a"
    assert tb.peek_char == "b"
    assert tb.current_line == "abcdef"
    assert tb.line == 0
    assert tb.column == 0
Beispiel #6
0
    def __init__(self, initial_position=None):
        self._text_buffer = text_buffer.TextBuffer()

        self._text_buffer.position
        self._buffer = []
        self._initial_position = initial_position or (0, 0)

        self.tokens = []
Beispiel #7
0
def test_insert():
    lex = BaseLexer()
    buf = text_buffer.TextBuffer()
    buf.load("Just an example\nOn two lines")
    lex._text_buffer = buf
    lex._nextline()

    lex._insert("A third line!")

    assert lex._current_line == "A third line!"
    lex._nextline()
    assert lex._current_line == "On two lines"
Beispiel #8
0
def test_text_buffer_insert():
    tb = text_buffer.TextBuffer("abc\ndef\nghi")
    tb.line = 1
    tb.column = 0

    tb.insert("XYZ\n")

    assert tb.current_line == "XYZ"
    assert tb.position == (1, 0)
    tb.nextline()
    assert tb.current_line == "def"
    assert tb.position == (2, 0)
Beispiel #9
0
    def __init__(self, initial_position=None):
        # Use a TextBuffer internally to manage the text
        self._text_buffer = text_buffer.TextBuffer()

        # A buffer of tokens, useful when you need to
        # collect them but later post-process them
        # before you actually store them as result.
        self._buffer = []

        self._initial_position = initial_position or (0, 0)

        # These are the tokens identified so far
        self.tokens = []
Beispiel #10
0
def test_context_long_lines_end():
    tb = text_buffer.TextBuffer(
        textwrap.dedent("""
            Some text on multiple lines that I will use to check the context() and to text that the whole thing
            works with bigger line numbers in front of the lines I need to add more text
            """))

    context = dedent("""
        1: [...] use to check the context() and to text th [...]
        2: [...] of the lines I need to add more text
                                     ^
        """)

    assert tb.context(2, 60) == context.split("\n")
Beispiel #11
0
def test_context_long_line_end():
    tb = text_buffer.TextBuffer(
        dedent("""
            Some text on a very long line that I will use to check the context() and to test that the whole thing works
            """))

    assert tb.context(0, 100) == {
        "text": [
            "0: [...] and to test that the whole thing works",
            "                                        ^",
        ],
        "line":
        0,
        "column":
        100,
    }
Beispiel #12
0
def test_context():
    tb = text_buffer.TextBuffer(
        textwrap.dedent("""
            Some text
            on multiple lines
            that I will use
            to check the context()
            """))

    context = dedent("""
        2: on multiple lines
        3: that I will use
                  ^
        """)

    assert tb.context(3, 7) == context.split("\n")
Beispiel #13
0
def test_context():
    tb = text_buffer.TextBuffer(
        dedent("""
            Some text
            on multiple lines
            that I will use
            to check the context()
            """))

    assert tb.context(2, 7) == {
        "text": [
            "2: that I will use",
            "          ^",
        ],
        "line": 2,
        "column": 7,
    }
Beispiel #14
0
def test_context_pair_line_numbers():
    tb = text_buffer.TextBuffer(
        textwrap.dedent("""
            Some text
            on multiple lines
            that I will use
            to check the context()
            and to text that
            the whole thing
            works with bigger
            line numbers
            in front of the lines
            I need to add
            more text
            """))

    context = dedent("""
        09: in front of the lines
        10: I need to add
                   ^
        """)

    assert tb.context(10, 7) == context.split("\n")
Beispiel #15
0
def test_text_buffer_skip_defaults_to_one():
    tb = text_buffer.TextBuffer("abc\ndef\nghi")
    tb.skip()

    assert tb.column == 1
Beispiel #16
0
def test_text_buffer_set_position():
    tb = text_buffer.TextBuffer()
    tb.position = (222, 333)

    assert tb.position == (222, 333)
Beispiel #17
0
def test_text_buffer_position():
    tb = text_buffer.TextBuffer()
    tb.line = 123
    tb.column = 456

    assert tb.position == (123, 456)
Beispiel #18
0
def test_text_buffer_skip_accepts_value():
    tb = text_buffer.TextBuffer("abc\ndef\nghi")
    tb.skip(3)

    assert tb.column == 3
Beispiel #19
0
def test_text_buffer_init_empty():
    tb = text_buffer.TextBuffer()

    with pytest.raises(text_buffer.EOFError):
        tb.current_char
Beispiel #20
0
def test_text_buffer_tail():
    ts = text_buffer.TextBuffer("abcdefgh")
    ts.column = 4

    assert ts.tail == "efgh"
Beispiel #21
0
def test_text_buffer_error_after_end_of_file():
    tb = text_buffer.TextBuffer("abcdef")
    tb.line = 100

    with pytest.raises(text_buffer.EOFError):
        tb.current_line
Beispiel #22
0
def test_text_buffer_end_of_line_current_char():
    tb = text_buffer.TextBuffer("abcdef")
    tb.column = 200

    with pytest.raises(text_buffer.EOLError):
        tb.current_char
Beispiel #23
0
def test_text_buffer_goto():
    tb = text_buffer.TextBuffer()
    tb.goto(12, 45)

    assert tb.position == (12, 45)
Beispiel #24
0
def test_text_buffer_goto_default_column():
    tb = text_buffer.TextBuffer()
    tb.goto(12)

    assert tb.position == (12, 0)