From 0b38568015a4153dc953a84bd54eb0e305675862 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Wed, 5 Jul 2017 12:04:00 +0900 Subject: [PATCH] Previous behaviour of populate was correct so reverting back to it --- components/content/src/sorting.rs | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/components/content/src/sorting.rs b/components/content/src/sorting.rs index 77271774..b81b4091 100644 --- a/components/content/src/sorting.rs +++ b/components/content/src/sorting.rs @@ -43,20 +43,20 @@ pub fn populate_previous_and_next_pages(input: Vec) -> Vec { let mut new_page = input[i].clone(); if i > 0 { - let mut previous_page = input[i - 1].clone(); - // Remove prev/next otherwise we serialise the whole thing... - previous_page.previous = None; - previous_page.next = None; - new_page.previous = Some(Box::new(previous_page)); - } - - if i < input.len() - 1 { - let mut next_page = input[i + 1].clone(); + let mut next_page = input[i - 1].clone(); // Remove prev/next otherwise we serialise the whole thing... next_page.previous = None; next_page.next = None; new_page.next = Some(Box::new(next_page)); } + + if i < input.len() - 1 { + let mut previous_page = input[i + 1].clone(); + // Remove prev/next otherwise we serialise the whole thing... + previous_page.previous = None; + previous_page.next = None; + new_page.previous = Some(Box::new(previous_page)); + } res.push(new_page); } @@ -164,17 +164,17 @@ mod tests { ]; let pages = populate_previous_and_next_pages(input); - assert!(pages[0].clone().previous.is_none()); - assert!(pages[0].clone().next.is_some()); - assert_eq!(pages[0].clone().next.unwrap().meta.order.unwrap(), 2); + assert!(pages[0].clone().next.is_none()); + assert!(pages[0].clone().previous.is_some()); + assert_eq!(pages[0].clone().previous.unwrap().meta.order.unwrap(), 2); assert!(pages[1].clone().next.is_some()); assert!(pages[1].clone().previous.is_some()); - assert_eq!(pages[1].clone().previous.unwrap().meta.order.unwrap(), 1); - assert_eq!(pages[1].clone().next.unwrap().meta.order.unwrap(), 3); + assert_eq!(pages[1].clone().previous.unwrap().meta.order.unwrap(), 3); + assert_eq!(pages[1].clone().next.unwrap().meta.order.unwrap(), 1); - assert!(pages[2].clone().next.is_none()); - assert!(pages[2].clone().previous.is_some()); - assert_eq!(pages[2].clone().previous.unwrap().meta.order.unwrap(), 2); + assert!(pages[2].clone().next.is_some()); + assert!(pages[2].clone().previous.is_none()); + assert_eq!(pages[2].clone().next.unwrap().meta.order.unwrap(), 2); } }