mirror of
https://github.com/jzillmann/pdf-to-markdown.git
synced 2024-11-24 08:43:31 +01:00
09facb09b4
* Way to do the markdown transformation of inline formats (bold, italic, link, footnote, etc..) at the end and not in the middle * Introduce StashingStream as a helper
134 lines
5.1 KiB
JavaScript
134 lines
5.1 KiB
JavaScript
import { expect } from 'chai';
|
|
|
|
import HeadlineFinder from '../src/javascript/models/HeadlineFinder';
|
|
import LineItem from '../src/javascript/models/LineItem.jsx';
|
|
|
|
describe('HeadlineFinder', () => {
|
|
|
|
it('Not Found - Case 1', () => {
|
|
const headlineFinder = new HeadlineFinder({
|
|
headline: 'My Little Headline'
|
|
});
|
|
const item1 = new LineItem({
|
|
text: 'My '
|
|
});
|
|
const item2 = new LineItem({
|
|
text: 'Little'
|
|
});
|
|
const item3 = new LineItem({
|
|
text: ' Headline2'
|
|
});
|
|
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
|
expect(headlineFinder.consume(item3)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(0);
|
|
|
|
});
|
|
|
|
it('Found - Simple', () => {
|
|
const headlineFinder = new HeadlineFinder({
|
|
headline: 'My Little Headline'
|
|
});
|
|
const item1 = new LineItem({
|
|
text: 'My '
|
|
});
|
|
const item2 = new LineItem({
|
|
text: 'Little'
|
|
});
|
|
const item3 = new LineItem({
|
|
text: ' Headline'
|
|
});
|
|
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
|
expect(headlineFinder.consume(item3)).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
|
|
|
});
|
|
|
|
it('Found - Waste in beginning', () => {
|
|
const headlineFinder = new HeadlineFinder({
|
|
headline: 'My Little Headline'
|
|
});
|
|
const item0 = new LineItem({
|
|
text: 'Waste '
|
|
});
|
|
const item1 = new LineItem({
|
|
text: 'My '
|
|
});
|
|
const item2 = new LineItem({
|
|
text: 'Little'
|
|
});
|
|
const item3 = new LineItem({
|
|
text: ' Headline'
|
|
});
|
|
|
|
expect(headlineFinder.consume(item0)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(0);
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
|
expect(headlineFinder.consume(item3)).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
|
|
|
});
|
|
|
|
it('Found - Duplicate in beginning', () => {
|
|
const headlineFinder = new HeadlineFinder({
|
|
headline: 'My Little Headline'
|
|
});
|
|
const item0 = new LineItem({
|
|
text: 'My '
|
|
});
|
|
const item1 = new LineItem({
|
|
text: 'My '
|
|
});
|
|
const item2 = new LineItem({
|
|
text: 'Little'
|
|
});
|
|
const item3 = new LineItem({
|
|
text: ' Headline'
|
|
});
|
|
|
|
expect(headlineFinder.consume(item0)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item0);
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
|
expect(headlineFinder.consume(item3)).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
|
|
|
});
|
|
|
|
it('Found - Mixed up case and Whitespace', () => {
|
|
const headlineFinder = new HeadlineFinder({
|
|
headline: 'MYLitt le HEADline'
|
|
});
|
|
const item1 = new LineItem({
|
|
text: 'My '
|
|
});
|
|
const item2 = new LineItem({
|
|
text: 'Little'
|
|
});
|
|
const item3 = new LineItem({
|
|
text: ' Headline'
|
|
});
|
|
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
|
expect(headlineFinder.consume(item3)).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
|
|
|
});
|
|
|
|
});
|