use crate::{
classes::ClassBuilder,
color::Color as TailwindColor,
responsive::{Breakpoint, ResponsiveValue},
theme::{Color as ThemeColor, Spacing, Theme},
validation::{ClassValidator, ValidationError},
};
#[cfg(test)]
mod api_signature_tests {
use super::*;
#[test]
fn test_class_builder_api_stability() {
let builder = ClassBuilder::new();
let _builder = builder.class("test-class");
let _class_set = _builder.build();
assert!(true, "ClassBuilder API should be stable");
}
#[test]
fn test_class_set_api_stability() {
let builder = ClassBuilder::new().class("test-class");
let class_set = builder.build();
let _css = class_set.to_css_classes();
assert!(true, "ClassSet API should be stable");
}
#[test]
fn test_color_api_stability() {
let _color1 = TailwindColor::Blue;
let _color2 = TailwindColor::Red;
let _color3 = TailwindColor::Green;
let _color4 = TailwindColor::Yellow;
let color = TailwindColor::Blue;
let _name = color.name();
assert!(true, "Color API should be stable");
}
#[test]
fn test_responsive_value_api_stability() {
let mut responsive = ResponsiveValue::new();
responsive.set_breakpoint(Breakpoint::Base, 10);
responsive.set_breakpoint(Breakpoint::Sm, 20);
let _value = responsive.get_breakpoint(Breakpoint::Sm);
assert!(true, "ResponsiveValue API should be stable");
}
#[test]
fn test_theme_api_stability() {
let mut theme = Theme::new("test-theme");
theme.add_color("primary", ThemeColor::hex("#3b82f6"));
let _color = theme.get_color("primary");
theme.add_spacing("test", Spacing::px(10.0));
let _spacing = theme.get_spacing("test");
assert!(true, "Theme API should be stable");
}
#[test]
fn test_class_validator_api_stability() {
let validator = ClassValidator::new();
let _result = validator.validate_class("test-class");
let _result = validator.validate_classes(&["test-class".to_string()]);
assert!(true, "ClassValidator API should be stable");
}
}
#[cfg(test)]
mod serialization_stability_tests {
use super::*;
#[test]
fn test_color_serialization_stability() {
let color = TailwindColor::Blue;
let json = serde_json::to_string(&color).expect("Should serialize to JSON");
let deserialized: TailwindColor =
serde_json::from_str(&json).expect("Should deserialize from JSON");
assert_eq!(
color, deserialized,
"Color JSON serialization should be stable"
);
assert!(
json.contains("Blue"),
"Color serialization format should be stable"
);
}
#[test]
fn test_spacing_serialization_stability() {
let spacing = Spacing::px(10.0);
let json = serde_json::to_string(&spacing).expect("Should serialize to JSON");
let deserialized: Spacing =
serde_json::from_str(&json).expect("Should deserialize from JSON");
assert_eq!(
spacing, deserialized,
"Spacing JSON serialization should be stable"
);
}
#[test]
fn test_theme_serialization_stability() {
let mut theme = Theme::new("test-theme");
theme.add_color("primary", ThemeColor::hex("#3b82f6"));
theme.add_spacing("test", Spacing::px(10.0));
let json = serde_json::to_string(&theme).expect("Should serialize to JSON");
let deserialized: Theme =
serde_json::from_str(&json).expect("Should deserialize from JSON");
assert_eq!(
theme.get_color("primary").unwrap(),
deserialized.get_color("primary").unwrap(),
"Theme JSON serialization should be stable"
);
}
#[test]
fn test_responsive_value_serialization_stability() {
let mut responsive = ResponsiveValue::new();
responsive.set_breakpoint(Breakpoint::Base, 10);
responsive.set_breakpoint(Breakpoint::Sm, 20);
let json = serde_json::to_string(&responsive).expect("Should serialize to JSON");
let deserialized: ResponsiveValue<i32> =
serde_json::from_str(&json).expect("Should deserialize from JSON");
assert_eq!(
responsive.get_breakpoint(Breakpoint::Base),
deserialized.get_breakpoint(Breakpoint::Base)
);
assert_eq!(
responsive.get_breakpoint(Breakpoint::Sm),
deserialized.get_breakpoint(Breakpoint::Sm)
);
}
}
#[cfg(test)]
mod error_stability_tests {
use super::*;
#[test]
fn test_validation_error_stability() {
let _error1 = ValidationError::InvalidClass("test".to_string());
let _error2 = ValidationError::ClassConflict("class1".to_string(), "class2".to_string());
let _error3 = ValidationError::DeprecatedClass("deprecated".to_string());
let _error4 = ValidationError::UnsupportedClass("unsupported".to_string());
let error = ValidationError::InvalidClass("test".to_string());
let message = format!("{}", error);
assert!(
message.contains("Invalid class name"),
"Error message should be stable"
);
}
#[test]
fn test_validation_error_formatting_stability() {
let error = ValidationError::InvalidClass("test".to_string());
let formatted = format!("{}", error);
assert!(
formatted.contains("Invalid class name"),
"Error formatting should be stable"
);
}
}
#[cfg(test)]
mod default_stability_tests {
use super::*;
#[test]
fn test_color_default_stability() {
let default_blue = TailwindColor::Blue;
let default_red = TailwindColor::Red;
assert_eq!(
default_blue.name(),
"blue",
"Default blue color should be stable"
);
assert_eq!(
default_red.name(),
"red",
"Default red color should be stable"
);
}
#[test]
fn test_spacing_default_stability() {
let default_px = Spacing::px(0.0);
let default_rem = Spacing::rem(0.0);
assert_eq!(
default_px.to_css(),
"0px",
"Default px spacing should be stable"
);
assert_eq!(
default_rem.to_css(),
"0rem",
"Default rem spacing should be stable"
);
}
#[test]
fn test_theme_default_stability() {
let theme = Theme::new("test-theme");
assert_eq!(
theme.name, "test-theme",
"Default theme name should be stable"
);
assert!(
theme.colors.is_empty(),
"Default theme should have no colors"
);
assert!(
theme.spacing.is_empty(),
"Default theme should have no spacing"
);
}
#[test]
fn test_breakpoint_default_stability() {
assert_eq!(
Breakpoint::Sm.min_width(),
640,
"SM breakpoint should be stable"
);
assert_eq!(
Breakpoint::Md.min_width(),
768,
"MD breakpoint should be stable"
);
assert_eq!(
Breakpoint::Lg.min_width(),
1024,
"LG breakpoint should be stable"
);
assert_eq!(
Breakpoint::Xl.min_width(),
1280,
"XL breakpoint should be stable"
);
assert_eq!(
Breakpoint::Xl2.min_width(),
1536,
"2XL breakpoint should be stable"
);
}
}
#[cfg(test)]
mod performance_stability_tests {
use super::*;
use std::time::Instant;
#[test]
fn test_class_builder_performance_stability() {
let start = Instant::now();
let mut builder = ClassBuilder::new();
for i in 0..100 {
builder = builder.class(&format!("class-{}", i));
}
let _class_set = builder.build();
let duration = start.elapsed();
assert!(
duration.as_micros() < 5000,
"ClassBuilder performance should be stable"
);
}
#[test]
fn test_class_validator_performance_stability() {
let validator = ClassValidator::new();
let classes: Vec<String> = (0..100).map(|i| format!("class-{}", i)).collect();
let start = Instant::now();
let _result = validator.validate_classes(&classes);
let duration = start.elapsed();
assert!(
duration.as_millis() < 20,
"ClassValidator performance should be stable"
);
}
#[test]
fn test_serialization_performance_stability() {
let theme = Theme::new("test-theme");
let start = Instant::now();
let _json = serde_json::to_string(&theme).expect("Should serialize");
let duration = start.elapsed();
assert!(
duration.as_micros() < 2000,
"Serialization performance should be stable"
);
}
}
#[cfg(test)]
mod migration_stability_tests {
use super::*;
#[test]
fn test_legacy_api_patterns() {
let builder = ClassBuilder::new();
let _class_set = builder.class("legacy-class").build();
let _color = TailwindColor::Blue;
let mut theme = Theme::new("legacy-theme");
theme.add_color("primary", ThemeColor::hex("#3b82f6"));
assert!(true, "Legacy API patterns should still work");
}
#[test]
fn test_new_api_backward_compatibility() {
let builder = ClassBuilder::new();
let _class_set = builder.class("new-class").build();
let _color = TailwindColor::Blue;
let mut theme = Theme::new("new-theme");
theme.add_color("primary", ThemeColor::hex("#3b82f6"));
assert!(true, "New API features should be backward compatible");
}
}