use std::path::Path; use galaxy_util::standardized_path::StandardizedPath; use crate::{language_by_filename, language_by_local_filename, load_language, SUPPORTED_LANGUAGES}; /// Validate that every supported language can be loaded successfully. /// This catches invalid node types, syntax errors, and other issues in .scm query files /// (highlights, indents, identifiers) that would otherwise only surface at runtime. #[test] fn all_supported_languages_load_successfully() { let failures: Vec<_> = SUPPORTED_LANGUAGES .iter() .filter(|lang| load_language(lang).is_none()) .collect(); assert!( failures.is_empty(), "The following languages failed to load:\n{}", failures .iter() .map(|lang| format!(" - {lang}")) .collect::>() .join("\n") ); } /// Both `.html` and the legacy three-character `.htm` extension should resolve to /// the same HTML language entry. `.htm` is widely produced by static-site generators /// and historical web tooling (DOS 8.3 filename limits) and is already treated as /// an HTML/text file elsewhere in the codebase /// (see `is_development_text_extension` in `crates/warp_util/src/file_type.rs`). #[test] fn html_extensions_resolve_to_html() { for filename in ["index.html", "index.htm"] { let path = StandardizedPath::try_new(&format!("/tmp/{filename}")) .expect("test path should be absolute"); let language = language_by_filename(&path) .unwrap_or_else(|| panic!("expected {filename} to resolve to a language")); assert_eq!( language.display_name(), "HTML", "{filename} should resolve to HTML", ); } } #[test] fn local_html_extensions_resolve_to_html() { for filename in ["index.html", "index.htm"] { let path = Path::new(filename); let language = language_by_local_filename(path) .unwrap_or_else(|| panic!("expected {filename} to resolve to a language")); assert_eq!( language.display_name(), "HTML", "{filename} should resolve to HTML", ); } } /// `.command` is the macOS convention for double-clickable shell scripts. /// Make sure `language_by_filename` recognizes it as shell so the editor /// renders syntax highlighting instead of the /// "Language support is unavailable for this file type" footer. #[test] fn command_extension_resolves_to_shell() { let path = StandardizedPath::try_new("/tmp/script.command").expect("test path should be absolute"); let language = language_by_filename(&path).expect("`.command` files should resolve to a language"); assert_eq!(language.display_name(), "Shell"); } #[test] fn local_command_extension_resolves_to_shell() { let language = language_by_local_filename(Path::new("script.command")) .expect("`.command` files should resolve to a language"); assert_eq!(language.display_name(), "Shell"); }