use crate::{design::prelude::*, traits::Validator};
use icydb_utils::{Case, Casing};
#[validator]
pub struct Kebab;
impl Validator<str> for Kebab {
fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
if !s.is_case(Case::Kebab) {
ctx.issue(format!("'{s}' is not kebab-case"));
}
}
}
#[validator]
pub struct Lower;
impl Validator<str> for Lower {
fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
if !s.is_case(Case::Lower) {
ctx.issue(format!("'{s}' is not lower case"));
}
}
}
#[validator]
pub struct LowerUscore;
impl Validator<str> for LowerUscore {
fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
if !s.chars().all(|c| c.is_lowercase() || c == '_') {
ctx.issue(format!("'{s}' is not lower case with underscores"));
}
}
}
#[validator]
pub struct Snake;
impl Validator<str> for Snake {
fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
if !s.is_case(Case::Snake) {
ctx.issue(format!("'{s}' is not snake_case"));
}
}
}
#[validator]
pub struct Title;
impl Validator<str> for Title {
fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
if !s.is_case(Case::Title) {
ctx.issue(format!("'{s}' is not Title Case"));
}
}
}
#[validator]
pub struct Upper;
impl Validator<str> for Upper {
fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
if !s.is_case(Case::Upper) {
ctx.issue(format!("'{s}' is not UPPER CASE"));
}
}
}
#[validator]
pub struct UpperCamel;
impl Validator<str> for UpperCamel {
fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
if !s.is_case(Case::UpperCamel) {
ctx.issue(format!("'{s}' is not UpperCamelCase"));
}
}
}
#[validator]
pub struct UpperSnake;
impl Validator<str> for UpperSnake {
fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
if !s.is_case(Case::UpperSnake) {
ctx.issue(format!("'{s}' is not UPPER_SNAKE_CASE"));
}
}
}