diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/html_renderer/assets.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/html_renderer/assets.rs index b4c433087..e2c74cb7e 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/html_renderer/assets.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/html_renderer/assets.rs @@ -54,6 +54,37 @@ pub(super) fn trim_float(value: f32) -> String { text.trim_end_matches('0').trim_end_matches('.').to_string() } +#[cfg(test)] +mod tests { + use super::font_face_rule; + use crate::ui_editor::resource::font::{FontAsset, FontAssetMetadata, FontFormat}; + use crate::ui_editor::utils::FontAssetId; + + fn font(format: FontFormat) -> FontAsset { + FontAsset { + asset_id: FontAssetId::new("font-main").expect("valid font id"), + metadata: FontAssetMetadata { + family_name: "测试字体".to_string(), + face_name: "Regular".to_string(), + weight: 400, + italic: false, + format, + source_file_name: format!("font.{}", format.extension()), + }, + path: format!("assets/font.{}", format.extension()), + content_sha256: "0".repeat(64), + } + } + + #[test] + fn font_face_rule_uses_standard_css_format_names() { + let truetype = font_face_rule(&font(FontFormat::TrueType), "ui-font").unwrap(); + let opentype = font_face_rule(&font(FontFormat::OpenType), "ui-font").unwrap(); + assert!(truetype.contains("format('truetype')")); + assert!(opentype.contains("format('opentype')")); + } +} + pub(super) fn hex_id(value: &str) -> String { value .as_bytes()