From 74a9b844cadf290dc972426193fc3841f63a6263 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 11 Feb 2016 15:15:31 +0100 Subject: [PATCH] Add debugging output in tests --- libimagstore/Cargo.toml | 4 +++- libimagstore/src/lib.rs | 2 +- libimagstore/src/store.rs | 21 ++++++++++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libimagstore/Cargo.toml b/libimagstore/Cargo.toml index acfa7e80..624e129e 100644 --- a/libimagstore/Cargo.toml +++ b/libimagstore/Cargo.toml @@ -4,9 +4,9 @@ version = "0.1.0" authors = ["Matthias Beyer "] [dependencies] -log = "0.3.5" fs2 = "0.2.2" glob = "0.2.10" +log = "0.3.5" regex = "0.1.47" semver = "0.2" toml = "0.1.25" @@ -14,3 +14,5 @@ version = "2.0.1" [dev-dependencies] tempdir = "0.3.4" +env_logger = "0.3" + diff --git a/libimagstore/src/lib.rs b/libimagstore/src/lib.rs index b0fb2286..97b7a52c 100644 --- a/libimagstore/src/lib.rs +++ b/libimagstore/src/lib.rs @@ -1,5 +1,5 @@ -#[macro_use] extern crate version; #[macro_use] extern crate log; +#[macro_use] extern crate version; extern crate fs2; extern crate glob; extern crate regex; diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 68eb300e..149d5b75 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -492,12 +492,14 @@ impl EntryHeader { return Err(tokens.err().unwrap()); } let tokens = tokens.unwrap(); + debug!("tokens = {:?}", tokens); let destination = tokens.iter().last(); if destination.is_none() { return Err(StoreError::new(StoreErrorKind::HeaderPathSyntaxError, None)); } let destination = destination.unwrap(); + debug!("destination = {:?}", destination); let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens let mut table = Value::Table(self.toml.clone()); // oh fuck, but yes, we clone() here @@ -506,6 +508,7 @@ impl EntryHeader { return Err(value.err().unwrap()); } let mut value = value.unwrap(); + debug!("walked value = {:?}", value); match destination { &Token::Key(ref s) => { // if the destination shall be an map key->value @@ -514,13 +517,17 @@ impl EntryHeader { * Put it in there if we have a map */ &mut Value::Table(ref mut t) => { + debug!("Matched Key->Table"); return Ok(t.insert(s.clone(), v)); } /* * Fail if there is no map here */ - _ => return Err(StoreError::new(StoreErrorKind::HeaderPathTypeFailure, None)), + _ => { + debug!("Matched Key->NON-Table"); + return Err(StoreError::new(StoreErrorKind::HeaderPathTypeFailure, None)); + } } }, @@ -531,21 +538,27 @@ impl EntryHeader { * Put it in there if we have an array */ &mut Value::Array(ref mut a) => { + debug!("Matched Index->Array"); a.push(v); // push to the end of the array // if the index is inside the array, we swap-remove the element at this // index - if a.len() < i { + if a.len() > i { + debug!("Swap-Removing in Array {:?}[{:?}] <- {:?}", a, i, a[a.len()-1]); return Ok(Some(a.swap_remove(i))); } + debug!("Appended"); return Ok(None); }, /* * Fail if there is no array here */ - _ => return Err(StoreError::new(StoreErrorKind::HeaderPathTypeFailure, None)), + _ => { + debug!("Matched Index->NON-Array"); + return Err(StoreError::new(StoreErrorKind::HeaderPathTypeFailure, None)); + }, } }, } @@ -828,6 +841,8 @@ impl Entry { #[cfg(test)] mod test { + extern crate env_logger; + use std::collections::BTreeMap; use super::EntryHeader; use super::Token;