import { describe, expect, it } from 'vitest'; import { VS_NFD_PROFILE, VS_NFD_PROFILE_ADVISORY, describeCompliance, isVsNfdCompliant, vsNfdModeSchema, } from './vs-nfd-profile'; describe('vsNfdModeSchema (issue #243)', () => { it('accepts the four modes and rejects anything else', () => { for (const mode of ['off', 'marked', 'hidden', 'enforced']) { expect(vsNfdModeSchema.parse(mode)).toBe(mode); } expect(() => vsNfdModeSchema.parse('strict')).toThrow(); }); }); describe('isVsNfdCompliant', () => { const entry = (compliance: (typeof VS_NFD_PROFILE)[number]['compliance']) => ({ scope: 'instance', key: 'x', compliance, hardeningRef: '1.1' }) as const; it('equals compares strictly — no truthiness shortcuts', () => { expect(isVsNfdCompliant(entry({ kind: 'equals', value: false }), false)).toBe(true); expect(isVsNfdCompliant(entry({ kind: 'equals', value: false }), 'false')).toBe(false); expect(isVsNfdCompliant(entry({ kind: 'equals', value: 'closed' }), 'closed')).toBe(true); expect(isVsNfdCompliant(entry({ kind: 'equals', value: 'closed' }), 'open')).toBe(false); }); it('maxNumber bounds numeric values and rejects non-numbers', () => { expect(isVsNfdCompliant(entry({ kind: 'maxNumber', value: 12 }), 12)).toBe(true); expect(isVsNfdCompliant(entry({ kind: 'maxNumber', value: 12 }), 13)).toBe(false); expect(isVsNfdCompliant(entry({ kind: 'maxNumber', value: 12 }), '2')).toBe(false); }); it('nonEmpty requires actual text', () => { expect(isVsNfdCompliant(entry({ kind: 'nonEmpty' }), 'Impressum')).toBe(true); expect(isVsNfdCompliant(entry({ kind: 'nonEmpty' }), ' ')).toBe(false); expect(isVsNfdCompliant(entry({ kind: 'nonEmpty' }), undefined)).toBe(false); }); }); describe('catalog shape', () => { it('lists every key at most once per scope, disjoint from the advisory list', () => { const keyOf = (e: { scope: string; key: string }) => `${e.scope}:${e.key}`; const catalog = VS_NFD_PROFILE.map(keyOf); const advisory = VS_NFD_PROFILE_ADVISORY.map(keyOf); expect(new Set(catalog).size).toBe(catalog.length); expect(new Set(advisory).size).toBe(advisory.length); expect(catalog.filter((key) => advisory.includes(key))).toEqual([]); }); it('describes every predicate for display', () => { for (const entry of VS_NFD_PROFILE) { expect(describeCompliance(entry.compliance)).not.toBe(''); } }); });