| 1 | use ucs2rust-analyzer cargo ucs2 0.3.3 crate/::{decoderust-analyzer cargo ucs2 0.3.3 decode()., decode_withrust-analyzer cargo ucs2 0.3.3 decode_with()., encoderust-analyzer cargo ucs2 0.3.3 encode()., ucs2_cstrrust-analyzer cargo ucs2 0.3.3 macros/ucs2_cstr!, Errorrust-analyzer cargo ucs2 0.3.3 Error#}; |
| 2 | |
| 3 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4 | fn encodingrust-analyzer cargo ucs2 0.3.3 encoding().() { |
| 5 | let input = "őэ╋"; |
| 6 | let mut buffer = [0u16; 3]; |
| 7 | |
| 8 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encoderust-analyzer cargo ucs2 0.3.3 encode().(input, &mut buffer), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(3)); |
| 9 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., [0x0151, 0x044D, 0x254B]); |
| 10 | |
| 11 | let mut buffer = [0u16; 2]; |
| 12 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encoderust-analyzer cargo ucs2 0.3.3 encode().(input, &mut buffer), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo ucs2 0.3.3 Error#::BufferOverflowrust-analyzer cargo ucs2 0.3.3 Error#BufferOverflow#)); |
| 13 | |
| 14 | let input = "😎"; |
| 15 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encoderust-analyzer cargo ucs2 0.3.3 encode().(input, &mut buffer), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo ucs2 0.3.3 Error#::MultiByterust-analyzer cargo ucs2 0.3.3 Error#MultiByte#)); |
| 16 | } |
| 17 | |
| 18 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 19 | fn decodingrust-analyzer cargo ucs2 0.3.3 decoding().() { |
| 20 | let input = "$¢ह한"; |
| 21 | let mut u16_buffer = [0u16; 4]; |
| 22 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encoderust-analyzer cargo ucs2 0.3.3 encode().(input, &mut u16_buffer), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(4)); |
| 23 | |
| 24 | let mut u8_buffer = [0u8; 9]; |
| 25 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decoderust-analyzer cargo ucs2 0.3.3 decode().(&u16_buffer, &mut u8_buffer), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(9)); |
| 26 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&u8_buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0..9]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#("$¢ह한")); |
| 27 | |
| 28 | // `decode` has three branches that can return `BufferOverflow`, |
| 29 | // check each of them. |
| 30 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 31 | decoderust-analyzer cargo ucs2 0.3.3 decode().(&u16_buffer, &mut u8_buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().), |
| 32 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo ucs2 0.3.3 Error#::BufferOverflowrust-analyzer cargo ucs2 0.3.3 Error#BufferOverflow#) |
| 33 | ); |
| 34 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 35 | decoderust-analyzer cargo ucs2 0.3.3 decode().(&u16_buffer, &mut u8_buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().), |
| 36 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo ucs2 0.3.3 Error#::BufferOverflowrust-analyzer cargo ucs2 0.3.3 Error#BufferOverflow#) |
| 37 | ); |
| 38 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 39 | decoderust-analyzer cargo ucs2 0.3.3 decode().(&u16_buffer, &mut u8_buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().), |
| 40 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo ucs2 0.3.3 Error#::BufferOverflowrust-analyzer cargo ucs2 0.3.3 Error#BufferOverflow#) |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 45 | fn decoding_withrust-analyzer cargo ucs2 0.3.3 decoding_with().() { |
| 46 | let input = "$¢ह한"; |
| 47 | |
| 48 | let mut u16_buffer = [0u16; 4]; |
| 49 | let result = encoderust-analyzer cargo ucs2 0.3.3 encode().(input, &mut u16_buffer); |
| 50 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 4); |
| 51 | |
| 52 | let mut u8_buffer = [0u8; 9]; |
| 53 | let mut pos = 0; |
| 54 | |
| 55 | let result = decode_withrust-analyzer cargo ucs2 0.3.3 decode_with().(&u16_buffer, |bytes| { |
| 56 | for byte in bytes.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`&'a [T]`][IntoIterator]into_iter().() { |
| 57 | u8_buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut(). = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().byte; |
| 58 | pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 59 | } |
| 60 | |
| 61 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 62 | }); |
| 63 | |
| 64 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 9); |
| 65 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&u8_buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0..9]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#("$¢ह한")); |
| 66 | } |
| 67 | |
| 68 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 69 | fn test_macrorust-analyzer cargo ucs2 0.3.3 test_macro().() { |
| 70 | const S1rust-analyzer cargo ucs2 0.3.3 S1.: [u16; 4] = ucs2_cstrrust-analyzer cargo ucs2 0.3.3 macros/ucs2_cstr!!("abc"); |
| 71 | const S2rust-analyzer cargo ucs2 0.3.3 S2.: &[u16] = &ucs2_cstrrust-analyzer cargo ucs2 0.3.3 macros/ucs2_cstr!!("$¢ह한"); |
| 72 | |
| 73 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(S1rust-analyzer cargo ucs2 0.3.3 S1., [97, 98, 99, 0]); |
| 74 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(S2rust-analyzer cargo ucs2 0.3.3 S2., [36, 162, 2361, 54620, 0]); |
| 75 | } |