use aethershell::{env::Env, eval, parser, value::Value};
#[test]
fn test_themes_returns_correct_count() {
let mut env = Env::default();
let stmts = parser::parse_program("themes()").unwrap();
let result = eval::eval_program(&stmts, &mut env).unwrap();
match result {
Value::Array(themes) => {
assert_eq!(
themes.len(),
38,
"themes() should return 38 themes, got {}",
themes.len()
);
}
_ => panic!("themes() should return Array"),
}
}
#[test]
fn test_expected_themes_exist() {
let mut env = Env::default();
let stmts = parser::parse_program("themes()").unwrap();
let result = eval::eval_program(&stmts, &mut env).unwrap();
let expected = vec![
"catppuccin",
"monokai",
"dracula",
"nord",
"gruvbox",
"solarized",
"tokyo-night",
"rose-pine",
"vscode",
];
if let Value::Array(themes) = result {
let theme_strings: Vec<String> = themes
.iter()
.filter_map(|v| {
if let Value::Str(s) = v {
Some(s.clone())
} else {
None
}
})
.collect();
for expected_theme in expected {
assert!(
theme_strings.contains(&expected_theme.to_string()),
"Theme '{}' should be in the list. Available: {:?}",
expected_theme,
theme_strings
);
}
}
}
#[test]
fn test_config_get_theme() {
let mut env = Env::default();
let stmts = parser::parse_program(r#"config_get("colors.theme")"#).unwrap();
let result = eval::eval_program(&stmts, &mut env).unwrap();
match result {
Value::Str(theme_name) => {
assert!(!theme_name.is_empty(), "Theme name should not be empty");
}
Value::Null => {
}
other => panic!("config_get for theme should return Str, got {:?}", other),
}
}
#[test]
fn test_all_themes_are_strings() {
let mut env = Env::default();
let stmts = parser::parse_program("themes()").unwrap();
let result = eval::eval_program(&stmts, &mut env).unwrap();
if let Value::Array(themes) = result {
for (i, theme) in themes.iter().enumerate() {
match theme {
Value::Str(s) => {
assert!(!s.is_empty(), "Theme at index {} should not be empty", i);
}
other => panic!("Theme at index {} should be Str, got {:?}", i, other),
}
}
}
}
#[test]
fn test_theme_lookup_with_in() {
let mut env = Env::default();
let code = r#"in("catppuccin", themes())"#;
let stmts = parser::parse_program(code).unwrap();
let result = eval::eval_program(&stmts, &mut env).unwrap();
match result {
Value::Bool(true) => {}
other => panic!("catppuccin should be in themes(), got {:?}", other),
}
}
#[test]
fn test_themes_order_consistent() {
let mut env = Env::default();
let stmts = parser::parse_program("themes()").unwrap();
let result1 = eval::eval_program(&stmts, &mut env.clone()).unwrap();
let result2 = eval::eval_program(&stmts, &mut env).unwrap();
match (&result1, &result2) {
(Value::Array(a1), Value::Array(a2)) => {
assert_eq!(a1.len(), a2.len(), "Theme count should be consistent");
for (i, (t1, t2)) in a1.iter().zip(a2.iter()).enumerate() {
assert_eq!(t1, t2, "Theme at index {} should be consistent", i);
}
}
_ => panic!("Both calls should return arrays"),
}
}