Download server/synctex.test.js from SSSAssist/Thoth: direct link, hf CLI and curl.
- Browser
- Download file 2.53 kB
-
https://huggingface.co/spaces/SSSAssist/Thoth/resolve/main/server/synctex.test.js
- Command line
-
hf download hf://spaces/SSSAssist/Thoth/server/synctex.test.js
-
curl -L -o synctex.test.js https://huggingface.co/spaces/SSSAssist/Thoth/resolve/main/server/synctex.test.js
2.53 kB
| import assert from 'node:assert/strict'; | |
| import { mkdtempSync, writeFileSync } from 'node:fs'; | |
| import { tmpdir } from 'node:os'; | |
| import path from 'node:path'; | |
| import { test } from 'node:test'; | |
| import { gzipSync } from 'node:zlib'; | |
| import { forwardSearch, inverseSearch, loadSynctex } from './synctex.js'; | |
| const bp = (n) => Math.round(n * 65781.76); // PDF noktasını SyncTeX birimine (sp) çevirir | |
| // Tek sayfa: (100, 100) taban çizgisinde 200x10 bp'lik bir satır; satırda main.tex:5 ve bolum.tex:7'den sözcükler. | |
| const SAMPLE = `SyncTeX Version:1 | |
| Input:1:C:\\proje\\src\\main.tex | |
| Input:2: | |
| Input:3:C:\\proje\\src\\bolumler/bolum.tex | |
| Input:4:C:\\baska\\paket.sty | |
| Output:pdf | |
| Magnification:1000 | |
| Unit:1 | |
| X Offset:0 | |
| Y Offset:0 | |
| Content: | |
| !200 | |
| {1 | |
| [4,1:0,0:${bp(595)},${bp(842)},0 | |
| (1,5:${bp(100)},${bp(100)}:${bp(200)},${bp(10)},0 | |
| x1,5:${bp(100)},${bp(100)} | |
| x3,7:${bp(200)},${bp(100)} | |
| ) | |
| ] | |
| }1 | |
| Postamble: | |
| Count:4 | |
| `; | |
| function load() { | |
| const dir = mkdtempSync(path.join(tmpdir(), 'thoth-synctex-')); | |
| const file = path.join(dir, 'main.synctex.gz'); | |
| writeFileSync(file, gzipSync(SAMPLE)); | |
| return loadSynctex(file, 'C:\\proje\\src'); | |
| } | |
| test('girdi yolları proje içi yollara çevrilir, proje dışındakiler atlanır', () => { | |
| assert.deepEqual([...load().files], [[1, 'main.tex'], [3, 'bolumler/bolum.tex']]); | |
| }); | |
| test('ileri arama satırın sayfasını ve dikdörtgenini bp cinsinden verir', () => { | |
| const r = forwardSearch(load(), 'main.tex', 5); | |
| assert.equal(r.page, 1); | |
| assert.equal(r.rects.length, 1); | |
| const [{ x, y, w, h }] = r.rects; | |
| assert.deepEqual([x, y, w, h].map(Math.round), [100, 90, 200, 10]); | |
| }); | |
| test('kutu olmayan kayıtta içinde bulunduğu satır kullanılır', () => { | |
| const r = forwardSearch(load(), 'bolumler/bolum.tex', 7); | |
| assert.deepEqual(r.rects.map((q) => Math.round(q.x)), [100]); | |
| }); | |
| test('izi olmayan satırda yakındaki satıra düşülür', () => { | |
| assert.equal(forwardSearch(load(), 'main.tex', 6).line, 5); | |
| assert.equal(forwardSearch(load(), 'yok.tex', 1), null); | |
| }); | |
| test('geri arama tıklanan yerin solundaki en yakın kaydı bulur', () => { | |
| const data = load(); | |
| assert.deepEqual(inverseSearch(data, 1, 150, 95), { file: 'main.tex', line: 5 }); | |
| assert.deepEqual(inverseSearch(data, 1, 250, 95), { file: 'bolumler/bolum.tex', line: 7 }); | |
| }); | |
| test('kutu dışındaki tıklamada sayfadaki en yakın kayda düşülür', () => { | |
| assert.equal(inverseSearch(load(), 1, 120, 400).file, 'main.tex'); | |
| assert.equal(inverseSearch(load(), 2, 120, 400), null); | |
| }); | |