Fixed tests, merged lookup functions
This commit is contained in:
parent
2047fa3bc9
commit
13cc8a9201
19
src/toml.rs
19
src/toml.rs
|
@ -55,7 +55,7 @@ pub use serialization::{InvalidMapKeyLocation, InvalidMapKeyType};
|
||||||
mod parser;
|
mod parser;
|
||||||
mod show;
|
mod show;
|
||||||
mod serialization;
|
mod serialization;
|
||||||
|
#[cfg(test)]mod test;
|
||||||
/// Representation of a TOML value.
|
/// Representation of a TOML value.
|
||||||
#[deriving(PartialEq, Clone)]
|
#[deriving(PartialEq, Clone)]
|
||||||
#[allow(missing_doc)]
|
#[allow(missing_doc)]
|
||||||
|
@ -172,18 +172,8 @@ impl Value {
|
||||||
/// assert_eq!(no_bar.is_none(), true);
|
/// assert_eq!(no_bar.is_none(), true);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn lookup<'a>(&'a self, path: &'a str) -> Option<&'a Value> {
|
pub fn lookup<'a>(&'a self, path: &'a str) -> Option<&'a Value> {
|
||||||
Value::lookup_path(self, path.split('.'))
|
let mut cur_value = self;
|
||||||
}
|
for key in path.split('.') {
|
||||||
|
|
||||||
// Performs actual traverse starting with value
|
|
||||||
//
|
|
||||||
// For arrays tries to convert key to uint and retrieve
|
|
||||||
// corresponding element
|
|
||||||
fn lookup_path<'a, I:Iterator<&'a str>>(value: &'a Value,
|
|
||||||
components: I) -> Option<&'a Value> {
|
|
||||||
let mut cur_value: &'a Value = value;
|
|
||||||
let mut iter = components;
|
|
||||||
for key in iter {
|
|
||||||
match cur_value {
|
match cur_value {
|
||||||
&Table(ref hm) => {
|
&Table(ref hm) => {
|
||||||
match hm.find_equiv(&key) {
|
match hm.find_equiv(&key) {
|
||||||
|
@ -212,9 +202,8 @@ impl FromStr for Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod tests {
|
||||||
use super::Value;
|
use super::Value;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue