icedwright-probe-macros 0.1.1

Derives for icedwright-probe: typed test ids and the Messages variant table
Documentation
//! Derives for `icedwright-probe`, which re-exports them. Use them through the probe:
//! `#[derive(icedwright_probe::TestId)]` and `#[derive(icedwright_probe::Messages)]`.
//!
//! Generated code names `::icedwright_probe` by absolute path. When the probe is renamed or
//! reached through a re-export, `#[icedwright_probe(crate = path)]` on the enum points it
//! elsewhere.

mod attrs;
mod case;
mod format;
mod messages;
mod test_id;

use proc_macro::TokenStream;
use syn::{DeriveInput, parse_macro_input};

/// Implements `icedwright_probe::TestId` for an enum.
///
/// Unit variants become their name in kebab case (`NewItem` is `"new-item"`).
/// `#[test_id("...")]` sets the string; on a variant with fields it is a format string that
/// names every field, as `{0}` for a tuple field or `{name}` for a named one. Literal text may
/// hold only `a-z`, `0-9`, `.`, `_` and `-`, and two variants may not share a string.
#[proc_macro_derive(TestId, attributes(test_id, icedwright_probe))]
pub fn derive_test_id(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    test_id::expand(&input)
        .unwrap_or_else(syn::Error::into_compile_error)
        .into()
}

/// Implements `icedwright_probe::Messages` for an enum: the table of every variant and the
/// index of a value's variant.
///
/// `#[messages(nested)]` on a variant with one field whose type also implements `Messages`
/// lists that type's variants under this one, as `Editor::Bold`.
#[proc_macro_derive(Messages, attributes(messages, icedwright_probe))]
pub fn derive_messages(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    messages::expand(&input)
        .unwrap_or_else(syn::Error::into_compile_error)
        .into()
}