diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-27 19:29:58 -0800 | 
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-27 19:29:58 -0800 | 
| commit | 482752b5f4c7bbb3e1b5fce28ec67720912ffb51 (patch) | |
| tree | 6ccad51d7458b41d37619a8fdd42d2a176224a3f /tests | |
| parent | 909a85069b866ab7384eda20a3ff7d751d8c2235 (diff) | |
| download | milf-rs-482752b5f4c7bbb3e1b5fce28ec67720912ffb51.tar.gz milf-rs-482752b5f4c7bbb3e1b5fce28ec67720912ffb51.zip  | |
Migrate to as many stable functions as possible
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/valid.rs | 22 | 
1 files changed, 8 insertions, 14 deletions
diff --git a/tests/valid.rs b/tests/valid.rs index 72e9d94..628130e 100644 --- a/tests/valid.rs +++ b/tests/valid.rs @@ -1,7 +1,6 @@  extern crate "rustc-serialize" as rustc_serialize;  extern crate toml; -use std::num::strconv;  use std::collections::BTreeMap;  use rustc_serialize::json::Json; @@ -11,27 +10,22 @@ use toml::Value::{Table, Integer, Float, Boolean, Datetime, Array};  fn to_json(toml: Value) -> Json {      fn doit(s: &str, json: Json) -> Json {          let mut map = BTreeMap::new(); -        map.insert("type".to_string(), Json::String(s.to_string())); -        map.insert("value".to_string(), json); +        map.insert(format!("{}", "type"), Json::String(format!("{}", s))); +        map.insert(format!("{}", "value"), json);          Json::Object(map)      }      match toml {          Value::String(s) => doit("string", Json::String(s)), -        Integer(i) => doit("integer", Json::String(i.to_string())), +        Integer(i) => doit("integer", Json::String(format!("{}", i))),          Float(f) => doit("float", Json::String({ -            let (bytes, _) = -                strconv::float_to_str_bytes_common(f, 10, true, -                                                   strconv::SignFormat::SignNeg, -                                                   strconv::SignificantDigits::DigMax(15), -                                                   strconv::ExponentFormat::ExpNone, -                                                   false); -            let s = String::from_utf8(bytes).unwrap(); -            if s.as_slice().contains(".") {s} else {format!("{}.0", s)} +            let s = format!("{:.15}", f); +            let s = format!("{}", s.trim_right_matches('0')); +            if s.ends_with(".") {format!("{}0", s)} else {s}          })), -        Boolean(b) => doit("bool", Json::String(b.to_string())), +        Boolean(b) => doit("bool", Json::String(format!("{}", b))),          Datetime(s) => doit("datetime", Json::String(s)),          Array(arr) => { -            let is_table = match arr.as_slice().first() { +            let is_table = match arr.first() {                  Some(&Table(..)) => true,                  _ => false,              };  |