tests/cad: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:49:17 -05:00
1 parent 928ac9b39f
commit a07d4065a6
1 file changed
+3 -17
+3 -17
View File
@@ -1,9 +1,5 @@
-- cad/step tests: STEP files written by OCCT (solids modelled in gmsh's OpenCASCADE kernel) and public sample files,
-- against an independent Python Part 21 census (instances, count per type); our writer's output read back by OCCT
-- (solids, volume, faces, area, bounding box equal to the originals); parse -> write -> parse equality; every
-- parameter kind and string escape, complex instances, edition 3 sections, comments; the api (F.load / F.save /
-- F.cad.*); the B-rep plug-in path through brep-luau (luau CLI only: the alias in tests/gen/.luaurc) against OCCT's
-- volumes and bounds, and a custom plug-in table; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/step.py.
-- cad/step tests: OCCT-written and public STEP files against a Python Part 21 census, OCCT and brep-luau.
-- Fixtures: tools/fixtures/step.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Step = require("@rosetta/cad/step")
@@ -25,12 +21,10 @@ local function near(a: number, b: number, rel: number): boolean
return math.abs(a - b) <= rel * math.max(1, math.abs(a), math.abs(b))
end
-- 1. contract
t:eq(Step.name, "step", "name")
t:eq(Step.category, "cad", "category")
t:check(Step.caps.decode and Step.caps.encode and table.find(Step.extensions, "stp"), "contract")
-- deep equality of two decoded values (buffers, the real marks of lists included)
local function same(a: any, b: any, path: string, depth: number?): (boolean, string)
local d = depth or 0
if type(a) ~= "table" or type(b) ~= "table" then
@@ -69,7 +63,6 @@ local function same(a: any, b: any, path: string, depth: number?): (boolean, str
return true, path
end
-- 2. fixtures: census, round trips; OCCT read our output like the original
local decoded = {}
local samples = {}
local t0 = T.clock()
@@ -111,7 +104,6 @@ end
local dt = T.clock() - t0
t:note("%d files (%.1f MB): census, OCCT read-back, round trips (%.2f s)", #Cases, bytes / 1e6, dt)
-- 3. every parameter kind, escapes, complex instances, sections, comments
local CRAFT = [[
ISO-10303-21; /* a comment */
HEADER;
@@ -212,7 +204,6 @@ t:check(string.find(e3text, "ANCHOR;\n<http://example.org/a> = #1;\nENDSEC;", 1,
local e3b = decode(e3text)
t:check(e3b and same(e3.entities, e3b.entities, "e"), "ed3: round trip")
-- 4. building a file
local new = Step.new("AP242")
local pt = Step.add(new, "cartesian_point", { "origin", Step.real({ 0, 0, 1.25 }, 1) })
Step.add(new, "VERTEX_POINT", { "", { ref = pt } })
@@ -231,7 +222,6 @@ t:eq(bad3 and bad3.code, Err.ARG, "encode: cycle -> ARG")
local _, bad4 = Step.encode({ kind = "image" } :: any)
t:eq(bad4 and bad4.code, Err.ARG, "encode: not a Cad")
-- 5. errors and sniff
local function code(s: string, opts: any?): string?
local v, e = decode(s, opts)
return if v then nil else e.code
@@ -249,7 +239,6 @@ t:eq(Step.sniff(Bytes.reader(buffer.fromstring(CRAFT))), 1, "sniff")
t:eq(Step.sniff(Bytes.reader(buffer.fromstring("\239\187\191/* x */ ISO-10303-21;"))), 1, "sniff: BOM + comment")
t:eq(Step.sniff(Bytes.reader(buffer.fromstring("ISO-10303-28"))), 0, "sniff: other")
-- 6. the api
local loaded, lerr = F.load(CRAFT)
t:check(loaded and loaded.kind == "cad", "F.load: " .. tostring(lerr))
t:eq(F.detect(CRAFT), "step", "F.detect")
@@ -260,7 +249,6 @@ t:eq(nop and nop.code, Err.UNSUPPORTED, "toBodies without a plug-in")
local _, nop2 = F.cad.tessellate(loaded)
t:eq(nop2 and nop2.code, Err.UNSUPPORTED, "F.cad.tessellate without a plug-in")
-- 7. the plug-in: a custom interface table
local calls = {}
local fake = {
read = function(text: string, _opts: any): any
@@ -296,7 +284,7 @@ local fapi = F.cad.tessellate(loaded)
t:check(fapi and fapi.kind == "scene", "F.cad.tessellate through F.plugins")
F.plugins.brep = nil
-- 8. brep-luau (luau CLI: tests/gen/.luaurc aliases it; LuaJIT has no `vector` type: skipped)
-- brep-luau: luau CLI only (tests/gen/.luaurc aliases it); LuaJIT has no `vector` type
local function volume(scene: any): (number, { number })
local v = 0
local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge }
@@ -364,7 +352,6 @@ if brepOk then
end
end
end
-- kernel bodies -> our Cad -> our text -> bodies again
local M = brep.M
local part = brep.Boolean.subtract(brep.Build.box(M.v(0, 0, 0), M.v(40, 30, 5)), brep.Build.cylinder(M.v(20, 15, -1), 6, 7))[1]
part.color = { r = 0.2, g = 0.5, b = 0.9 }
@@ -383,7 +370,6 @@ else
t:note("brep-luau plug-in part skipped (%s)", if T.runtime ~= "luau" then "LuaJIT: no vector type" else "no ~/dev/luau/brep-luau")
end
-- 9. fuzz
table.insert(samples, buffer.fromstring(CRAFT))
table.insert(samples, buffer.fromstring(ED3))
t:fuzz("decode", function(b: buffer): any