Exemple #1
0
def test_buf_set_value_idx_negative():
    lst = ['a', 'b', 'c']

    buf = Buf(lst)

    with buf.record() as modifications:
        buf[-1] = 'hello'

    assert lst == ['a', 'b', 'hello']

    buf.apply(modifications)

    assert lst == ['a', 'b', 'c']
Exemple #2
0
def test_buf_insert_with_negative():
    lst = ['a', 'b', 'c']

    buf = Buf(lst)

    with buf.record() as modifications:
        buf.insert(-1, 'q')

    assert lst == ['a', 'b', 'q', 'c']

    buf.apply(modifications)

    assert lst == ['a', 'b', 'c']
Exemple #3
0
def test_buf_del_with_negative():
    lst = ['a', 'b', 'c']

    buf = Buf(lst)

    with buf.record() as modifications:
        del buf[-1]

    assert lst == ['a', 'b']

    buf.apply(modifications)

    assert lst == ['a', 'b', 'c']
Exemple #4
0
def test_buf_pop_idx():
    lst = ['a', 'b', 'c']

    buf = Buf(lst)

    with buf.record() as modifications:
        buf.pop(1)

    assert lst == ['a', 'c']

    buf.apply(modifications)

    assert lst == ['a', 'b', 'c']
Exemple #5
0
def test_buf_append():
    lst = ['a', 'b', 'c']

    buf = Buf(lst)

    with buf.record() as modifications:
        buf.append('q')

    assert lst == ['a', 'b', 'c', 'q']

    buf.apply(modifications)

    assert lst == ['a', 'b', 'c']
Exemple #6
0
def test_buf_multiple_modifications():
    lst = ['a', 'b', 'c']

    buf = Buf(lst)

    with buf.record() as modifications:
        buf[1] = 'hello'
        buf.insert(1, 'ohai')
        del buf[0]

    assert lst == ['ohai', 'hello', 'c']

    buf.apply(modifications)

    assert lst == ['a', 'b', 'c']