diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/display.rs | 28 | ||||
-rw-r--r-- | src/lib.rs | 8 | ||||
-rw-r--r-- | src/parser.rs | 8 | ||||
-rw-r--r-- | src/serialization.rs | 4 |
4 files changed, 26 insertions, 22 deletions
diff --git a/src/display.rs b/src/display.rs index f1b2a76..0c561e8 100644 --- a/src/display.rs +++ b/src/display.rs @@ -138,36 +138,36 @@ mod tests { #[test] fn simple_show() { - assert_eq!(String("foo".to_string()).to_string().as_slice(), + assert_eq!(String("foo".to_string()).to_string(), "\"foo\""); - assert_eq!(Integer(10).to_string().as_slice(), + assert_eq!(Integer(10).to_string(), "10"); - assert_eq!(Float(10.0).to_string().as_slice(), + assert_eq!(Float(10.0).to_string(), "10.0"); - assert_eq!(Float(2.4).to_string().as_slice(), + assert_eq!(Float(2.4).to_string(), "2.4"); - assert_eq!(Boolean(true).to_string().as_slice(), + assert_eq!(Boolean(true).to_string(), "true"); - assert_eq!(Datetime("test".to_string()).to_string().as_slice(), + assert_eq!(Datetime("test".to_string()).to_string(), "test"); - assert_eq!(Array(vec![]).to_string().as_slice(), + assert_eq!(Array(vec![]).to_string(), "[]"); - assert_eq!(Array(vec![Integer(1), Integer(2)]).to_string().as_slice(), + assert_eq!(Array(vec![Integer(1), Integer(2)]).to_string(), "[1, 2]"); } #[test] fn table() { - assert_eq!(Table(map! { }).to_string().as_slice(), + assert_eq!(Table(map! { }).to_string(), ""); - assert_eq!(Table(map! { "test" => Integer(2) }).to_string().as_slice(), + assert_eq!(Table(map! { "test" => Integer(2) }).to_string(), "test = 2\n"); assert_eq!(Table(map! { "test" => Integer(2), "test2" => Table(map! { "test" => String("wut".to_string()) }) - }).to_string().as_slice(), + }).to_string(), "test = 2\n\ \n\ [test2]\n\ @@ -177,7 +177,7 @@ mod tests { "test2" => Table(map! { "test" => String("wut".to_string()) }) - }).to_string().as_slice(), + }).to_string(), "test = 2\n\ \n\ [test2]\n\ @@ -187,7 +187,7 @@ mod tests { "test2" => Array(vec![Table(map! { "test" => String("wut".to_string()) })]) - }).to_string().as_slice(), + }).to_string(), "test = 2\n\ \n\ [[test2]]\n\ @@ -195,7 +195,7 @@ mod tests { assert_eq!(Table(map! { "foo.bar" => Integer(2), "foo\"bar" => Integer(2) - }).to_string().as_slice(), + }).to_string(), "\"foo\\\"bar\" = 2\n\ \"foo.bar\" = 2\n"); } @@ -34,10 +34,9 @@ //! //! [1]: https://github.com/mojombo/toml //! [2]: https://github.com/BurntSushi/toml-test -//! #![doc(html_root_url = "http://alexcrichton.com/toml-rs")] -#![feature(collections, core)] +#![feature(core)] #![deny(missing_docs)] #![cfg_attr(test, deny(warnings))] @@ -209,7 +208,10 @@ impl FromStr for Value { type Err = Vec<ParserError>; fn from_str(s: &str) -> Result<Value, Vec<ParserError>> { let mut p = Parser::new(s); - p.parse().map(Value::Table).ok_or(p.errors) + match p.parse().map(Value::Table) { + Some(n) => Ok(n), + None => Err(p.errors), + } } } diff --git a/src/parser.rs b/src/parser.rs index 7c991c4..abb4c5c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,3 +1,4 @@ +use std::ascii::AsciiExt; use std::char; use std::collections::BTreeMap; use std::error::Error; @@ -385,8 +386,9 @@ impl<'a> Parser<'a> { Some((pos, c @ 'u')) | Some((pos, c @ 'U')) => { let len = if c == 'u' {4} else {8}; - let num = if me.input.is_char_boundary(pos + 1 + len) { - &me.input[pos + 1 .. pos + 1 + len] + let num = &me.input[pos+1..]; + let num = if num.len() >= len && num.is_ascii() { + &num[..len] } else { "invalid" }; @@ -614,7 +616,7 @@ impl<'a> Parser<'a> { lo: start, hi: next, desc: format!("unexpected character: `{}`", - rest.char_at(0)), + rest.chars().next().unwrap()), }); None } diff --git a/src/serialization.rs b/src/serialization.rs index a7ddaf3..03f9de3 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -1062,7 +1062,7 @@ mod tests { match a { Ok(..) => panic!("should not have decoded"), Err(e) => { - assert_eq!(format!("{}", e).as_slice(), + assert_eq!(format!("{}", e), "expected a value of type `integer`, but \ found a value of type `float` for the key `bar`"); } @@ -1080,7 +1080,7 @@ mod tests { match a { Ok(..) => panic!("should not have decoded"), Err(e) => { - assert_eq!(format!("{}", e).as_slice(), + assert_eq!(format!("{}", e), "expected a value of type `integer` for the key `bar`"); } } |