All files / vscode-extension/src/preview inspection.ts

88.88% Statements 8/9
66.66% Branches 6/9
100% Functions 2/2
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                                        13x 13x 13x 13x 12x 12x         13x    
import {
  detectPhotometricFormat,
  inspectParsedPhotometry,
  validatePhotometry,
  type PhotometryInspection,
} from '@ies-tools/core';
import type { PhotometryValidation } from '@ies-tools/viewer/react';
 
export interface InspectionState {
  inspection: PhotometryInspection | null;
  validation: PhotometryValidation;
  inspectionError: string | null;
}
/** The preview and CLI share core validation/inspection. Parsed profiles avoid a second parse here. */
export function inspectPreview(
  text: string,
  format?: 'ies' | 'ldt',
  strict = false,
  lampSetIndex?: number,
): InspectionState {
  const validation = validatePhotometry(text, format ?? detectPhotometricFormat(text), strict, lampSetIndex);
  let inspection: PhotometryInspection | null = null;
  let inspectionError: string | null = null;
  if (validation.profile && !validation.diagnostics.some((item) => item.severity === 'error')) {
    try {
      inspection = inspectParsedPhotometry(validation.profile, lampSetIndex);
    } catch (error) {
      inspectionError = error instanceof Error ? error.message : String(error);
    }
  }
  return { inspection, validation: { valid: validation.valid, diagnostics: validation.diagnostics }, inspectionError };
}