import { describe, expect, it } from 'vitest'; import { readFileSync } from 'node:fs'; import { BEARING_ELEVATION_REF } from '../src/core/bearing-ref'; import { parseBearingElevationTable, readDxfTexts, type DxfText } from '../src/core/dxf-table'; const texts = JSON.parse(readFileSync(new URL('./fixtures/bearing-table-texts.json', import.meta.url), 'utf-8')) as DxfText[]; describe('도면 받침 ELEVATION TABLE 읽기 (DXF 텍스트, 승인 2026-10-23)', () => { it('reads all ten bearings from the 운곡교 교각도(2) table', () => { const r = parseBearingElevationTable(texts); expect(r.errors).toEqual([]); expect(r.drawing.map((d) => d.no)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); }); it('the values equal the reference table used for the 도면 비교 (EL.X, h1, h2 on every bearing)', () => { const r = parseBearingElevationTable(texts); for (const ref of BEARING_ELEVATION_REF) { const got = r.drawing.find((d) => d.no === ref.no)!; expect(got.elx, `No ${ref.no} EL.X`).toBeCloseTo(ref.elx, 3); expect(got.h1, `No ${ref.no} h1`).toBe(ref.h1); expect(got.h2, `No ${ref.no} h2`).toBe(ref.h2); } }); it('a leader-line "EL. X" label placed before the table does not replace the table header', () => { const distractor = { x: 11102.8, y: 11521.7, text: 'EL. "X"' }; const r = parseBearingElevationTable([distractor, ...texts]); expect(r.errors).toEqual([]); expect(r.drawing.map((d) => d.no)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); }); it('a stray "NO" label elsewhere on the drawing does not move the No column', () => { const r = parseBearingElevationTable([{ x: 100, y: 100, text: 'NO.' }, ...texts]); expect(r.errors).toEqual([]); expect(r.drawing.map((d) => d.no)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); }); it('reads TEXT entities from DXF text (x, y, string)', () => { const dxf = ['0', 'SECTION', '2', 'ENTITIES', '0', 'TEXT', '10', '100.5', '20', '200.25', '1', 'EL. "X"', '0', 'ENDSEC'].join('\n'); expect(readDxfTexts(dxf)).toEqual([{ x: 100.5, y: 200.25, text: 'EL. "X"' }]); }); }); import { parseSolplateTable } from '../src/core/dxf-table'; import { SOLPLATE_REF } from '../src/core/bearing-ref'; describe('솔플레이트 TABLE 읽기 (승인 2026-10-23)', () => { const sp = JSON.parse(readFileSync(new URL('./fixtures/solplate-table-texts.json', import.meta.url), 'utf-8')) as DxfText[]; it('a stray "S(%)" label elsewhere on the drawing does not replace the solplate header', () => { const r = parseSolplateTable([{ x: 16000, y: 16200, text: 'S(%)' }, ...sp]); expect(r.errors).toEqual([]); expect(r.rows.length).toBe(10); }); it('reads S, L, W, T, T1 and T2 for all ten bearings, and they equal the reference values', () => { const r = parseSolplateTable(sp); expect(r.errors).toEqual([]); expect(r.rows.map((x) => x.no)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); for (const ref of SOLPLATE_REF) { const got = r.rows.find((x) => x.no === ref.no)!; expect(got.S, `No ${ref.no} S`).toBeCloseTo(ref.s, 3); expect(got.L, `No ${ref.no} L`).toBe(ref.L); expect(got.W, `No ${ref.no} W`).toBe(ref.W); expect(got.T, `No ${ref.no} T`).toBe(30); expect(got.T1, `No ${ref.no} T1`).toBe(38); expect(got.T2, `No ${ref.no} T2`).toBe(22); } }); });