about summary refs log tree commit diff
path: root/__tests__
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-10-04 10:15:35 -0500
committerPaul Frazee <pfrazee@gmail.com>2022-10-04 10:15:35 -0500
commit0296e8411e528ae1c39a5d8231ba2ec89fa2633e (patch)
tree476b1b963eeb957644175c9f1522330f19e87bd3 /__tests__
parent195d2f7d2bd193108938901c3f757a9e89080b63 (diff)
downloadvoidsky-0296e8411e528ae1c39a5d8231ba2ec89fa2633e.tar.zst
Fixes to entity extraction
Diffstat (limited to '__tests__')
-rw-r--r--__tests__/App-test.tsx26
-rw-r--r--__tests__/string-utils.ts47
2 files changed, 60 insertions, 13 deletions
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(<App />)
-  })
-})
+// it('renders correctly', () => {
+//   renderer.act(() => {
+//     renderer.create(<App />)
+//   })
+// })
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}`,
+          )
+        }
+      }
+    }
+  })
+})