From 84ffcafbc2f9e88fee6dc75fd0a7ce5ae591bd87 Mon Sep 17 00:00:00 2001 From: Tom Parker Date: Sun, 12 Mar 2017 16:02:18 +0000 Subject: [PATCH 1/3] Add quickcheck to find broken exports --- saphyr/Cargo.toml | 3 +++ saphyr/tests/quickcheck.rs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 saphyr/tests/quickcheck.rs 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/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 From 21049c8d6a4f9318f9c3b657fa5712a6c7d282a6 Mon Sep 17 00:00:00 2001 From: Tom Parker Date: Sun, 12 Mar 2017 16:02:47 +0000 Subject: [PATCH 2/3] Add quoting for " and ' --- saphyr/src/emitter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saphyr/src/emitter.rs b/saphyr/src/emitter.rs index 308bd93..0d2defa 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, } }) From dd3d169c1a1e7fde026d4b7710f39d50e4661e05 Mon Sep 17 00:00:00 2001 From: Tom Parker Date: Mon, 8 May 2017 18:31:06 +0100 Subject: [PATCH 3/3] Quickcheck needs Rust at least 1.9 --- saphyr/.travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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