# Test operations where the spans overlap with the existing ones. Only a single
# update is applied at a time.

apply
set [b,h):A
----
added [b,h):A


# Check that writing a span with a partial overlap first deletes the existing
# entry and adds three new ones.
apply
set [d,f):B
----
deleted [b,h)
added [b,d):A
added [d,f):B
added [f,h):A

overlapping span=[b,h)
----
[b,d):A
[d,f):B
[f,h):A

interned
----
A (refs = 2)
B (refs = 1)


# Check that writing a span that partially overlaps with multiple existing
# entries deletes all of them, and re-adds the right non-overlapping fragments
# with the right configs.
apply
set [c,e):C
----
deleted [b,d)
deleted [d,f)
added [b,c):A
added [c,e):C
added [e,f):B

overlapping span=[b,h)
----
[b,c):A
[c,e):C
[e,f):B
[f,h):A

interned
----
A (refs = 2)
B (refs = 1)
C (refs = 1)

# Check that when a span being written to entirely envelopes an existing entry,
# that entry is deleted in its entirety.
apply
delete [d,g)
----
deleted [c,e)
deleted [e,f)
deleted [f,h)
added [c,d):C
added [g,h):A

overlapping span=[b,h)
----
[b,c):A
[c,d):C
[g,h):A

interned
----
A (refs = 2)
C (refs = 1)

# Validate that the right split points (span start keys) are surfaced.
needs-split span=[b,h)
----
true

compute-split span=[b,h)
----
key=c

apply
set [b,g):B
----
deleted [b,c)
deleted [c,d)
added [b,g):B

overlapping span=[b,h)
----
[b,g):B
[g,h):A

interned
----
A (refs = 1)
B (refs = 1)

needs-split span=[b,h)
----
true

compute-split span=[b,h)
----
key=g

needs-split span=[h,z)
----
false
