define
a.SET.1:1 b.SET.2:2
c.SET.3:3 d.SET.4:4
dd.SET.5:5
----

iter
seek-ge a
next
next
next
next
next
----
a#1,1:1
b#2,1:2
c#3,1:3
d#4,1:4
dd#5,1:5
.

iter
seek-ge b
next
next
next
next
----
b#2,1:2
c#3,1:3
d#4,1:4
dd#5,1:5
.

iter
seek-ge c
next
next
next
----
c#3,1:3
d#4,1:4
dd#5,1:5
.

iter
seek-ge d
next
next
----
d#4,1:4
dd#5,1:5
.

iter
seek-ge dd
next
----
dd#5,1:5
.

iter
seek-ge e
----
.

iter
seek-lt a
----
.

iter
seek-lt b
prev
----
a#1,1:1
.

iter
seek-lt c
prev
prev
----
b#2,1:2
a#1,1:1
.

iter
seek-lt d
prev
prev
prev
----
c#3,1:3
b#2,1:2
a#1,1:1
.

iter
seek-lt e
prev
prev
prev
prev
prev
----
dd#5,1:5
d#4,1:4
c#3,1:3
b#2,1:2
a#1,1:1
.

iter
seek-prefix-ge a
next
----
a#1,1:1
b#2,1:2

iter
seek-prefix-ge d
next
next
----
d#4,1:4
dd#5,1:5
.

iter
seek-prefix-ge dd
next
----
dd#5,1:5
.

iter
seek-prefix-ge d
next
prev
prev
----
d#4,1:4
dd#5,1:5
d#4,1:4
c#3,1:3

iter
seek-prefix-ge d
prev
----
d#4,1:4
c#3,1:3

iter
seek-prefix-ge dd
prev
----
dd#5,1:5
d#4,1:4

iter lower=a
seek-ge a
first
----
a#1,1:1
a#1,1:1

iter
set-bounds lower=a
seek-ge a
first
----
a#1,1:1
a#1,1:1

iter
set-bounds lower=dd upper=f
seek-lt dc
set-bounds lower=a upper=f
seek-lt dc
prev
prev
prev
prev
----
.
d#4,1:4
c#3,1:3
b#2,1:2
a#1,1:1
.

iter
set-bounds lower=a upper=b
seek-ge c
set-bounds lower=a upper=f
seek-ge c
next
next
next
----
.
c#3,1:3
d#4,1:4
dd#5,1:5
.

# levelIter trims lower/upper bound in the options passed to sstables.
load a
----
[,]

load b lower=aa upper=bb
----
[aa,]

load b lower=aa upper=c
----
[aa,]

load c lower=b upper=d
----
[,d]

load c lower=b upper=e
----
[,]

# levelIter only checks lower bound when loading sstables.
iter lower=b
seek-ge a
first
----
a#1,1:1
a#1,1:1

iter lower=c
seek-ge a
first
----
c#3,1:3
c#3,1:3

iter
set-bounds lower=b
seek-ge a
first
----
a#1,1:1
a#1,1:1

iter
set-bounds lower=c
seek-ge a
first
----
c#3,1:3
c#3,1:3

# levelIter only checks lower bound when loading sstables.
iter lower=d
seek-ge a
first
----
c#3,1:3
c#3,1:3

iter lower=e
seek-ge a
first
----
.
.

iter upper=e
seek-lt e
last
----
dd#5,1:5
dd#5,1:5

iter
set-bounds lower=d
seek-ge a
first
----
c#3,1:3
c#3,1:3

iter
set-bounds lower=e
seek-ge a
first
----
.
.

iter
set-bounds upper=e
seek-lt e
last
----
dd#5,1:5
dd#5,1:5

# levelIter only checks upper bound when loading sstables.
iter upper=d
seek-lt e
last
----
d#4,1:4
d#4,1:4

iter upper=c
seek-lt e
last
----
b#2,1:2
b#2,1:2

iter
set-bounds upper=d
seek-lt e
last
----
d#4,1:4
d#4,1:4

iter
set-bounds upper=c
seek-lt e
last
----
b#2,1:2
b#2,1:2

# levelIter only checks upper bound when loading sstables.
iter upper=b
seek-lt e
last
----
b#2,1:2
b#2,1:2

iter upper=a
seek-lt e
last
----
.
.

iter upper=dd
seek-prefix-ge d
next
----
d#4,1:4
.

iter
set-bounds upper=b
seek-lt e
last
----
b#2,1:2
b#2,1:2

iter
set-bounds upper=a
seek-lt e
last
----
.
.

iter
set-bounds upper=dd
seek-prefix-ge d
next
----
d#4,1:4
.

iter upper=e
seek-prefix-ge d
next
next
----
d#4,1:4
dd#5,1:5
.

iter lower=dd
seek-prefix-ge d
next
----
dd#5,1:5
.

iter lower=d
seek-prefix-ge dd
prev
----
dd#5,1:5
d#4,1:4

iter lower=c
seek-prefix-ge dd
prev
----
dd#5,1:5
d#4,1:4

iter lower=c
seek-lt c
----
.

iter
seek-lt c
set-bounds lower=c
seek-lt c
----
b#2,1:2
.

iter upper=c
seek-ge c
----
.

iter
seek-ge c
set-bounds upper=c
seek-ge c
----
c#3,1:3
.

# The behavior of next/prev after set-bounds is undefined. We're just
# asserting the current behavior.

# The lower bound is beyond the current table's bounds.

iter
seek-ge c
set-bounds lower=e
next
----
c#3,1:3
.

# The lower bound lies within the current table's bounds.

iter
seek-ge c
set-bounds lower=d
next
----
c#3,1:3
d#4,1:4

# The upper bound is before the current table's bounds.

iter
seek-ge d
set-bounds upper=c
prev
----
d#4,1:4
.

# The upper bound lies within the current table's bounds.

iter
seek-ge d
set-bounds upper=cc
prev
----
d#4,1:4
c#3,1:3

# Setting bounds should update the table bounds, allowing a subsequent
# seek-ge/seek-lt to see the boundary keys.

iter
seek-ge d
set-bounds lower=cc
seek-lt d
----
d#4,1:4
.

iter
seek-ge c
set-bounds upper=cc
seek-ge d
----
c#3,1:3
.
