diff options
Diffstat (limited to '__tests__/string-utils.ts')
-rw-r--r-- | __tests__/string-utils.ts | 47 |
1 files changed, 47 insertions, 0 deletions
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}`, + ) + } + } + } + }) +}) |