From 4834a0b0a3eedd015ff669c27a233f979da57959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Parmentier?= Date: Wed, 29 Mar 2023 09:17:00 +0200 Subject: [PATCH] test(basics): Adapt test to new expected structure --- packages/basics/test/txt-sentences.js | 98 ++++++++++++++++++++------- 1 file changed, 73 insertions(+), 25 deletions(-) diff --git a/packages/basics/test/txt-sentences.js b/packages/basics/test/txt-sentences.js index 69aab776..b1fcae54 100644 --- a/packages/basics/test/txt-sentences.js +++ b/packages/basics/test/txt-sentences.js @@ -1,4 +1,5 @@ import from from 'from'; +// @ts-ignore import ezs from '../../core/src'; import ezsBasics from '../src'; @@ -6,130 +7,177 @@ 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(); }); });