This commit is contained in:
freestrings 2020-02-16 13:17:44 +09:00
commit b736c962d2
2 changed files with 12 additions and 2 deletions

View File

@ -439,9 +439,9 @@ fn walk<'a, F>(vec: &[&'a Value], tmp: &mut Vec<&'a Value>, fun: &F)
fn abs_index(n: isize, len: usize) -> usize {
if n < 0_isize {
(n + len as isize) as usize
(n + len as isize).max(0) as usize
} else {
n as usize
n.min(len as isize) as usize
}
}

View File

@ -602,6 +602,16 @@ fn range() {
json!(["first", "second", "third", "forth", "fifth"]),
json!(["first", "third"]),
);
select_and_then_compare(
"$[-4:]",
json!(["first", "second", "third"]),
json!(["first", "second", "third"]),
);
select_and_then_compare(
"$[:4]",
json!(["first", "second", "third"]),
json!(["first", "second", "third"]),
);
}
#[test]