Closed
Description
Hello!
I see some garbage in memory:
use super::yaml_rust::{YamlLoader, Yaml};
use std::collections::HashMap;
#[test]
fn test_yaml() {
let test_data = r#"
Property1:
data: Value1
Property2:
data: Value2
Property3:
data: Value3
"#;
let mut check_data = HashMap::new();
check_data.insert("Property1","Value1");
check_data.insert("Property2","Value2");
check_data.insert("Property3","Value3");
let scheme = &(YamlLoader::load_from_str(test_data).unwrap() as Vec<Yaml>)[0];
for (key, value) in {
if let Yaml::Hash(ref x) = *scheme {
x // if write here "x.clone()", OK
} else {
panic!("Bad format")
}
} {
println!("{:?}: {:?};", key, value);
if check_data[key.as_str().unwrap()] != value["data"].as_str().unwrap() {
panic!("\nkey: {:?} ,data: {:?} ≠ {:?}\n",
key.as_str().unwrap(),
check_data[key.as_str().unwrap()],
value["data"].as_str().unwrap()
);
}
}
}
I expect correct return (like with rust 1.11), but I have panic:
Rust 1.12
$ rustup run stable cargo test test_yaml
Compiling yaml-rust v0.3.3 (https://github.com/chyh1990/yaml-rust.git#f7d2897b)
Compiling …
Finished debug [unoptimized + debuginfo] target(s) in 6.13 secs
Running target/debug/…
running 1 test
test test_yaml ... FAILED
failures:
---- test_yaml stdout ----
String("Property1"): Hash({String("data"): String("Value1")});
String("Property2"): Hash({String("data"): String("Value2")});
String("String(\"3"): Hash({String("data"): String("datang")});
thread 'test_yaml' panicked at 'no entry found for key', ../src/libcore/option.rs:700
note: Run with `RUST_BACKTRACE=1` for a backtrace.
failures:
scheme::test::test_yaml
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
error: test failed
Rust 1.11
$ rustup run 1.11.0 cargo test test_yaml
Compiling yaml-rust v0.3.3 (https://github.com/chyh1990/yaml-rust.git#f7d2897b)
Compiling …
Running target/debug/…
running 1 test
test test_yaml ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
Data corrupted always in last record.
Thanks!