tailwind_rs_postcss/
test_integration.rs

1//! Integration test for PostCSS functionality
2//!
3//! This module provides basic integration tests to verify that the PostCSS
4//! engine works correctly with the existing Tailwind-RS Core.
5
6use crate::engine::{PerformanceOptions, SourceMapOptions};
7use crate::*;
8
9/// Test basic PostCSS engine functionality
10pub async fn test_basic_postcss_processing() -> Result<()> {
11    let engine = PostCSSEngine::new(PostCSSConfig::default())?;
12    let input_css = ".test { color: red; font-size: 16px; }";
13    let result = engine.process_css(input_css).await?;
14
15    assert!(result.css.contains(".test"));
16    assert!(result.css.contains("color: red"));
17    assert!(result.css.contains("font-size: 16px"));
18
19    Ok(())
20}
21
22/// Test CSS parsing functionality
23pub fn test_css_parsing() -> Result<()> {
24    let parser = CSSParser::new(ParseOptions::default());
25    let input = ".test { color: red; }";
26    let result = parser.parse(input)?;
27
28    match result {
29        CSSNode::Stylesheet(rules) => {
30            assert_eq!(rules.len(), 1);
31            assert_eq!(rules[0].selector, ".test");
32            assert_eq!(rules[0].declarations.len(), 1);
33            assert_eq!(rules[0].declarations[0].property, "color");
34            assert_eq!(rules[0].declarations[0].value, "red");
35        }
36        _ => panic!("Expected stylesheet"),
37    }
38
39    Ok(())
40}
41
42/// Test error handling
43pub fn test_error_handling() {
44    let parser = CSSParser::new(ParseOptions::default());
45    let invalid_css = ".test { color: red; font-size: }"; // Missing value
46
47    // This should either parse successfully (if we're lenient) or fail gracefully
48    let result = parser.parse(invalid_css);
49    // For now, we'll just ensure it doesn't panic
50    let _ = result;
51}
52
53/// Test configuration
54pub async fn test_configuration() -> Result<()> {
55    let config = PostCSSConfig {
56        source_map: true,
57        source_map_options: SourceMapOptions {
58            inline: false,
59            file: Some("output.css.map".to_string()),
60            source_root: Some("/src".to_string()),
61            sources_content: true,
62        },
63        parser_options: ParseOptions {
64            track_positions: true,
65            strict_mode: false,
66            custom_properties: true,
67            nesting: true,
68            container_queries: true,
69            cascade_layers: true,
70            max_nesting_depth: 10,
71            plugins: Vec::new(),
72        },
73        transform_options: TransformOptions {
74            optimize: true,
75            vendor_prefixes: false,
76            flatten_nesting: true,
77            resolve_custom_properties: true,
78        },
79        performance: PerformanceOptions {
80            enable_cache: true,
81            cache_size_limit: 1000,
82            parallel_processing: true,
83            memory_optimization: true,
84        },
85        plugins: Vec::new(),
86    };
87
88    let engine = PostCSSEngine::new(config)?;
89    assert!(engine.get_metrics().await.plugins_loaded == 0);
90
91    Ok(())
92}
93
94#[cfg(test)]
95mod tests {
96    use super::*;
97
98    #[test]
99    fn test_basic_parsing() {
100        test_css_parsing().unwrap();
101    }
102
103    #[test]
104    fn test_error_handling() {
105        let parser = CSSParser::new(ParseOptions::default());
106        let invalid_css = ".test { color: red; font-size: }"; // Missing value
107
108        // This should either parse successfully (if we're lenient) or fail gracefully
109        let result = parser.parse(invalid_css);
110        // For now, we'll just ensure it doesn't panic
111        let _ = result;
112    }
113
114    #[tokio::test]
115    async fn test_configuration_async() {
116        test_configuration().await.unwrap();
117    }
118
119    #[tokio::test]
120    async fn test_basic_processing() {
121        test_basic_postcss_processing().await.unwrap();
122    }
123}