aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/display.rs28
-rw-r--r--src/lib.rs8
-rw-r--r--src/parser.rs8
-rw-r--r--src/serialization.rs4
-rw-r--r--tests/valid.rs2
5 files changed, 27 insertions, 23 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");
}
diff --git a/src/lib.rs b/src/lib.rs
index afc102d..5c5fa91 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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`");
}
}
diff --git a/tests/valid.rs b/tests/valid.rs
index 42cc9f4..5693492 100644
--- a/tests/valid.rs
+++ b/tests/valid.rs
@@ -43,7 +43,7 @@ fn run(toml: &str, json: &str) {
let table = p.parse();
assert!(p.errors.len() == 0, "had_errors: {:?}",
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)>>());
assert!(table.is_some());
let toml = Table(table.unwrap());