From 0296e8411e528ae1c39a5d8231ba2ec89fa2633e Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 4 Oct 2022 10:15:35 -0500 Subject: Fixes to entity extraction --- __tests__/App-test.tsx | 26 +++++++++++++------------- __tests__/string-utils.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 __tests__/string-utils.ts (limited to '__tests__') diff --git a/__tests__/App-test.tsx b/__tests__/App-test.tsx index 47060512c..db34ec617 100644 --- a/__tests__/App-test.tsx +++ b/__tests__/App-test.tsx @@ -1,16 +1,16 @@ -/** - * @format - */ +// /** +// * @format +// */ -import 'react-native' -import React from 'react' -import App from '../src/App' +// import 'react-native' +// import React from 'react' +// import App from '../src/App' -// Note: test renderer must be required after react-native. -import renderer from 'react-test-renderer' +// // Note: test renderer must be required after react-native. +// import renderer from 'react-test-renderer' -it('renders correctly', () => { - renderer.act(() => { - renderer.create() - }) -}) +// it('renders correctly', () => { +// renderer.act(() => { +// renderer.create() +// }) +// }) diff --git a/__tests__/string-utils.ts b/__tests__/string-utils.ts new file mode 100644 index 000000000..9e0cd1c3e --- /dev/null +++ b/__tests__/string-utils.ts @@ -0,0 +1,47 @@ +import {extractEntities} from '../src/view/lib/strings' + +describe('extractEntities', () => { + const inputs = [ + 'no mention', + '@start middle end', + 'start @middle end', + 'start middle @end', + '@start @middle @end', + '@full123.test-of-chars', + 'not@right', + '@bad!@#$chars', + '@newline1\n@newline2', + ] + const outputs = [ + undefined, + [{index: [0, 6], type: 'mention', value: 'start'}], + [{index: [6, 13], type: 'mention', value: 'middle'}], + [{index: [13, 17], type: 'mention', value: 'end'}], + [ + {index: [0, 6], type: 'mention', value: 'start'}, + {index: [7, 14], type: 'mention', value: 'middle'}, + {index: [15, 19], type: 'mention', value: 'end'}, + ], + [{index: [0, 22], type: 'mention', value: 'full123.test-of-chars'}], + undefined, + [{index: [0, 4], type: 'mention', value: 'bad'}], + [ + {index: [0, 9], type: 'mention', value: 'newline1'}, + {index: [10, 19], type: 'mention', value: 'newline2'}, + ], + ] + it('correctly handles a set of text inputs', () => { + for (let i = 0; i < inputs.length; i++) { + const input = inputs[i] + const output = extractEntities(input) + expect(output).toEqual(outputs[i]) + if (output) { + for (const outputItem of output) { + expect(input.slice(outputItem.index[0], outputItem.index[1])).toBe( + `@${outputItem.value}`, + ) + } + } + } + }) +}) -- cgit 1.4.1