Skip to content

Commit

Permalink
test(basics): Adapt test to new expected structure
Browse files Browse the repository at this point in the history
  • Loading branch information
parmentf committed Mar 29, 2023
1 parent 252dd22 commit 4834a0b
Showing 1 changed file with 73 additions and 25 deletions.
98 changes: 73 additions & 25 deletions packages/basics/test/txt-sentences.js
Original file line number Diff line number Diff line change
@@ -1,135 +1,183 @@
import from from 'from';
// @ts-ignore
import ezs from '../../core/src';
import ezsBasics from '../src';

ezs.use(ezsBasics);

describe('TXTSentences', () => {
it('should return an array', (done) => {
from([''])
let res = [];
from([{ value: '' }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
expect(Array.isArray(data)).toBe(true);
expect(data).toStrictEqual([]);
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual([{ value: [] }]);
done();
});
});

it('should generate two sentences', (done) => {
let res = [];
from(['After all. These are two sentences.'])
from([{ value: 'After all. These are two sentences.' }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual(['After all.', 'These are two sentences.']);
expect(res).toStrictEqual([
{ value: ['After all.', 'These are two sentences.'] },
]);
done();
});
});

it('should return an empty array when input is not a string', (done) => {
it('should take path parameter into account', (done) => {
let res = [];
from([{}])
.pipe(ezs('TXTSentences'))
from([{ other: 'After all. These are two sentences.' }])
.pipe(ezs('TXTSentences', { path: 'other' }))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual([]);
expect(res).toStrictEqual([
{ other: ['After all.', 'These are two sentences.'] },
]);
done();
});
});

it('should generate two values from a Buffer', (done) => {
it('should generate three sentences', (done) => {
let res = [];
from([Buffer.from('Sentence 1. Sentence 2.')])
from([{ value: 'And now. Three sentences. Indeed.' }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual(['Sentence 1.', 'Sentence 2.']);
expect(res).toStrictEqual([
{ value: ['And now.', 'Three sentences.', 'Indeed.'] },
]);
done();
});
});

it('should generate from several chunks', (done) => {
it('should return an empty array when input is not a string', (done) => {
let res = [];
from(['Senten', 'ce 1. Sent', 'ence 2.'])
from([{ value: {} }, { value: 1 }, { value: true }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual(['Sentence 1.', 'Sentence 2.']);
expect(res).toStrictEqual([
{ value: [] },
{ value: [] },
{ value: [] },
]);
done();
});
});

it('should generate two sentences with other endings', (done) => {
let res = [];
from(['Is it? It is!'])
from([{ value: 'Is it? It is!' }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual(['Is it?', 'It is!']);
expect(res).toStrictEqual([{ value: ['Is it?', 'It is!'] }]);
done();
});
});

it('should not split initials in the middle of a sentence', (done) => {
let res = [];
from(['My name is Bond, J. Bond.'])
from([{ value: 'My name is Bond, J. Bond.' }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual(['My name is Bond, J. Bond.']);
expect(res).toStrictEqual([
{ value: ['My name is Bond, J. Bond.'] },
]);
done();
});
});

it('should not split initials at the beginning of a sentence', (done) => {
let res = [];
from(['C. Norris, that means Chuck Norris.'])
from([{ value: 'C. Norris, that means Chuck Norris.' }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual([
{ value: ['C. Norris, that means Chuck Norris.'] },
]);
done();
});
});

it('should return an array already segmented', (done) => {
let res = [];
from([{ value: ['Sentence 1.', 'Sentence 2.'] }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual([
{ value: ['Sentence 1.', 'Sentence 2.'] },
]);
done();
});
});

it('should segment again an array wrongly segmented', (done) => {
let res = [];
from([{ value: ['Sentence', '1. Sentence 2.'] }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual(['C. Norris, that means Chuck Norris.']);
expect(res).toStrictEqual([
{ value: ['Sentence 1.', 'Sentence 2.'] },
]);
done();
});
});

it.skip('should not split abbreviations in a sentence', (done) => {
let res = [];
from(['Born in the U.S.A.'])
from([{ value: 'Born in the U.S.A.' }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual(['Born in the U.S.A.']);
expect(res).toStrictEqual([{ value: ['Born in the U.S.A.'] }]);
done();
});
});

it.skip('should not split abbreviations at the end of a sentence', (done) => {
let res = [];
from(['Don\'t use T.N.T. inside buildings.'])
from([{ value: 'Don\'t use T.N.T. inside buildings.' }])
.pipe(ezs('TXTSentences'))
.on('data', (data) => {
res = [...res, data];
})
.on('end', () => {
expect(res).toStrictEqual(['Don\'t use T.N.T. inside buildings.']);
expect(res).toStrictEqual([
{ value: ['Don\'t use T.N.T. inside buildings.'] },
]);
done();
});
});
Expand Down

0 comments on commit 4834a0b

Please sign in to comment.