From bb4cc9746c0565e56942e6adc333aae7b182d0d8 Mon Sep 17 00:00:00 2001 From: Mateusz Titz Date: Mon, 30 Dec 2024 10:44:24 +0100 Subject: [PATCH] Cleanup and fix short-mentions tests --- __tests__/ExpensiMark-HTML-test.js | 10 +++---- __tests__/ExpensiMark-test.js | 1 - lib/ExpensiMark.ts | 47 +++++++++++++++--------------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index ceb64398..b18aecca 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -697,6 +697,7 @@ test('Test url replacements', () => { '@test.com test.com ' + '@test.com @test.com '; + // Fixme [short-mention] this errors on "test.com @test.com @test.com { }, ]; - // Fixme @expensify.com is a now correct "possible" short mention + // Fixme [short-mention] @expensify.com should now be considered a short-mention "candidate" testCases.forEach((testCase) => { expect(parser.replace(testCase.testString)).toBe(testCase.resultString); }); @@ -1325,12 +1326,8 @@ test('Test for user mention with @username@domain.com', () => { const resultString = '@username@expensify.com'; expect(parser.replace(testString)).toBe(resultString); }); -// Todo -// popraw psujący się @here testy -// Todo wszystkie edge kejsy w których short mention jest ambiguous -// short-mention -> possible-short-mention -test('Test for short mention mention with @username@domain.com', () => { +test('Test for short mention mention with @username', () => { const testString = '@john.doe'; const resultString = '@john.doe'; expect(parser.replace(testString)).toBe(resultString); @@ -1519,6 +1516,7 @@ test('Test for @here mention with italic, bold and strikethrough styles', () => ' @here!' + ' @here?'; + // Fixme [short-mention] these should now be short-mention candidates const resultString = '@here' + ' @here' + diff --git a/__tests__/ExpensiMark-test.js b/__tests__/ExpensiMark-test.js index 41c0a2c9..befe1958 100644 --- a/__tests__/ExpensiMark-test.js +++ b/__tests__/ExpensiMark-test.js @@ -1,7 +1,6 @@ /* eslint-disable max-len */ import ExpensiMark from '../lib/ExpensiMark'; import * as Utils from '../lib/utils'; -import {any, string} from "prop-types"; const parser = new ExpensiMark(); diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index 3ce43635..d468f936 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -417,29 +417,6 @@ export default class ExpensiMark { }, }, - { - name: 'shortMentions', - regex: new RegExp( - "(@here|[a-zA-Z0-9.!$%&+=?^\\`{|}-]?)(@(?=((?=[\\w]+[\\w'#%+-]+(?:\\.[\\w'#%+-]+)*)[\\w\\.'#%+-]{1,64}(?= |_|\\b))(?!([:\\/\\\\]))(?.*))\\S{3,254}(?=\\k$))(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>|<\\/mention-user>|<\\/mention-here>))", - 'gim', - ), - replacement: (_extras, match, g1, g2) => { - if (!Str.isValidMention(match)) { - return match; - } - return `${g1}${g2}`; - }, - // rawInputReplacement: (_extras, match, g1, g2) => { - // const phoneNumberRegex = new RegExp(`^${Constants.CONST.REG_EXP.PHONE_PART}$`); - // const mention = g2.slice(1); - // const mentionWithoutSMSDomain = str_1.default.removeSMSDomain(mention); - // if (!str_1.default.isValidMention(match) || (phoneNumberRegex.test(mentionWithoutSMSDomain) && !str_1.default.isValidPhoneNumber(mentionWithoutSMSDomain))) { - // return match; - // } - // return `${g1}${g2}`; - // }, - }, - { name: 'quote', @@ -507,6 +484,30 @@ export default class ExpensiMark { rawInputReplacement: '$1$2', }, + { + name: 'shortMentions', + + regex: new RegExp( + "(@here|[a-zA-Z0-9.!$%&+=?^\\`{|}-]?)(@(?=((?=[\\w]+[\\w'#%+-]+(?:\\.[\\w'#%+-]+)*)[\\w\\.'#%+-]{1,64}(?= |_|\\b))(?!([:\\/\\\\]))(?.*))\\S{3,254}(?=\\k$))(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>|<\\/mention-user>|<\\/mention-here>))", + 'gim', + ), + replacement: (_extras, match, g1, g2) => { + if (!Str.isValidMention(match)) { + return match; + } + return `${g1}${g2}`; + }, + // rawInputReplacement: (_extras, match, g1, g2) => { + // const phoneNumberRegex = new RegExp(`^${Constants.CONST.REG_EXP.PHONE_PART}$`); + // const mention = g2.slice(1); + // const mentionWithoutSMSDomain = str_1.default.removeSMSDomain(mention); + // if (!str_1.default.isValidMention(match) || (phoneNumberRegex.test(mentionWithoutSMSDomain) && !str_1.default.isValidPhoneNumber(mentionWithoutSMSDomain))) { + // return match; + // } + // return `${g1}${g2}`; + // }, + }, + { // Use \B in this case because \b doesn't match * or ~. // \B will match everything that \b doesn't, so it works