| 1 | // Allow unstable items until Rust hits 1.0 |
| 2 | |
| 3 | extern crate yamlrust-analyzer cargo yaml 0.3.0 yaml/; |
| 4 | |
| 5 | use yamlrust-analyzer cargo yaml 0.3.0 crate/::constructorrust-analyzer cargo yaml 0.3.0 constructor/::YamlStandardDatarust-analyzer cargo yaml 0.3.0 constructor/YamlStandardData#; |
| 6 | use yamlrust-analyzer cargo yaml 0.3.0 crate/::ffirust-analyzer cargo yaml 0.3.0 ffi/::YamlEncodingrust-analyzer cargo yaml 0.3.0 ffi/YamlEncoding#; |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#; |
| 8 | |
| 9 | macro_rules! test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!{ |
| 10 | ($filename: expr, $expected: expr) => ( |
| 11 | test_file!(yaml::ffi::YamlEncoding::YamlUtf8Encoding, $filename, $expected) |
| 12 | ) |
| 13 | } |
| 14 | |
| 15 | macro_rules! test_filerust-analyzer cargo yaml 0.3.0 test_file!{ |
| 16 | ($encoding: expr, $filename: expr, $expected: expr) => ( |
| 17 | { |
| 18 | let data: &[u8] = include_bytes!($filename); |
| 19 | let mut reader = Cursor::new(data); |
| 20 | match yaml::parse_io(&mut reader, $encoding) { |
| 21 | Ok(docs) => if docs.len() == 1 { |
| 22 | assert_eq!(docs[..].first().unwrap(), &$expected) |
| 23 | } else { |
| 24 | panic!("too many number of documents: {:?}", docs) |
| 25 | }, |
| 26 | Err(e) => panic!("parse failure: {:?}", e) |
| 27 | } |
| 28 | } |
| 29 | ) |
| 30 | } |
| 31 | |
| 32 | macro_rules! ystrrust-analyzer cargo yaml 0.3.0 ystr!{ |
| 33 | ($e: expr) => ( |
| 34 | YamlStandardData::YamlString($e.to_string()) |
| 35 | ) |
| 36 | } |
| 37 | |
| 38 | macro_rules! yintrust-analyzer cargo yaml 0.3.0 yint!{ |
| 39 | ($e: expr) => ( |
| 40 | YamlStandardData::YamlInteger($e) |
| 41 | ) |
| 42 | } |
| 43 | |
| 44 | macro_rules! yfloatrust-analyzer cargo yaml 0.3.0 yfloat!{ |
| 45 | ($e: expr) => ( |
| 46 | YamlStandardData::YamlFloat($e) |
| 47 | ) |
| 48 | } |
| 49 | |
| 50 | macro_rules! yseqrust-analyzer cargo yaml 0.3.0 yseq!{ |
| 51 | ($($e:expr),*) => ( |
| 52 | YamlStandardData::YamlSequence(vec![$(($e),)*]) |
| 53 | ) |
| 54 | } |
| 55 | |
| 56 | macro_rules! ymaprust-analyzer cargo yaml 0.3.0 ymap!{ |
| 57 | ($($k:expr => $v:expr),*) => ( |
| 58 | YamlStandardData::YamlMapping(vec![$((ystr!($k), $v),)*]) |
| 59 | ) |
| 60 | } |
| 61 | |
| 62 | macro_rules! y_cmp_maprust-analyzer cargo yaml 0.3.0 y_cmp_map!{ |
| 63 | ($($k:expr => $v:expr),*) => ( |
| 64 | YamlStandardData::YamlMapping(vec![$(($k, $v),)*]) |
| 65 | ) |
| 66 | } |
| 67 | |
| 68 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 69 | fn sequence_of_scalarsrust-analyzer cargo yaml 0.3.0 sequence_of_scalars().() { |
| 70 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/ball_players.yml", yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Mark McGwire"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Sammy Sosa"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Ken Griffey")]); |
| 71 | } |
| 72 | |
| 73 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 74 | fn scalar_mappingsrust-analyzer cargo yaml 0.3.0 scalar_mappings().() { |
| 75 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/player_stat.yml", ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ |
| 76 | "hr" => yintrust-analyzer cargo yaml 0.3.0 yint!!(65), |
| 77 | "avg" => yfloatrust-analyzer cargo yaml 0.3.0 yfloat!!(0.278), |
| 78 | "rbi" => yintrust-analyzer cargo yaml 0.3.0 yint!!(147) |
| 79 | }) |
| 80 | } |
| 81 | |
| 82 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 83 | fn maps_of_sequencesrust-analyzer cargo yaml 0.3.0 maps_of_sequences().() { |
| 84 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/ball_clubs.yml", ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ |
| 85 | "american" => yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Boston Red Sox"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Detroit Tigers"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("New York Yankees")], |
| 86 | "national" => yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("New York Mets"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Chicago Cubs"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Atlanta Braves")] |
| 87 | }) |
| 88 | } |
| 89 | |
| 90 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 91 | fn sequence_of_mapsrust-analyzer cargo yaml 0.3.0 sequence_of_maps().() { |
| 92 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/multiple_player_stat.yml", |
| 93 | yseqrust-analyzer cargo yaml 0.3.0 yseq!![ |
| 94 | ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ |
| 95 | "name" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Mark McGwire"), |
| 96 | "hr" => yintrust-analyzer cargo yaml 0.3.0 yint!!(65) |
| 97 | }, |
| 98 | ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ |
| 99 | "name" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Sammy Sosa"), |
| 100 | "hr" => yintrust-analyzer cargo yaml 0.3.0 yint!!(63) |
| 101 | } |
| 102 | ]) |
| 103 | } |
| 104 | |
| 105 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 106 | fn sequence_of_sequencesrust-analyzer cargo yaml 0.3.0 sequence_of_sequences().() { |
| 107 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/csv.yml", |
| 108 | yseqrust-analyzer cargo yaml 0.3.0 yseq!![ |
| 109 | yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("name"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("hr")], |
| 110 | yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Mark McGwire"), yintrust-analyzer cargo yaml 0.3.0 yint!!(65)], |
| 111 | yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Sammy Sosa"), yintrust-analyzer cargo yaml 0.3.0 yint!!(63)] |
| 112 | ]) |
| 113 | } |
| 114 | |
| 115 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 116 | fn mapping_of_mappingsrust-analyzer cargo yaml 0.3.0 mapping_of_mappings().() { |
| 117 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/map_map.yml", |
| 118 | ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ |
| 119 | "Mark McGwire" => ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ "hr" => yintrust-analyzer cargo yaml 0.3.0 yint!!(65) }, |
| 120 | "Sammy Sosa" => ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ "hr" => yintrust-analyzer cargo yaml 0.3.0 yint!!(63) } |
| 121 | }) |
| 122 | } |
| 123 | |
| 124 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 125 | fn aliasrust-analyzer cargo yaml 0.3.0 alias().() { |
| 126 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/alias.yml", |
| 127 | ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ |
| 128 | "hr" => yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Mark McGwire"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Sammy Sosa")], |
| 129 | "rbi" => yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Sammy Sosa"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Ken Griffey")] |
| 130 | }) |
| 131 | } |
| 132 | |
| 133 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 134 | fn complex_keysrust-analyzer cargo yaml 0.3.0 complex_keys().() { |
| 135 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/complex_key.yml", |
| 136 | y_cmp_maprust-analyzer cargo yaml 0.3.0 y_cmp_map!!{ |
| 137 | yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Detroit Tigers"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Chicago Cubs")] => yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("2001-07-23")], |
| 138 | yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("New York Yankees"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Atlanta Braves")] => yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("2001-07-02"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("2001-08-12"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("2001-08-14")] |
| 139 | }) |
| 140 | } |
| 141 | |
| 142 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 143 | fn block_literalrust-analyzer cargo yaml 0.3.0 block_literal().() { |
| 144 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/block_literal.yml", ystrrust-analyzer cargo yaml 0.3.0 ystr!!("\\//||\\/||\n// || ||__\n")) |
| 145 | } |
| 146 | |
| 147 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 148 | fn plain_scalarrust-analyzer cargo yaml 0.3.0 plain_scalar().() { |
| 149 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/plain_scalar.yml", ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Mark McGwire's year was crippled by a knee injury.")) |
| 150 | } |
| 151 | |
| 152 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 153 | fn quoted_scalarrust-analyzer cargo yaml 0.3.0 quoted_scalar().() { |
| 154 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/quoted_scalar.yml", |
| 155 | ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ |
| 156 | "unicode" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Sosa did fine.\u{263A}"), |
| 157 | "control" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!("\x081998\t1999\t2000\n"), |
| 158 | "hexesc" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!("\x13\x10 is \r\n"), |
| 159 | "single" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!(r#""Howdy!" he cried."#), |
| 160 | "quoted" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!(" # not a 'comment'."), |
| 161 | "tie-fighter" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!(r"|\-*-/|") |
| 162 | }) |
| 163 | } |
| 164 | |
| 165 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 166 | fn multi_line_scalarrust-analyzer cargo yaml 0.3.0 multi_line_scalar().() { |
| 167 | test_utf8rust-analyzer cargo yaml 0.3.0 test_utf8!!("source/multi_line_scalar.yml", |
| 168 | ymaprust-analyzer cargo yaml 0.3.0 ymap!!{ |
| 169 | "plain" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!("This unquoted scalar spans many lines."), |
| 170 | "quoted" => ystrrust-analyzer cargo yaml 0.3.0 ystr!!("So does this quoted scalar.\n") |
| 171 | }) |
| 172 | } |
| 173 | |
| 174 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 175 | fn utf16lerust-analyzer cargo yaml 0.3.0 utf16le().() { |
| 176 | test_filerust-analyzer cargo yaml 0.3.0 test_file!!(YamlEncodingrust-analyzer cargo yaml 0.3.0 ffi/YamlEncoding#::YamlUtf16LeEncodingrust-analyzer cargo yaml 0.3.0 ffi/YamlEncoding#YamlUtf16LeEncoding#, "source/utf16le.yml", |
| 177 | yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Hello"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("世界")] |
| 178 | ) |
| 179 | } |
| 180 | |
| 181 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 182 | fn utf16berust-analyzer cargo yaml 0.3.0 utf16be().() { |
| 183 | test_filerust-analyzer cargo yaml 0.3.0 test_file!!(YamlEncodingrust-analyzer cargo yaml 0.3.0 ffi/YamlEncoding#::YamlUtf16BeEncodingrust-analyzer cargo yaml 0.3.0 ffi/YamlEncoding#YamlUtf16BeEncoding#, "source/utf16be.yml", |
| 184 | yseqrust-analyzer cargo yaml 0.3.0 yseq!![ystrrust-analyzer cargo yaml 0.3.0 ystr!!("Hello"), ystrrust-analyzer cargo yaml 0.3.0 ystr!!("世界")] |
| 185 | ) |
| 186 | } |