From 7c45d027a833a5038660952873424465b25e1e55 Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Mon, 21 Sep 2026 22:40:43 +0800 Subject: test(desktop): CJK 清单唯一性与图集网格防复发断言 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 断言 cjk-glyphs.txt 非空、每行恰 1 字符、字符唯一 - 读 cjk-glyph-atlas.png IHDR,断言 16 列且网格容量覆盖清单、无多余空行 --- src/LivingVillage.Desktop.Tests/PrototypeTests.fs | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/LivingVillage.Desktop.Tests/PrototypeTests.fs b/src/LivingVillage.Desktop.Tests/PrototypeTests.fs index d5602e8..eeafb56 100644 --- a/src/LivingVillage.Desktop.Tests/PrototypeTests.fs +++ b/src/LivingVillage.Desktop.Tests/PrototypeTests.fs @@ -1018,3 +1018,36 @@ type PrototypeTests () = |> List.filter (fun relativePath -> not (File.Exists(Path.Combine(AppContext.BaseDirectory, relativePath)))) Assert.AreEqual([], missing, sprintf "Missing Jiangnan PNG assets: %s" (String.concat ", " missing)) + + [] + member _.CjkGlyphManifestIsUniqueAndMatchesAtlasGrid () = + // 防复发:图集用字增长时,清单必须非空、每行恰 1 个字符、字符唯一, + // 且与 16 列图集网格自洽(打包脚本不再硬编码行数)。 + let assets = Path.Combine(AppContext.BaseDirectory, "Assets") + let manifestPath = Path.Combine(assets, "cjk-glyphs.txt") + let atlasPath = Path.Combine(assets, "cjk-glyph-atlas.png") + Assert.IsTrue(File.Exists manifestPath, "missing cjk-glyphs.txt") + Assert.IsTrue(File.Exists atlasPath, "missing cjk-glyph-atlas.png") + + let lines = File.ReadAllLines manifestPath + Assert.IsTrue(lines.Length > 0, "CJK manifest must not be empty") + for index in 0 .. lines.Length - 1 do + Assert.AreEqual(1, lines.[index].Length) + Assert.AreEqual(lines.Length, (Set.ofArray lines).Count) + + let header = File.ReadAllBytes atlasPath + let be32 offset = + (int header.[offset] <<< 24) + ||| (int header.[offset + 1] <<< 16) + ||| (int header.[offset + 2] <<< 8) + ||| int header.[offset + 3] + let cell = 24 + let width = be32 16 + let height = be32 20 + Assert.AreEqual(0, width % cell) + Assert.AreEqual(0, height % cell) + let columns = width / cell + let capacity = columns * (height / cell) + Assert.AreEqual(16, columns) + Assert.IsTrue(capacity >= lines.Length, "CJK atlas grid must cover every manifest character") + Assert.IsTrue(capacity - lines.Length < columns, "CJK atlas must not keep an extra empty row") -- cgit v1.2.3