if (start < 0) start = llen+start;
if (end < 0) end = llen+end;
if (start < 0) start = 0;
- if (end < 0) end = 0;
- /* indexes sanity checks */
+ /* Invariant: start >= 0, so this test will be true when end < 0.
+ * The range is empty when start > end or start >= length. */
if (start > end || start >= llen) {
/* Out of range start or start > end result in empty list */
addReply(c,shared.emptymultibulk);
if (start < 0) start = llen+start;
if (end < 0) end = llen+end;
if (start < 0) start = 0;
- if (end < 0) end = 0;
- /* indexes sanity checks */
+ /* Invariant: start >= 0, so this test will be true when end < 0.
+ * The range is empty when start > end or start >= length. */
if (start > end || start >= llen) {
/* Out of range start or start > end result in empty list */
ltrim = llen;
create_$type mylist {1 2 3}
assert_equal {1 2 3} [r lrange mylist -1000 1000]
}
+
+ test "LRANGE out of range negative end index - $type" {
+ create_$type mylist {1 2 3}
+ assert_equal {1} [r lrange mylist 0 -3]
+ assert_equal {} [r lrange mylist 0 -4]
+ }
}
test {LRANGE against non existing key} {
assert_equal {1 2 3 4 5} [trim_list $type 0 10]
}
+ test "LTRIM out of range negative end index - $type" {
+ assert_equal {1} [trim_list $type 0 -5]
+ assert_equal {} [trim_list $type 0 -6]
+ }
+
tags {"slow"} {
test "LTRIM stress testing - $type" {
set mylist {}