| 1 | extern crate yamlrust-analyzer cargo yaml 0.3.0 yaml/; |
| 2 | |
| 3 | use yamlrust-analyzer cargo yaml 0.3.0 crate/::errorrust-analyzer cargo yaml 0.3.0 error/::YamlErrorrust-analyzer cargo yaml 0.3.0 error/YamlError#; |
| 4 | use yamlrust-analyzer cargo yaml 0.3.0 crate/::emitterrust-analyzer cargo yaml 0.3.0 emitter/::YamlEmitterrust-analyzer cargo yaml 0.3.0 emitter/YamlEmitter#; |
| 5 | 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#, YamlScalarStylerust-analyzer cargo yaml 0.3.0 ffi/YamlScalarStyle#}; |
| 6 | |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#; |
| 8 | 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/; |
| 9 | 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/::{Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 10 | |
| 11 | struct MockRWrust-analyzer cargo yaml 0.3.0 MockRW# { |
| 12 | _datarust-analyzer cargo yaml 0.3.0 MockRW#_data.: () |
| 13 | } |
| 14 | |
| 15 | impl MockRWrust-analyzer cargo yaml 0.3.0 MockRW# { |
| 16 | pub fn newrust-analyzer cargo yaml 0.3.0 impl#[MockRW]new().() -> MockRWrust-analyzer cargo yaml 0.3.0 MockRW# { |
| 17 | MockRWrust-analyzer cargo yaml 0.3.0 MockRW# { _datarust-analyzer cargo yaml 0.3.0 MockRW#_data.: () } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | impl Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for MockRWrust-analyzer cargo yaml 0.3.0 MockRW# { |
| 22 | fn readrust-analyzer cargo yaml 0.3.0 impl#[MockRW][Read]read().(&mut self, _buf: &mut [u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 23 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, "")) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | impl Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for MockRWrust-analyzer cargo yaml 0.3.0 MockRW# { |
| 28 | fn writerust-analyzer cargo yaml 0.3.0 impl#[MockRW][Write]write().(&mut self, _buf: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 29 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, "")) |
| 30 | } |
| 31 | |
| 32 | fn flushrust-analyzer cargo yaml 0.3.0 impl#[MockRW][Write]flush().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 33 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, "")) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 38 | fn error_cause_test_readrust-analyzer cargo yaml 0.3.0 error_cause_test_read().() { |
| 39 | let mut mock_reader = MockRWrust-analyzer cargo yaml 0.3.0 MockRW#::newrust-analyzer cargo yaml 0.3.0 impl#[MockRW]new().(); |
| 40 | match yamlrust-analyzer cargo yaml 0.3.0 crate/::parse_io_utf8rust-analyzer cargo yaml 0.3.0 parse_io_utf8().(&mut mock_reader) { |
| 41 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Should return an error"), |
| 42 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.causerust-analyzer cargo yaml 0.3.0 error/impl#[YamlError][Error]cause().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|ioe| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", ioe)), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | fn write_to_bad_streamrust-analyzer cargo yaml 0.3.0 write_to_bad_stream().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), YamlErrorrust-analyzer cargo yaml 0.3.0 error/YamlError#> { |
| 47 | let mut mock_writer = MockRWrust-analyzer cargo yaml 0.3.0 MockRW#::newrust-analyzer cargo yaml 0.3.0 impl#[MockRW]new().(); |
| 48 | let mut emitter = YamlEmitterrust-analyzer cargo yaml 0.3.0 emitter/YamlEmitter#::initrust-analyzer cargo yaml 0.3.0 emitter/impl#[`YamlEmitter<'r>`]init().(&mut mock_writer); |
| 49 | tryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/`r#try`!!(emitter.emit_streamrust-analyzer cargo yaml 0.3.0 emitter/impl#[`YamlEmitter<'r>`]emit_stream().(YamlEncodingrust-analyzer cargo yaml 0.3.0 ffi/YamlEncoding#::YamlUtf8Encodingrust-analyzer cargo yaml 0.3.0 ffi/YamlEncoding#YamlUtf8Encoding#, |stream| |
| 50 | stream.emit_documentrust-analyzer cargo yaml 0.3.0 emitter/impl#[`YamlEmitter<'r>`]emit_document().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &[], true, |doc| { |
| 51 | doc.emit_scalar_eventrust-analyzer cargo yaml 0.3.0 emitter/impl#[`YamlEmitter<'r>`]emit_scalar_event().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, "a", true, false, YamlScalarStylerust-analyzer cargo yaml 0.3.0 ffi/YamlScalarStyle#::YamlPlainScalarStylerust-analyzer cargo yaml 0.3.0 ffi/YamlScalarStyle#YamlPlainScalarStyle#) |
| 52 | }) |
| 53 | )); |
| 54 | emitter.flushrust-analyzer cargo yaml 0.3.0 emitter/impl#[`YamlEmitter<'r>`]flush().() |
| 55 | } |
| 56 | |
| 57 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 58 | fn error_cause_test_writerust-analyzer cargo yaml 0.3.0 error_cause_test_write().() { |
| 59 | match write_to_bad_streamrust-analyzer cargo yaml 0.3.0 write_to_bad_stream().() { |
| 60 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Should return an error"), |
| 61 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(e.causerust-analyzer cargo yaml 0.3.0 error/impl#[YamlError][Error]cause().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|ioe| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", ioe)), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())) |
| 62 | } |
| 63 | } |