49 lines
2.1 KiB
JavaScript
49 lines
2.1 KiB
JavaScript
const fs = require('fs/promises');
|
|
const path = require('path');
|
|
const { cleanTextract, dehyphenateLines, isStandalonePageNumber } = require('../src/clean');
|
|
|
|
describe('cleaning', () => {
|
|
it('dehyphenates a broken word and keeps a real compound', () => {
|
|
const joined = dehyphenateLines(['This is an exam-', 'ple of text.', 'The well-', 'known road.']);
|
|
expect(joined.lines[0]).toBe('This is an example of text.');
|
|
expect(joined.lines[1]).toBe('The well-known road.');
|
|
expect(joined.hyphenFixes).toBe(1);
|
|
});
|
|
|
|
it('recognizes arabic and roman page numbers', () => {
|
|
expect(isStandalonePageNumber('12')).toBe(true);
|
|
expect(isStandalonePageNumber('iv')).toBe(true);
|
|
expect(isStandalonePageNumber('I')).toBe(false);
|
|
expect(isStandalonePageNumber('Chapter 1')).toBe(false);
|
|
});
|
|
|
|
it('cleans the layout fixture', async () => {
|
|
const raw = JSON.parse(await fs.readFile(path.join(__dirname, 'fixtures/textract-layout.json'), 'utf8'));
|
|
const { pages } = cleanTextract([raw]);
|
|
const page1 = pages.find((page) => page.page === 1);
|
|
const page2 = pages.find((page) => page.page === 2);
|
|
const page3 = pages.find((page) => page.page === 3);
|
|
const page4 = pages.find((page) => page.page === 4);
|
|
|
|
expect(page1.text).toContain('example of a sentence');
|
|
expect(page1.text).not.toMatch(/exam-/);
|
|
expect(page1.text).not.toContain('Edition Banner');
|
|
expect(page1.text).not.toContain('Printed Footer');
|
|
expect(page1.text).not.toContain('Weekly Digest');
|
|
expect(page1.removedLines).toContain('Weekly Digest');
|
|
expect(page1.removedLines).toContain('Confidential');
|
|
expect(page1.printedLabel).toBe('12');
|
|
|
|
expect(page2.text.indexOf('Left column sentence.')).toBeLessThan(page2.text.indexOf('Right column sentence.'));
|
|
expect(page2.text).not.toContain('iv');
|
|
|
|
expect(page3.text).toContain('Ada 36');
|
|
expect(page3.text).toContain('Item one');
|
|
expect(page3.text).toContain('Item two');
|
|
|
|
expect(page4.text).toContain('well-known');
|
|
expect(page4.text).toContain('filigature');
|
|
expect(page4.text).not.toContain('\uFB01');
|
|
});
|
|
});
|