Files
figcraft/crates/mcp/tests/export_xml.rs
T
Filip Strajnar eae9546878 M6: export as Android Vector Drawable (XML)
ExportFormat::VectorDrawable ("XML", .xml) and ExportSetting.vd_compat
(bestEffort / exact / ignore, stored only when not the default) wire the
figcraft-vectordrawable writer into file.export, file.exportLayers and
export.add/update: a vdCompat param (junk refused), svgIdAttribute writes
android:name, and the results carry the writer's warnings (per file for
export layers). The Export section lists XML with an "Android Vector
Drawable" tooltip and its id attribute and compatibility options, File >
Export... gets an XML preset, and the toasts say when content was changed
or left out. CLI: --format xml / .xml outputs, --vd-compat, warnings as
note: lines. MCP: format xml returns the XML as text plus its warnings.
A .fig export writes XML settings as SVG with a note.

Docs: file-format-parity (row and revision), ui-parity and roadmap
revisions, architecture (the crate), cli and mcp.
2026-10-18 20:39:46 +02:00

31 lines
1.6 KiB
Rust

//! The `export` tool's Android Vector Drawable format: the XML as text, then its warnings.
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod common;
use common::Client;
use serde_json::{Value, json};
#[test]
fn xml_comes_back_as_text_and_its_warnings() {
let mut c = Client::new();
let id = c.create(json!({"type": "rectangle", "x": 0, "y": 0, "width": 24, "height": 16}));
let r = c.call("export", json!({"ids": [id], "format": "xml"}));
assert_eq!(r["isError"], false, "{r}");
let blocks = r["content"].as_array().unwrap();
let xml = blocks[0]["text"].as_str().unwrap();
assert!(xml.starts_with("<?xml") && xml.contains("android:width=\"24dp\"") && xml.contains("android:height=\"16dp\""), "{xml}");
let info: Value = serde_json::from_str(blocks[1]["text"].as_str().unwrap()).unwrap();
assert_eq!((info["format"].as_str(), info["warnings"].as_array().map(Vec::len)), (Some("xml"), Some(0)));
c.ok("set_properties", json!({"ids": [id], "props": {"effects": [{"type": "dropShadow"}]}}));
let r = c.call("export", json!({"ids": [id], "format": "xml"}));
let info: Value = serde_json::from_str(r["content"][1]["text"].as_str().unwrap()).unwrap();
assert_eq!(info["warnings"], json!(["drop shadows were left out (Rectangle)"]), "{info}");
let r = c.call("export", json!({"ids": [id], "format": "xml", "vdCompat": "ignore"}));
let info: Value = serde_json::from_str(r["content"][1]["text"].as_str().unwrap()).unwrap();
assert_eq!(info["warnings"], json!([]));
assert!(c.err("export", json!({"ids": [id], "format": "xml", "vdCompat": "loose"})).contains("vdCompat"));
}