diff --git a/saphyr/.travis.yml b/saphyr/.travis.yml index 89e430a..e203825 100644 --- a/saphyr/.travis.yml +++ b/saphyr/.travis.yml @@ -1,6 +1,6 @@ language: rust rust: - - 1.8.0 + - 1.9.0 - 1.16.0 - beta - nightly diff --git a/saphyr/Cargo.toml b/saphyr/Cargo.toml index c4a4780..1e63db6 100644 --- a/saphyr/Cargo.toml +++ b/saphyr/Cargo.toml @@ -11,3 +11,6 @@ repository = "https://github.com/chyh1990/yaml-rust" [dependencies] clippy = { version = "^0.*", optional = true } linked-hash-map = ">=0.0.9, <0.4" + +[dev-dependencies] +quickcheck = "0.4" diff --git a/saphyr/src/emitter.rs b/saphyr/src/emitter.rs index cd83994..fa8a712 100644 --- a/saphyr/src/emitter.rs +++ b/saphyr/src/emitter.rs @@ -263,7 +263,7 @@ fn need_quotes(string: &str) -> bool { || need_quotes_spaces(string) || string.contains(|character: char| { match character { - ':' | '{' | '}' | '[' | ']' | ',' | '&' | '*' | '#' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@' | '`' | '\\' | '\0' ... '\x06' | '\t' | '\n' | '\r' | '\x0e' ... '\x1a' | '\x1c' ... '\x1f' => true, + ':' | '{' | '}' | '[' | ']' | ',' | '&' | '*' | '#' | '?' | '|' | '-' | '<' | '>' | '=' | '!' | '%' | '@' | '`' | '\"' | '\'' | '\\' | '\0' ... '\x06' | '\t' | '\n' | '\r' | '\x0e' ... '\x1a' | '\x1c' ... '\x1f' => true, _ => false, } }) diff --git a/saphyr/tests/quickcheck.rs b/saphyr/tests/quickcheck.rs new file mode 100644 index 0000000..62db056 --- /dev/null +++ b/saphyr/tests/quickcheck.rs @@ -0,0 +1,21 @@ +extern crate yaml_rust; +#[macro_use] +extern crate quickcheck; + +use quickcheck::TestResult; +use yaml_rust::{Yaml, YamlLoader, YamlEmitter}; +use std::error::Error; + +quickcheck! { + fn test_check_weird_keys(xs: Vec) -> TestResult { + let mut out_str = String::new(); + { + let mut emitter = YamlEmitter::new(&mut out_str); + emitter.dump(&Yaml::Array(xs.into_iter().map(|s| Yaml::String(s)).collect())).unwrap(); + } + if let Err(err) = YamlLoader::load_from_str(&out_str) { + return TestResult::error(err.description()); + } + return TestResult::passed(); + } +} \ No newline at end of file