Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/arrayvec/tests/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  borsh.rs

  Sprache: Rust
 

#![cfg(feature = "borsh")]
use std::fmt;
extern crate arrayvec;
extern crate borsh;

fn assert_ser<T: borsh::BorshSerialize>(v: &T, expected_bytes: &[u8]) {
    let mut actual_bytes = Vec::new();
    v.serialize(&mut actual_bytes).unwrap();
    assert_eq!(actual_bytes, expected_bytes);
}

fn assert_roundtrip<T: borsh::BorshSerialize + borsh::BorshDeserialize + PartialEq + fmt::Debug>(v: &T) {
    let mut bytes = Vec::new();
    v.serialize(&mut bytes).unwrap();
    let v_de = T::try_from_slice(&bytes).unwrap();
    assert_eq!(*v, v_de);
}

mod array_vec {
    use arrayvec::ArrayVec;
    use super::{assert_ser, assert_roundtrip};

    #[test]
    fn test_empty() {
        let vec = ArrayVec::<u32, 0>::new();
        assert_ser(&vec, b"\0\0\0\0");
        assert_roundtrip(&vec);
    }

    #[test]
    fn test_full() {
        let mut vec = ArrayVec::<u32, 3>::new();
        vec.push(0xdeadbeef);
        vec.push(0x123);
        vec.push(0x456);
        assert_ser(&vec, b"\x03\0\0\0\xef\xbe\xad\xde\x23\x01\0\0\x56\x04\0\0");
        assert_roundtrip(&vec);
    }

    #[test]
    fn test_with_free_capacity() {
        let mut vec = ArrayVec::<u32, 3>::new();
        vec.push(0xdeadbeef);
        assert_ser(&vec, b"\x01\0\0\0\xef\xbe\xad\xde");
        assert_roundtrip(&vec);
    }
}

mod array_string {
    use arrayvec::ArrayString;
    use super::{assert_ser, assert_roundtrip};

    #[test]
    fn test_empty() {
        let string = ArrayString::<0>::new();
        assert_ser(&string, b"\0\0\0\0");
        assert_roundtrip(&string);
    }

    #[test]
    fn test_full() {
        let string = ArrayString::from_byte_string(b"hello world").unwrap();
        assert_ser(&string, b"\x0b\0\0\0hello world");
        assert_roundtrip(&string);
    }

    #[test]
    fn test_with_free_capacity() {
        let string = ArrayString::<16>::from("hello world").unwrap();
        assert_ser(&string, b"\x0b\0\0\0hello world");
        assert_roundtrip(&string);
    }
}

Messung V0.5 in Prozent
C=78 H=96 G=87

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet am  2026-06-19) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.