use core::{borrow::Borrow, hash::BuildHasher};
use std::collections::HashMap;
use crate::{GraphqlName, MongoName, MysqlName, PostgresName, SqliteName};
#[test]
fn a_variant_name_views_the_str_it_was_made_from() {
const WIRE: &GraphqlName = GraphqlName::new("LOW");
let borrowed: &'static str = WIRE;
assert_eq!(borrowed, "LOW");
assert_eq!(SqliteName::new("").len(), 0);
assert_eq!(MongoName::new("ключ").as_ref(), "ключ");
assert_eq!(MongoName::new("ключ").len(), 8);
}
#[expect(
dead_code,
reason = "the signature is the assertion — rustc checks it without a caller"
)]
fn each_namespace_is_its_own_type<'a>(
sqlite: &'a SqliteName,
postgres: &'a PostgresName,
mysql: &'a MysqlName,
mongo: &'a MongoName,
graphql: &'a GraphqlName,
) -> (
&'a SqliteName,
&'a PostgresName,
&'a MysqlName,
&'a MongoName,
&'a GraphqlName,
) {
(sqlite, postgres, mysql, mongo, graphql)
}
#[test]
fn a_variant_name_and_its_borrowed_str_agree() {
let word = SqliteName::new("vp09");
let borrowed: &str = word.borrow();
let stored = HashMap::from([("vp09", 0usize), ("Tape", 1)]);
assert_eq!(stored.get(borrowed), Some(&0));
assert_eq!(
stored.get(Borrow::<str>::borrow(SqliteName::new("Tape"))),
Some(&1)
);
let hasher = stored.hasher();
assert_eq!(hasher.hash_one(word), hasher.hash_one(borrowed));
assert_eq!(word, SqliteName::new("vp09"));
assert_eq!(word.cmp(SqliteName::new("Tape")), borrowed.cmp("Tape"));
}