|
|
@@ -1,5 +1,8 @@
|
|
|
+import { mkdtempSync, rmSync, symlinkSync } from 'node:fs'
|
|
|
+import { tmpdir } from 'node:os'
|
|
|
+import { join } from 'node:path'
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
-import { findConcreteTermViolations } from './verify-concrete-terms.ts'
|
|
|
+import { findConcreteTermViolations, readTrackedSource } from './verify-concrete-terms.ts'
|
|
|
|
|
|
const blockedTerm = 'prove' + 'nance'
|
|
|
|
|
|
@@ -21,6 +24,27 @@ describe('concrete terminology policy', () => {
|
|
|
.toEqual([{ file: 'packages/example/src/source.ts', line: 1 }])
|
|
|
})
|
|
|
|
|
|
+ it('normalizes compatibility characters before scanning', () => {
|
|
|
+ const fullwidthTerm = blockedTerm.split('')
|
|
|
+ .map(character => String.fromCodePoint(character.charCodeAt(0) + 0xfee0))
|
|
|
+ .join('')
|
|
|
+ expect(findConcreteTermViolations('packages/example/src/source.ts', fullwidthTerm))
|
|
|
+ .toEqual([{ file: 'packages/example/src/source.ts', line: 1 }])
|
|
|
+ })
|
|
|
+
|
|
|
+ it.skipIf(process.platform === 'win32')('reads the target of a dangling tracked symlink', () => {
|
|
|
+ const repoRoot = mkdtempSync(join(tmpdir(), 'dsh-concrete-terms-'))
|
|
|
+ try {
|
|
|
+ symlinkSync(`../${blockedTerm}-target`, join(repoRoot, 'tracked-link'))
|
|
|
+ expect(findConcreteTermViolations(
|
|
|
+ 'tracked-link',
|
|
|
+ readTrackedSource(repoRoot, 'tracked-link') ?? '',
|
|
|
+ )).toEqual([{ file: 'tracked-link', line: 1 }])
|
|
|
+ } finally {
|
|
|
+ rmSync(repoRoot, { recursive: true, force: true })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
it('accepts exact replacement terms', () => {
|
|
|
expect(findConcreteTermViolations(
|
|
|
'packages/example/src/origin.ts',
|