Fixes to entity extraction

This commit is contained in:
Paul Frazee 2022-10-04 10:15:35 -05:00
parent 195d2f7d2b
commit 0296e8411e
5 changed files with 83 additions and 37 deletions

View file

@ -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(<App />)
})
})
// it('renders correctly', () => {
// renderer.act(() => {
// renderer.create(<App />)
// })
// })

47
__tests__/string-utils.ts Normal file
View file

@ -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}`,
)
}
}
}
})
})