Exemple #1
0
def test_hash_delta():
    operation = OperationsList()
    delta = Delta()

    assert hash(delta) == hash(operation)

    assert hash(Delta().insert('Hello')) == hash(Delta().insert('Hello'))
    assert hash(Delta().insert('hello')) != hash(Delta().insert('Hello'))
Exemple #2
0
    def test_insert_text_after_delete(self):
        delta = Delta().delete(1).insert('a')
        expected = Delta().insert('a').delete(1)

        assert delta == expected, [delta.ops, expected.ops]

        delta = Delta().delete(1).insert('a').insert('b')
        expected = Delta().insert('a').insert('b').delete(1)

        assert delta == expected, [delta.ops, expected.ops]
Exemple #3
0
    def test_retain_delta_lengths(self):
        delta = Delta().retain(1)
        assert delta.length() == 1

        delta = Delta().retain(10)
        assert delta.length() == 10

        delta = Delta().retain(10).retain(10).retain(10)
        assert delta.length() == 30
Exemple #4
0
    def test_delete_delta_lengths(self):
        delta = Delta().delete(1)
        assert delta.length() == 1

        delta = Delta().delete(10)
        assert delta.length() == 10

        delta = Delta().delete(10).delete(10).delete(10)
        assert delta.length() == 30
Exemple #5
0
    def test_insert_lengths(self):
        delta = Delta().insert('test')
        assert delta.length() == 4

        delta = Delta().insert(1)
        assert delta.length() == 1

        delta = Delta().insert({'url': 'https://google.com/'})
        assert delta.length() == 1
Exemple #6
0
    def test_insert_embed_non_integer(self):
        value = {'url': 'https://quilljs.com'}
        attrs = {'alt': 'Quill'}
        delta = Delta().insert(value, attrs)

        assert len(delta.ops) == 1
        assert delta.ops == [Insert(value, attrs)]
Exemple #7
0
    def test_push_consecutive_embeds_with_matching_attributes(self):
        delta = Delta().insert(1, {'alt': 'Description'})
        delta.push({
            'insert': {
                'url': 'http://quilljs.com'
            },
            'attributes': {
                'alt': 'Description'
            }
        })

        assert len(delta.ops) == 2
        assert delta.ops == [
            Insert(1, {'alt': 'Description'}),
            Insert({'url': 'http://quilljs.com'}, {'alt': 'Description'})
        ]
Exemple #8
0
    def test_delta_chain(self):
        delta = (Delta().insert('Hello').insert({
            'image': True
        }).insert('World'))

        assert delta.ops == [
            Insert('Hello', None),
            Insert({'image': True}, None),
            Insert('World', None),
        ]
Exemple #9
0
    def test_delta_delete_text(self):
        delta = (Delta().insert('foo').insert(' ').insert('bar'))

        assert delta.ops == [Insert('foo bar', None)]

        delta = delta.delete(2).delete(2)

        delta.insert(' ')
        delta.insert('baz')

        assert delta.ops == [Insert('foo bar baz', None), Delete(4)]
Exemple #10
0
    def test_delta_insert_text(self):
        delta = Delta()

        assert delta.ops == []

        delta = (delta.insert('Hello',
                              None).insert(' ', None).insert('World!', None))

        assert len(delta.ops) == 1, delta.ops
        assert delta.ops == [Insert('Hello World!', None)]

        delta.insert('\n', None)
        delta.insert('Hello World', None)
        delta.insert('!', None)

        assert len(delta.ops) == 1, delta.ops
        assert delta.ops == [Insert('Hello World!\nHello World!', None)]
Exemple #11
0
 def test_array_of_ops(self, dict_ops, inst_ops):
     delta = Delta(dict_ops)
     assert delta.ops == inst_ops
Exemple #12
0
 def test_empty(self):
     delta = Delta()
     assert len(delta.ops) == 0
Exemple #13
0
    def test_empty_ops(self):
        delta = Delta()
        delta.insert('').delete(0).retain(0)

        assert len(delta.ops) == 0
Exemple #14
0
    def test_push_consecutive_retain_with_not_matching_attributes(self):
        delta = Delta().retain(1, {'bold': True})
        delta.push({'retain': 3})

        assert len(delta.ops) == 2
        assert delta.ops == [Retain(1, {'bold': True}), Retain(3, None)]
Exemple #15
0
 def test_retain_0(self):
     delta = Delta().retain(0)
     assert delta.ops == []
Exemple #16
0
    def test_insert_text_none(self):
        delta = Delta().insert('test', None)

        assert len(delta.ops) == 1
        assert delta.ops == [Insert('test', None)]
Exemple #17
0
 def test_delete_0(self):
     delta = Delta().delete(0)
     assert delta.ops == []
Exemple #18
0
    def test_insert_text_empty_attributes(self):
        delta = Delta().insert('a', {})
        expected = Delta().insert('a')

        assert delta == expected, [delta.ops, expected.ops]
Exemple #19
0
    def test_delta(self, dict_ops, inst_ops):
        original = Delta(inst_ops)
        delta = Delta(original)

        assert delta.ops == original.ops
Exemple #20
0
    def test_push_consecutive_delete(self):
        delta = Delta().delete(2)
        delta.push({'delete': 3})

        assert len(delta.ops) == 1
        assert delta.ops == [Delete(5)]
Exemple #21
0
 def test_push_into_empty(self):
     delta = Delta()
     delta.push({'insert': 'test'})
     assert len(delta.ops) == 1
Exemple #22
0
 def test_retain_length_empty_attributes(self):
     delta = Delta().retain(1, {})
     assert len(delta.ops) == 1
     assert delta.ops == [Retain(1, None)]
Exemple #23
0
 def test_retain_length_attributes(self):
     delta = Delta().retain(1, {'bold': True})
     assert len(delta.ops) == 1
     assert delta.ops == [Retain(1, {'bold': True})]
Exemple #24
0
 def test_retain_length_none(self):
     delta = Delta().retain(2, None)
     assert len(delta.ops) == 1
     assert delta.ops == [Retain(2, None)]
Exemple #25
0
 def test_delta_in_object_form(self, dict_ops, inst_ops):
     delta = Delta({'ops': dict_ops})
     assert delta.ops == inst_ops
Exemple #26
0
    def test_push_consecutive_text_with_matching_attributes(self):
        delta = Delta().insert('a', {'bold': True})
        delta.push({'insert': 'b', 'attributes': {'bold': True}})

        assert len(delta.ops) == 1
        assert delta.ops == [Insert('ab', {'bold': True})]
Exemple #27
0
    def test_push_consecutive_retain_with_matching_attributes(self):
        delta = Delta().retain(1, {'bold': True})
        delta.push({'retain': 3, 'attributes': {'bold': True}})

        assert len(delta.ops) == 1
        assert delta.ops == [Retain(4, {'bold': True})]
Exemple #28
0
    def test_push_consecutive_text_with_not_matching_attributes(self):
        delta = Delta().insert('a', {'bold': True})
        delta.push({'insert': 'b'})

        assert len(delta.ops) == 2
        assert delta.ops == [Insert('a', {'bold': True}), Insert('b', None)]
Exemple #29
0
    def test_push_consecutive_text(self):
        delta = Delta().insert('a')
        delta.push({'insert': 'b'})

        assert len(delta.ops) == 1
        assert delta.ops == [Insert('ab', None)]
Exemple #30
0
 def test_delete_positive(self):
     delta = Delta().delete(1)
     assert len(delta.ops) == 1
     assert delta.ops == [Delete(1)]