|
| 1 | +use std::sync::{Mutex, MutexGuard, OnceLock}; |
| 2 | + |
| 3 | +use git_iris::theme; |
| 4 | +use opaline::{OpalineColor, Theme}; |
| 5 | + |
| 6 | +fn theme_lock() -> MutexGuard<'static, ()> { |
| 7 | + static LOCK: OnceLock<Mutex<()>> = OnceLock::new(); |
| 8 | + LOCK.get_or_init(|| Mutex::new(())).lock().expect("lock") |
| 9 | +} |
| 10 | + |
| 11 | +fn base_theme() -> Theme { |
| 12 | + Theme::builder("Derived Test") |
| 13 | + .token("text.primary", OpalineColor::new(240, 240, 240)) |
| 14 | + .token("text.muted", OpalineColor::new(120, 120, 120)) |
| 15 | + .token("text.dim", OpalineColor::new(90, 90, 90)) |
| 16 | + .token("accent.primary", OpalineColor::new(225, 53, 255)) |
| 17 | + .token("accent.secondary", OpalineColor::new(128, 255, 234)) |
| 18 | + .token("accent.tertiary", OpalineColor::new(255, 106, 193)) |
| 19 | + .token("success", OpalineColor::new(80, 250, 123)) |
| 20 | + .token("warning", OpalineColor::new(241, 250, 140)) |
| 21 | + .token("error", OpalineColor::new(255, 99, 99)) |
| 22 | + .token("info", OpalineColor::new(100, 200, 255)) |
| 23 | + .build() |
| 24 | +} |
| 25 | + |
| 26 | +#[test] |
| 27 | +fn theme_wrapper_derives_iris_specific_tokens_and_styles() { |
| 28 | + let _guard = theme_lock(); |
| 29 | + let previous = theme::current(); |
| 30 | + |
| 31 | + theme::set_theme(base_theme()); |
| 32 | + let current = theme::current(); |
| 33 | + |
| 34 | + assert_eq!( |
| 35 | + current.color("git.staged"), |
| 36 | + current.color(theme::names::tokens::SUCCESS) |
| 37 | + ); |
| 38 | + assert_eq!( |
| 39 | + current.color("code.hash"), |
| 40 | + current.color(theme::names::tokens::ACCENT_TERTIARY) |
| 41 | + ); |
| 42 | + assert_eq!( |
| 43 | + current.color("mode.inactive"), |
| 44 | + current.color(theme::names::tokens::TEXT_MUTED) |
| 45 | + ); |
| 46 | + assert!(current.has_style("git_staged")); |
| 47 | + assert!(current.has_style("diff_removed")); |
| 48 | + assert!(current.has_style("commit_hash")); |
| 49 | + assert!(current.has_style("file_path")); |
| 50 | + assert!(current.has_style("mode_inactive")); |
| 51 | + |
| 52 | + theme::set_theme((*previous).clone()); |
| 53 | +} |
0 commit comments