mysql-handler-macros 0.2.0

Procedural macros for mysql-handler engine cdylibs
Documentation
// Copyright (C) 2026 ren-yamanashi
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, version 2.0,
// as published by the Free Software Foundation.
//
// This program is designed to work with certain software (including
// but not limited to OpenSSL) that is licensed under separate terms,
// as designated in a particular file or component or in included license
// documentation. The authors of this program hereby grant you an additional
// permission to link the program and your derivative works with the
// separately licensed software that they have either included with
// the program or referenced in the documentation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <https://www.gnu.org/licenses/>.

//! Unit tests for [`super`] — split off so `args.rs` stays under the
//! 250-line ceiling without exposing the parser internals as `pub`.

use proc_macro2::Span;
use syn::LitStr;

use super::{MAX_PLUGIN_NAME_LEN, validate_name};

fn lit(value: &str) -> LitStr {
    LitStr::new(value, Span::call_site())
}

#[test]
fn empty_name_rejected() {
    let err = validate_name(&lit("")).unwrap_err();
    assert!(err.to_string().contains("non-empty"));
}

#[test]
fn nul_byte_in_name_rejected() {
    let err = validate_name(&lit("rust\0engine")).unwrap_err();
    assert!(err.to_string().contains("NUL byte"));
}

#[test]
fn overlong_name_rejected() {
    let too_long = "a".repeat(MAX_PLUGIN_NAME_LEN + 1);
    let err = validate_name(&lit(&too_long)).unwrap_err();
    assert!(err.to_string().contains("at most"));
}

#[test]
fn name_at_limit_accepted() {
    let at_limit = "a".repeat(MAX_PLUGIN_NAME_LEN);
    validate_name(&lit(&at_limit)).unwrap();
}

#[test]
fn typical_name_accepted() {
    validate_name(&lit("my_engine")).unwrap();
}