//! Theme TOML parsing integration tests (unit-level, no AppHandle needed). // ── Theme Parsing ──────────────────────────────────────────────────── #[test] fn theme_toml_parse_full() { let toml_str = r##" [meta] name = "Ocean Dark" variant = "dark" [background] primary = "#1a1a2e" secondary = "#16213e" [foreground] primary = "#e0e0e0" secondary = "#a0a0a0" [accent] primary = "#0f3460" highlight = "#e94560" [border] default = "#2a2a4a" "##; let table: toml::Table = toml_str.parse().unwrap(); // Verify meta parsing let meta = table.get("meta").unwrap().as_table().unwrap(); assert_eq!(meta.get("name").unwrap().as_str().unwrap(), "Ocean Dark"); assert_eq!(meta.get("variant").unwrap().as_str().unwrap(), "dark"); // Verify color sections can be extracted (replicates get_theme logic) let mut colors = std::collections::HashMap::new(); for section in &["background", "foreground", "accent", "border"] { if let Some(sect) = table.get(*section).and_then(|s| s.as_table()) { for (key, val) in sect { if let Some(color) = val.as_str() { colors.insert(format!("{}.{}", section, key), color.to_string()); } } } } assert_eq!(colors.get("background.primary").unwrap(), "#1a1a2e"); assert_eq!(colors.get("foreground.primary").unwrap(), "#e0e0e0"); assert_eq!(colors.get("accent.highlight").unwrap(), "#e94560"); assert_eq!(colors.get("border.default").unwrap(), "#2a2a4a"); assert_eq!(colors.len(), 7); } #[test] fn theme_toml_parse_minimal() { // A theme with only meta and one color section let toml_str = r##" [meta] name = "Minimal" [background] primary = "#fff" "##; let table: toml::Table = toml_str.parse().unwrap(); let meta = table.get("meta").unwrap().as_table().unwrap(); assert_eq!(meta.get("name").unwrap().as_str().unwrap(), "Minimal"); // Variant not specified — consumer should default to "dark" assert!(meta.get("variant").is_none()); let mut colors = std::collections::HashMap::new(); for section in &["background", "foreground", "accent", "border"] { if let Some(sect) = table.get(*section).and_then(|s| s.as_table()) { for (key, val) in sect { if let Some(color) = val.as_str() { colors.insert(format!("{}.{}", section, key), color.to_string()); } } } } assert_eq!(colors.len(), 1); assert_eq!(colors.get("background.primary").unwrap(), "#fff"); } #[test] fn theme_toml_parse_empty_is_valid() { // An empty TOML should parse without error let table: toml::Table = "".parse().unwrap(); let mut colors = std::collections::HashMap::new(); for section in &["background", "foreground", "accent", "border"] { if let Some(sect) = table.get(*section).and_then(|s| s.as_table()) { for (key, val) in sect { if let Some(color) = val.as_str() { colors.insert(format!("{}.{}", section, key), color.to_string()); } } } } assert!(colors.is_empty()); } #[test] fn theme_toml_ignores_unknown_sections() { let toml_str = r##" [meta] name = "Custom" [background] primary = "#000" [custom_section] foo = "bar" "##; let table: toml::Table = toml_str.parse().unwrap(); // The standard extraction logic only reads known sections let mut colors = std::collections::HashMap::new(); for section in &["background", "foreground", "accent", "border"] { if let Some(sect) = table.get(*section).and_then(|s| s.as_table()) { for (key, val) in sect { if let Some(color) = val.as_str() { colors.insert(format!("{}.{}", section, key), color.to_string()); } } } } // custom_section should not appear in colors assert_eq!(colors.len(), 1); assert!(!colors.contains_key("custom_section.foo")); }