pdf-to-markdown/test/HeadlineFinder.spec.js

134 lines
5.1 KiB
JavaScript
Raw Normal View History

2017-03-07 18:42:14 +01:00
import { expect } from 'chai';
import HeadlineFinder from '../src/javascript/models/HeadlineFinder';
import LineItem from '../src/javascript/models/LineItem.jsx';
2017-03-07 18:42:14 +01:00
describe('HeadlineFinder', () => {
it('Not Found - Case 1', () => {
const headlineFinder = new HeadlineFinder({
headline: 'My Little Headline'
});
const item1 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'My '
});
const item2 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'Little'
});
const item3 = new LineItem({
2017-03-07 18:42:14 +01:00
text: ' Headline2'
});
expect(headlineFinder.consume(item1)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
2017-03-07 18:42:14 +01:00
expect(headlineFinder.consume(item2)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
2017-03-07 18:42:14 +01:00
expect(headlineFinder.consume(item3)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(0);
2017-03-07 18:42:14 +01:00
});
it('Found - Simple', () => {
const headlineFinder = new HeadlineFinder({
headline: 'My Little Headline'
});
const item1 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'My '
});
const item2 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'Little'
});
const item3 = new LineItem({
2017-03-07 18:42:14 +01:00
text: ' Headline'
});
expect(headlineFinder.consume(item1)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
2017-03-07 18:42:14 +01:00
expect(headlineFinder.consume(item2)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
2017-03-07 18:42:14 +01:00
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);
2017-03-07 18:42:14 +01:00
});
it('Found - Waste in beginning', () => {
const headlineFinder = new HeadlineFinder({
headline: 'My Little Headline'
});
const item0 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'Waste '
});
const item1 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'My '
});
const item2 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'Little'
});
const item3 = new LineItem({
2017-03-07 18:42:14 +01:00
text: ' Headline'
});
expect(headlineFinder.consume(item0)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(0);
2017-03-07 18:42:14 +01:00
expect(headlineFinder.consume(item1)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
2017-03-07 18:42:14 +01:00
expect(headlineFinder.consume(item2)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
2017-03-07 18:42:14 +01:00
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);
2017-03-07 18:42:14 +01:00
});
it('Found - Duplicate in beginning', () => {
const headlineFinder = new HeadlineFinder({
headline: 'My Little Headline'
});
const item0 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'My '
});
const item1 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'My '
});
const item2 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'Little'
});
const item3 = new LineItem({
2017-03-07 18:42:14 +01:00
text: ' Headline'
});
expect(headlineFinder.consume(item0)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item0);
2017-03-07 18:42:14 +01:00
expect(headlineFinder.consume(item1)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
2017-03-07 18:42:14 +01:00
expect(headlineFinder.consume(item2)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
2017-03-07 18:42:14 +01:00
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);
2017-03-07 18:42:14 +01:00
});
it('Found - Mixed up case and Whitespace', () => {
const headlineFinder = new HeadlineFinder({
headline: 'MYLitt le HEADline'
});
const item1 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'My '
});
const item2 = new LineItem({
2017-03-07 18:42:14 +01:00
text: 'Little'
});
const item3 = new LineItem({
2017-03-07 18:42:14 +01:00
text: ' Headline'
});
expect(headlineFinder.consume(item1)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
2017-03-07 18:42:14 +01:00
expect(headlineFinder.consume(item2)).to.equal(null);
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
2017-03-07 18:42:14 +01:00
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);
2017-03-07 18:42:14 +01:00
});
});