Skip to content

Commit aea769d

Browse files
authored
test(export3d): verify STL output is valid ASCII STL format (JhaSourav07#1173)
2 parents 89effb5 + ae7f920 commit aea769d

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

lib/export3d.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,43 @@ describe('generateMonolithSTL', () => {
4949
expect(stl).toContain('endsolid commitpulse_monolith');
5050
});
5151
});
52+
53+
it('generates structurally valid ASCII STL facets', () => {
54+
const mockTowers: TowerData[] = [
55+
{
56+
x: 0,
57+
y: 0,
58+
h: 10,
59+
hasCommits: true,
60+
isGhost: false,
61+
isToday: false,
62+
isTodayWithCommits: false,
63+
tooltip: '',
64+
contributionCount: 5,
65+
faceOpacity: { left: 1, right: 1, top: 1 },
66+
strokeOpacity: 1,
67+
strokeWidth: 1,
68+
row: 0,
69+
col: 0,
70+
},
71+
];
72+
73+
const stl = generateMonolithSTL(mockTowers);
74+
75+
const facetCount = (stl.match(/facet normal/g) ?? []).length;
76+
const endFacetCount = (stl.match(/endfacet/g) ?? []).length;
77+
78+
const outerLoopCount = (stl.match(/outer loop/g) ?? []).length;
79+
const endLoopCount = (stl.match(/endloop/g) ?? []).length;
80+
81+
expect(facetCount).toBe(endFacetCount);
82+
expect(outerLoopCount).toBe(endLoopCount);
83+
84+
const vertexLines = stl.split('\n').filter((line) => line.trim().startsWith('vertex'));
85+
86+
expect(vertexLines.length).toBeGreaterThan(0);
87+
88+
vertexLines.forEach((line) => {
89+
expect(line.trim()).toMatch(/^vertex -?\d+\.\d+ -?\d+\.\d+ -?\d+\.\d+$/);
90+
});
91+
});

0 commit comments

Comments
 (0)