Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  skip.rs

  Sprache: Rust
 

//! Test that skipped fields are not read into structs when they appear in input.

use darling::{FromDeriveInput, FromMeta};
use syn::parse_quote;

#[derive(Debug, PartialEq, Eq, FromDeriveInput)]
#[darling(attributes(skip_test))]
pub struct Lorem {
    ipsum: String,

    #[darling(skip)]
    dolor: u8,
}

/// Verify variant-level and field-level skip work correctly for enums.
#[derive(Debug, FromMeta)]
pub enum Sit {
    Amet(bool),

    #[darling(skip)]
    Foo {
        hello: bool,
    },

    Bar {
        hello: bool,
        #[darling(skip)]
        world: u8,
    },
}

#[test]
fn verify_skipped_field_not_required() {
    let di = parse_quote! {
        #[skip_test(ipsum = "Hello")]
        struct Baz;
    };

    assert_eq!(
        Lorem::from_derive_input(&di).unwrap(),
        Lorem {
            ipsum: "Hello".to_string(),
            dolor: 0,
        }
    );
}

/// This test verifies that a skipped field will still prefer an explicit default
/// over the default that would come from its field type. It would be incorrect for
/// `Defaulting::from_derive_input` to fail here, and it would be wrong for the value
/// of `dolor` to be `None`.
#[test]
fn verify_default_supersedes_from_none() {
    fn default_dolor() -> Option<u8> {
        Some(2)
    }

    #[derive(Debug, PartialEq, Eq, FromDeriveInput)]
    #[darling(attributes(skip_test))]
    pub struct Defaulting {
        #[darling(skip, default = "default_dolor")]
        dolor: Option<u8>,
    }

    let di = parse_quote! {
        #[skip_test]
        struct Baz;
    };

    assert_eq!(
        Defaulting::from_derive_input(&di).unwrap(),
        Defaulting { dolor: Some(2) }
    )
}

Messung V0.5 in Prozent
C=77 H=94 G=85

¤ Dauer der Verarbeitung: 0.12 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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik