import assert from 'node:assert/strict'; import { test } from 'node:test'; import { citeKey, toBibtex } from './citations.js'; import { HttpError, cleanPath, isTextPath } from './util.js'; test('cleanPath yolları normalleştirir', () => { assert.equal(cleanPath('bolumler\\giris.tex'), 'bolumler/giris.tex'); assert.equal(cleanPath('./a//b/./c.tex'), 'a/b/c.tex'); assert.equal(cleanPath('Şekil 1.png'), 'Şekil 1.png'); }); test('cleanPath proje dışına çıkan yolları reddeder', () => { for (const bad of ['../gizli.tex', 'a/../../b.tex', '', '/', 'a:b.tex', 42, 'x'.repeat(201)]) { assert.throws(() => cleanPath(bad), HttpError, String(bad)); } }); test('isTextPath uzantıya göre karar verir', () => { assert.ok(isTextPath('main.tex')); assert.ok(isTextPath('kaynakca.BIB')); assert.ok(!isTextPath('sekil.png')); }); test('citeKey Türkçe karakterleri sadeleştirir ve dolgu sözcükleri atlar', () => { assert.equal(citeKey(['Öztürk, Çağrı'], 2021, 'Bir Eğitim Araştırması'), 'ozturk2021egitim'); assert.equal(citeKey(['Yann LeCun'], 2015, 'Deep learning'), 'lecun2015deep'); assert.equal(citeKey([], null, 'The Art'), 'anonimart'); }); test('toBibtex boş alanları atlar ve özel karakterleri kaçırır', () => { const bib = toBibtex('article', 'a2020b', { title: 'R&D 100%', volume: null, doi: '10.1/a_b' }); assert.equal(bib, '@article{a2020b,\n title = {R\\&D 100\\%},\n doi = {10.1/a_b}\n}'); });