Reduce usage of unstable features

This commit is contained in:
Alex Crichton 2015-03-09 11:09:07 -07:00
parent e14c2052b7
commit ff3bb7d255
5 changed files with 27 additions and 23 deletions

View file

@ -138,36 +138,36 @@ mod tests {
#[test] #[test]
fn simple_show() { fn simple_show() {
assert_eq!(String("foo".to_string()).to_string().as_slice(), assert_eq!(String("foo".to_string()).to_string(),
"\"foo\""); "\"foo\"");
assert_eq!(Integer(10).to_string().as_slice(), assert_eq!(Integer(10).to_string(),
"10"); "10");
assert_eq!(Float(10.0).to_string().as_slice(), assert_eq!(Float(10.0).to_string(),
"10.0"); "10.0");
assert_eq!(Float(2.4).to_string().as_slice(), assert_eq!(Float(2.4).to_string(),
"2.4"); "2.4");
assert_eq!(Boolean(true).to_string().as_slice(), assert_eq!(Boolean(true).to_string(),
"true"); "true");
assert_eq!(Datetime("test".to_string()).to_string().as_slice(), assert_eq!(Datetime("test".to_string()).to_string(),
"test"); "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]"); "[1, 2]");
} }
#[test] #[test]
fn table() { 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"); "test = 2\n");
assert_eq!(Table(map! { assert_eq!(Table(map! {
"test" => Integer(2), "test" => Integer(2),
"test2" => Table(map! { "test2" => Table(map! {
"test" => String("wut".to_string()) "test" => String("wut".to_string())
}) })
}).to_string().as_slice(), }).to_string(),
"test = 2\n\ "test = 2\n\
\n\ \n\
[test2]\n\ [test2]\n\
@ -177,7 +177,7 @@ mod tests {
"test2" => Table(map! { "test2" => Table(map! {
"test" => String("wut".to_string()) "test" => String("wut".to_string())
}) })
}).to_string().as_slice(), }).to_string(),
"test = 2\n\ "test = 2\n\
\n\ \n\
[test2]\n\ [test2]\n\
@ -187,7 +187,7 @@ mod tests {
"test2" => Array(vec![Table(map! { "test2" => Array(vec![Table(map! {
"test" => String("wut".to_string()) "test" => String("wut".to_string())
})]) })])
}).to_string().as_slice(), }).to_string(),
"test = 2\n\ "test = 2\n\
\n\ \n\
[[test2]]\n\ [[test2]]\n\
@ -195,7 +195,7 @@ mod tests {
assert_eq!(Table(map! { assert_eq!(Table(map! {
"foo.bar" => Integer(2), "foo.bar" => Integer(2),
"foo\"bar" => Integer(2) "foo\"bar" => Integer(2)
}).to_string().as_slice(), }).to_string(),
"\"foo\\\"bar\" = 2\n\ "\"foo\\\"bar\" = 2\n\
\"foo.bar\" = 2\n"); \"foo.bar\" = 2\n");
} }

View file

@ -34,10 +34,9 @@
//! //!
//! [1]: https://github.com/mojombo/toml //! [1]: https://github.com/mojombo/toml
//! [2]: https://github.com/BurntSushi/toml-test //! [2]: https://github.com/BurntSushi/toml-test
//!
#![doc(html_root_url = "http://alexcrichton.com/toml-rs")] #![doc(html_root_url = "http://alexcrichton.com/toml-rs")]
#![feature(collections, core)] #![feature(core)]
#![deny(missing_docs)] #![deny(missing_docs)]
#![cfg_attr(test, deny(warnings))] #![cfg_attr(test, deny(warnings))]
@ -209,7 +208,10 @@ impl FromStr for Value {
type Err = Vec<ParserError>; type Err = Vec<ParserError>;
fn from_str(s: &str) -> Result<Value, Vec<ParserError>> { fn from_str(s: &str) -> Result<Value, Vec<ParserError>> {
let mut p = Parser::new(s); 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),
}
} }
} }

View file

@ -1,3 +1,4 @@
use std::ascii::AsciiExt;
use std::char; use std::char;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::error::Error; use std::error::Error;
@ -385,8 +386,9 @@ impl<'a> Parser<'a> {
Some((pos, c @ 'u')) | Some((pos, c @ 'u')) |
Some((pos, c @ 'U')) => { Some((pos, c @ 'U')) => {
let len = if c == 'u' {4} else {8}; let len = if c == 'u' {4} else {8};
let num = if me.input.is_char_boundary(pos + 1 + len) { let num = &me.input[pos+1..];
&me.input[pos + 1 .. pos + 1 + len] let num = if num.len() >= len && num.is_ascii() {
&num[..len]
} else { } else {
"invalid" "invalid"
}; };
@ -614,7 +616,7 @@ impl<'a> Parser<'a> {
lo: start, lo: start,
hi: next, hi: next,
desc: format!("unexpected character: `{}`", desc: format!("unexpected character: `{}`",
rest.char_at(0)), rest.chars().next().unwrap()),
}); });
None None
} }

View file

@ -1062,7 +1062,7 @@ mod tests {
match a { match a {
Ok(..) => panic!("should not have decoded"), Ok(..) => panic!("should not have decoded"),
Err(e) => { Err(e) => {
assert_eq!(format!("{}", e).as_slice(), assert_eq!(format!("{}", e),
"expected a value of type `integer`, but \ "expected a value of type `integer`, but \
found a value of type `float` for the key `bar`"); found a value of type `float` for the key `bar`");
} }
@ -1080,7 +1080,7 @@ mod tests {
match a { match a {
Ok(..) => panic!("should not have decoded"), Ok(..) => panic!("should not have decoded"),
Err(e) => { Err(e) => {
assert_eq!(format!("{}", e).as_slice(), assert_eq!(format!("{}", e),
"expected a value of type `integer` for the key `bar`"); "expected a value of type `integer` for the key `bar`");
} }
} }

View file

@ -43,7 +43,7 @@ fn run(toml: &str, json: &str) {
let table = p.parse(); let table = p.parse();
assert!(p.errors.len() == 0, "had_errors: {:?}", assert!(p.errors.len() == 0, "had_errors: {:?}",
p.errors.iter().map(|e| { p.errors.iter().map(|e| {
(e.desc.clone(), toml.slice(e.lo - 5, e.hi + 5)) (e.desc.clone(), &toml[e.lo - 5..e.hi + 5])
}).collect::<Vec<(String, &str)>>()); }).collect::<Vec<(String, &str)>>());
assert!(table.is_some()); assert!(table.is_some());
let toml = Table(table.unwrap()); let toml = Table(table.unwrap());