about summary refs log tree commit diff
path: root/__tests__/lib/string.test.ts
diff options
context:
space:
mode:
Diffstat (limited to '__tests__/lib/string.test.ts')
-rw-r--r--__tests__/lib/string.test.ts164
1 files changed, 1 insertions, 163 deletions
diff --git a/__tests__/lib/string.test.ts b/__tests__/lib/string.test.ts
index 4f6fd62d6..f25bd02a7 100644
--- a/__tests__/lib/string.test.ts
+++ b/__tests__/lib/string.test.ts
@@ -7,172 +7,10 @@ import {
 } from '../../src/lib/strings/url-helpers'
 import {pluralize, enforceLen} from '../../src/lib/strings/helpers'
 import {ago} from '../../src/lib/strings/time'
-import {
-  extractEntities,
-  detectLinkables,
-} from '../../src/lib/strings/rich-text-detection'
+import {detectLinkables} from '../../src/lib/strings/rich-text-detection'
 import {makeValidHandle, createFullHandle} from '../../src/lib/strings/handles'
 import {cleanError} from '../../src/lib/strings/errors'
 
-describe('extractEntities', () => {
-  const knownHandles = new Set(['handle.com', 'full123.test-of-chars'])
-  const inputs = [
-    'no mention',
-    '@handle.com middle end',
-    'start @handle.com end',
-    'start middle @handle.com',
-    '@handle.com @handle.com @handle.com',
-    '@full123.test-of-chars',
-    'not@right',
-    '@handle.com!@#$chars',
-    '@handle.com\n@handle.com',
-    'parenthetical (@handle.com)',
-    'start https://middle.com end',
-    'start https://middle.com/foo/bar end',
-    'start https://middle.com/foo/bar?baz=bux end',
-    'start https://middle.com/foo/bar?baz=bux#hash end',
-    'https://start.com/foo/bar?baz=bux#hash middle end',
-    'start middle https://end.com/foo/bar?baz=bux#hash',
-    'https://newline1.com\nhttps://newline2.com',
-    'start middle.com end',
-    'start middle.com/foo/bar end',
-    'start middle.com/foo/bar?baz=bux end',
-    'start middle.com/foo/bar?baz=bux#hash end',
-    'start.com/foo/bar?baz=bux#hash middle end',
-    'start middle end.com/foo/bar?baz=bux#hash',
-    'newline1.com\nnewline2.com',
-    'not.. a..url ..here',
-    'e.g.',
-    'something-cool.jpg',
-    'website.com.jpg',
-    'e.g./foo',
-    'website.com.jpg/foo',
-    'Classic article https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/',
-    'Classic article https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/ ',
-    'https://foo.com https://bar.com/whatever https://baz.com',
-    'punctuation https://foo.com, https://bar.com/whatever; https://baz.com.',
-    'parenthentical (https://foo.com)',
-    'except for https://foo.com/thing_(cool)',
-  ]
-  interface Output {
-    type: string
-    value: string
-    noScheme?: boolean
-  }
-  const outputs: Output[][] = [
-    [],
-    [{type: 'mention', value: 'handle.com'}],
-    [{type: 'mention', value: 'handle.com'}],
-    [{type: 'mention', value: 'handle.com'}],
-    [
-      {type: 'mention', value: 'handle.com'},
-      {type: 'mention', value: 'handle.com'},
-      {type: 'mention', value: 'handle.com'},
-    ],
-    [
-      {
-        type: 'mention',
-        value: 'full123.test-of-chars',
-      },
-    ],
-    [],
-    [{type: 'mention', value: 'handle.com'}],
-    [
-      {type: 'mention', value: 'handle.com'},
-      {type: 'mention', value: 'handle.com'},
-    ],
-    [{type: 'mention', value: 'handle.com'}],
-    [{type: 'link', value: 'https://middle.com'}],
-    [{type: 'link', value: 'https://middle.com/foo/bar'}],
-    [{type: 'link', value: 'https://middle.com/foo/bar?baz=bux'}],
-    [{type: 'link', value: 'https://middle.com/foo/bar?baz=bux#hash'}],
-    [{type: 'link', value: 'https://start.com/foo/bar?baz=bux#hash'}],
-    [{type: 'link', value: 'https://end.com/foo/bar?baz=bux#hash'}],
-    [
-      {type: 'link', value: 'https://newline1.com'},
-      {type: 'link', value: 'https://newline2.com'},
-    ],
-    [{type: 'link', value: 'middle.com', noScheme: true}],
-    [{type: 'link', value: 'middle.com/foo/bar', noScheme: true}],
-    [{type: 'link', value: 'middle.com/foo/bar?baz=bux', noScheme: true}],
-    [{type: 'link', value: 'middle.com/foo/bar?baz=bux#hash', noScheme: true}],
-    [{type: 'link', value: 'start.com/foo/bar?baz=bux#hash', noScheme: true}],
-    [{type: 'link', value: 'end.com/foo/bar?baz=bux#hash', noScheme: true}],
-    [
-      {type: 'link', value: 'newline1.com', noScheme: true},
-      {type: 'link', value: 'newline2.com', noScheme: true},
-    ],
-    [],
-    [],
-    [],
-    [],
-    [],
-    [],
-    [
-      {
-        type: 'link',
-        value:
-          'https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/',
-      },
-    ],
-    [
-      {
-        type: 'link',
-        value:
-          'https://socket3.wordpress.com/2018/02/03/designing-windows-95s-user-interface/',
-      },
-    ],
-    [
-      {type: 'link', value: 'https://foo.com'},
-      {type: 'link', value: 'https://bar.com/whatever'},
-      {type: 'link', value: 'https://baz.com'},
-    ],
-    [
-      {type: 'link', value: 'https://foo.com'},
-      {type: 'link', value: 'https://bar.com/whatever'},
-      {type: 'link', value: 'https://baz.com'},
-    ],
-    [{type: 'link', value: 'https://foo.com'}],
-    [{type: 'link', value: 'https://foo.com/thing_(cool)'}],
-  ]
-  it('correctly handles a set of text inputs', () => {
-    for (let i = 0; i < inputs.length; i++) {
-      const input = inputs[i]
-      const result = extractEntities(input, knownHandles)
-      if (!outputs[i].length) {
-        expect(result).toBeFalsy()
-      } else if (outputs[i].length && !result) {
-        expect(result).toBeTruthy()
-      } else if (result) {
-        expect(result.length).toBe(outputs[i].length)
-        for (let j = 0; j < outputs[i].length; j++) {
-          expect(result[j].type).toEqual(outputs[i][j].type)
-          if (outputs[i][j].noScheme) {
-            expect(result[j].value).toEqual(`https://${outputs[i][j].value}`)
-          } else {
-            expect(result[j].value).toEqual(outputs[i][j].value)
-          }
-          if (outputs[i]?.[j].type === 'mention') {
-            expect(
-              input.slice(result[j].index.start, result[j].index.end),
-            ).toBe(`@${result[j].value}`)
-          } else {
-            if (!outputs[i]?.[j].noScheme) {
-              expect(
-                input.slice(result[j].index.start, result[j].index.end),
-              ).toBe(result[j].value)
-            } else {
-              expect(
-                input.slice(result[j].index.start, result[j].index.end),
-              ).toBe(result[j].value.slice('https://'.length))
-            }
-          }
-        }
-      }
-    }
-  })
-})
-
 describe('detectLinkables', () => {
   const inputs = [
     'no linkable',