diff --git a/ee/apps/account-service/Dockerfile b/ee/apps/account-service/Dockerfile index bead093d464..cbfb056bee3 100644 --- a/ee/apps/account-service/Dockerfile +++ b/ee/apps/account-service/Dockerfile @@ -28,7 +28,6 @@ COPY ./packages/media-signaling/dist packages/media-signaling/dist COPY ./packages/message-parser/package.json packages/message-parser/package.json COPY ./packages/message-parser/dist packages/message-parser/dist -COPY ./packages/message-parser/messageParser.js packages/message-parser/messageParser.js COPY ./packages/peggy-loader/package.json packages/peggy-loader/package.json COPY ./packages/peggy-loader/dist packages/peggy-loader/dist diff --git a/ee/apps/authorization-service/Dockerfile b/ee/apps/authorization-service/Dockerfile index ef525715a25..90afd4fcee6 100644 --- a/ee/apps/authorization-service/Dockerfile +++ b/ee/apps/authorization-service/Dockerfile @@ -28,7 +28,6 @@ COPY ./packages/media-signaling/dist packages/media-signaling/dist COPY ./packages/message-parser/package.json packages/message-parser/package.json COPY ./packages/message-parser/dist packages/message-parser/dist -COPY ./packages/message-parser/messageParser.js packages/message-parser/messageParser.js COPY ./packages/peggy-loader/package.json packages/peggy-loader/package.json COPY ./packages/peggy-loader/dist packages/peggy-loader/dist diff --git a/ee/apps/ddp-streamer/Dockerfile b/ee/apps/ddp-streamer/Dockerfile index 8ba1e076e7a..2aeed83e5b8 100644 --- a/ee/apps/ddp-streamer/Dockerfile +++ b/ee/apps/ddp-streamer/Dockerfile @@ -28,7 +28,6 @@ COPY ./packages/media-signaling/dist packages/media-signaling/dist COPY ./packages/message-parser/package.json packages/message-parser/package.json COPY ./packages/message-parser/dist packages/message-parser/dist -COPY ./packages/message-parser/messageParser.js packages/message-parser/messageParser.js COPY ./packages/peggy-loader/package.json packages/peggy-loader/package.json COPY ./packages/peggy-loader/dist packages/peggy-loader/dist diff --git a/ee/apps/omnichannel-transcript/Dockerfile b/ee/apps/omnichannel-transcript/Dockerfile index 545809c3337..24ff7514f57 100644 --- a/ee/apps/omnichannel-transcript/Dockerfile +++ b/ee/apps/omnichannel-transcript/Dockerfile @@ -28,7 +28,6 @@ COPY ./packages/media-signaling/dist packages/media-signaling/dist COPY ./packages/message-parser/package.json packages/message-parser/package.json COPY ./packages/message-parser/dist packages/message-parser/dist -COPY ./packages/message-parser/messageParser.js packages/message-parser/messageParser.js COPY ./packages/peggy-loader/package.json packages/peggy-loader/package.json COPY ./packages/peggy-loader/dist packages/peggy-loader/dist diff --git a/ee/apps/presence-service/Dockerfile b/ee/apps/presence-service/Dockerfile index cc058f195b7..0fbd83415af 100644 --- a/ee/apps/presence-service/Dockerfile +++ b/ee/apps/presence-service/Dockerfile @@ -31,7 +31,6 @@ COPY ./packages/media-signaling/dist packages/media-signaling/dist COPY ./packages/message-parser/package.json packages/message-parser/package.json COPY ./packages/message-parser/dist packages/message-parser/dist -COPY ./packages/message-parser/messageParser.js packages/message-parser/messageParser.js COPY ./packages/peggy-loader/package.json packages/peggy-loader/package.json COPY ./packages/peggy-loader/dist packages/peggy-loader/dist diff --git a/ee/apps/queue-worker/Dockerfile b/ee/apps/queue-worker/Dockerfile index 545809c3337..24ff7514f57 100644 --- a/ee/apps/queue-worker/Dockerfile +++ b/ee/apps/queue-worker/Dockerfile @@ -28,7 +28,6 @@ COPY ./packages/media-signaling/dist packages/media-signaling/dist COPY ./packages/message-parser/package.json packages/message-parser/package.json COPY ./packages/message-parser/dist packages/message-parser/dist -COPY ./packages/message-parser/messageParser.js packages/message-parser/messageParser.js COPY ./packages/peggy-loader/package.json packages/peggy-loader/package.json COPY ./packages/peggy-loader/dist packages/peggy-loader/dist diff --git a/ee/apps/stream-hub-service/Dockerfile b/ee/apps/stream-hub-service/Dockerfile index 5043c33c44e..41c345bc53f 100644 --- a/ee/apps/stream-hub-service/Dockerfile +++ b/ee/apps/stream-hub-service/Dockerfile @@ -28,7 +28,6 @@ COPY ./packages/media-signaling/dist packages/media-signaling/dist COPY ./packages/message-parser/package.json packages/message-parser/package.json COPY ./packages/message-parser/dist packages/message-parser/dist -COPY ./packages/message-parser/messageParser.js packages/message-parser/messageParser.js COPY ./packages/peggy-loader/package.json packages/peggy-loader/package.json COPY ./packages/peggy-loader/dist packages/peggy-loader/dist diff --git a/packages/message-parser/.prettierrc.js b/packages/message-parser/.prettierrc.js deleted file mode 100644 index b57f474edb9..00000000000 --- a/packages/message-parser/.prettierrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('@rocket.chat/prettier-config/fuselage'); diff --git a/packages/message-parser/babel.config.js b/packages/message-parser/babel.config.js deleted file mode 100644 index 8456c191273..00000000000 --- a/packages/message-parser/babel.config.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - presets: [ - [ - '@babel/preset-env', - { - targets: { - browsers: [ - 'Chrome >= 59', - 'FireFox >= 44', - 'Safari >= 7', - 'Explorer 11', - 'last 4 Edge versions', - ], - }, - }, - ], - ], -}; diff --git a/packages/message-parser/jest.config.ts b/packages/message-parser/jest.config.ts index e11f29938eb..4bbab0385d9 100644 --- a/packages/message-parser/jest.config.ts +++ b/packages/message-parser/jest.config.ts @@ -4,9 +4,9 @@ import server from '@rocket.chat/jest-presets/server'; import type { Config } from 'jest'; export default { - preset: server.preset, - transform: { - '\\.pegjs$': resolve(__dirname, './loaders/pegtransform.js'), - }, - moduleFileExtensions: ['js', 'ts', 'pegjs'], + preset: server.preset, + transform: { + '\\.pegjs$': resolve(__dirname, './loaders/pegtransform.js'), + }, + moduleFileExtensions: ['js', 'ts', 'pegjs'], } satisfies Config; diff --git a/packages/message-parser/loaders/pegtransform.js b/packages/message-parser/loaders/pegtransform.js index 9df49c61dfe..52aca042a84 100644 --- a/packages/message-parser/loaders/pegtransform.js +++ b/packages/message-parser/loaders/pegtransform.js @@ -1,10 +1,10 @@ const pegjs = require('peggy'); module.exports = { - process: (content) => ({ - code: pegjs.generate(content, { - output: 'source', - format: 'commonjs', - }), - }), + process: (content) => ({ + code: pegjs.generate(content, { + output: 'source', + format: 'commonjs', + }), + }), }; diff --git a/packages/message-parser/messageParser.js b/packages/message-parser/messageParser.js deleted file mode 100644 index c1dc1bda949..00000000000 --- a/packages/message-parser/messageParser.js +++ /dev/null @@ -1,7 +0,0 @@ -/* eslint-disable import/no-unresolved */ - -if (process.env.NODE_ENV === 'production') { - module.exports = require('./dist/messageParser.production.js'); -} else { - module.exports = require('./dist/messageParser.development.js'); -} diff --git a/packages/message-parser/package.json b/packages/message-parser/package.json index d28488727c8..7a943d47f71 100644 --- a/packages/message-parser/package.json +++ b/packages/message-parser/package.json @@ -18,56 +18,46 @@ }, "exports": { ".": { - "default": "./messageParser.js" - }, - "./index": { - "default": "./messageParser.js" + "default": "./dist/messageParser.js", + "types": "./dist/index.d.ts" } }, - "main": "messageParser.js", - "unpkg": "dist/messageParser.umd.js", - "module": "dist/messageParser.mjs", + "main": "dist/messageParser.js", + "module": "dist/messageParser.js", "types": "dist/index.d.ts", "directories": { "test": "test" }, "files": [ - "/dist", - "/messageParser.js" + "/dist" ], "scripts": { ".:build:bundle": "webpack-cli", ".:build:clean": "rimraf dist", "build": "run-s .:build:clean .:build:bundle", - "docs": "typedoc", "lint": "eslint .", "test": "jest", - "testunit": "jest" + "testunit": "jest", + "typecheck": "tsc --noEmit" }, "dependencies": { "tldts": "~6.1.86" }, "devDependencies": { - "@babel/core": "~7.28.5", - "@babel/eslint-parser": "~7.28.5", - "@babel/preset-env": "~7.28.5", "@rocket.chat/eslint-config": "workspace:^", "@rocket.chat/jest-presets": "workspace:~", "@rocket.chat/peggy-loader": "workspace:~", "@rocket.chat/prettier-config": "~0.31.25", "@types/jest": "~30.0.0", "@types/node": "~22.16.5", - "@typescript-eslint/parser": "~5.58.0", - "babel-loader": "~10.0.0", + "@typescript-eslint/parser": "~5.60.1", "eslint": "~8.45.0", "jest": "~30.2.0", "npm-run-all": "^4.1.5", "peggy": "4.1.1", - "prettier": "~3.3.3", "prettier-plugin-pegjs": "~0.5.4", "rimraf": "^6.0.1", "ts-loader": "~9.5.4", - "typedoc": "~0.28.14", "typescript": "~5.9.3", "webpack": "~5.99.9", "webpack-cli": "~5.1.4" diff --git a/packages/message-parser/src/definitions.ts b/packages/message-parser/src/definitions.ts index 97f18285872..f463346a974 100644 --- a/packages/message-parser/src/definitions.ts +++ b/packages/message-parser/src/definitions.ts @@ -1,260 +1,228 @@ export type Blockquote = { - type: 'BLOCKQUOTE'; - value: Paragraph[]; + type: 'BLOCKQUOTE'; + value: Paragraph[]; }; export type OrderedList = { - type: 'ORDERED_LIST'; - value: ListItem[]; + type: 'ORDERED_LIST'; + value: ListItem[]; }; export type UnorderedList = { - type: 'UNORDERED_LIST'; - value: ListItem[]; + type: 'UNORDERED_LIST'; + value: ListItem[]; }; export type ListItem = { - type: 'LIST_ITEM'; - value: Inlines[]; - number?: number; + type: 'LIST_ITEM'; + value: Inlines[]; + number?: number; }; export type Tasks = { - type: 'TASKS'; - value: Task[]; + type: 'TASKS'; + value: Task[]; }; export type Task = { - type: 'TASK'; - status: boolean; - value: Inlines[]; + type: 'TASK'; + status: boolean; + value: Inlines[]; }; export type CodeLine = { - type: 'CODE_LINE'; - value: Plain; + type: 'CODE_LINE'; + value: Plain; }; export type Color = { - type: 'COLOR'; - value: { - r: number; - g: number; - b: number; - a: number; - }; + type: 'COLOR'; + value: { + r: number; + g: number; + b: number; + a: number; + }; }; export type BigEmoji = { - type: 'BIG_EMOJI'; - value: [Emoji] | [Emoji, Emoji] | [Emoji, Emoji, Emoji]; + type: 'BIG_EMOJI'; + value: [Emoji] | [Emoji, Emoji] | [Emoji, Emoji, Emoji]; }; export type Emoji = - | { - type: 'EMOJI'; - value: Plain; - shortCode: string; - } - | { - type: 'EMOJI'; - value: undefined; - unicode: string; - }; + | { + type: 'EMOJI'; + value: Plain; + shortCode: string; + } + | { + type: 'EMOJI'; + value: undefined; + unicode: string; + }; export type Code = { - type: 'CODE'; - language: string | undefined; - value: CodeLine[]; + type: 'CODE'; + language: string | undefined; + value: CodeLine[]; }; export type InlineCode = { - type: 'INLINE_CODE'; - value: Plain; + type: 'INLINE_CODE'; + value: Plain; }; export type Heading = { - type: 'HEADING'; - level: 1 | 2 | 3 | 4; - value: Plain[]; + type: 'HEADING'; + level: 1 | 2 | 3 | 4; + value: Plain[]; }; export type Quote = { - type: 'QUOTE'; - value: Paragraph[]; + type: 'QUOTE'; + value: Paragraph[]; }; export type Markup = Italic | Strike | Bold | Plain | ChannelMention; export type MarkupExcluding = Exclude; export type Bold = { - type: 'BOLD'; - value: Array< - | MarkupExcluding - | Link - | Emoji - | UserMention - | ChannelMention - | InlineCode - >; + type: 'BOLD'; + value: Array | Link | Emoji | UserMention | ChannelMention | InlineCode>; }; export type Italic = { - type: 'ITALIC'; - value: Array< - | MarkupExcluding - | Link - | Emoji - | UserMention - | ChannelMention - | InlineCode - >; + type: 'ITALIC'; + value: Array | Link | Emoji | UserMention | ChannelMention | InlineCode>; }; export type Strike = { - type: 'STRIKE'; - value: Array< - | MarkupExcluding - | Link - | Emoji - | UserMention - | ChannelMention - | InlineCode - | Italic - | Timestamp - >; + type: 'STRIKE'; + value: Array | Link | Emoji | UserMention | ChannelMention | InlineCode | Italic | Timestamp>; }; export type Plain = { - type: 'PLAIN_TEXT'; - value: string; + type: 'PLAIN_TEXT'; + value: string; }; export type LineBreak = { - type: 'LINE_BREAK'; - value: undefined; + type: 'LINE_BREAK'; + value: undefined; }; export type KaTeX = { - type: 'KATEX'; - value: string; + type: 'KATEX'; + value: string; }; export type InlineKaTeX = { - type: 'INLINE_KATEX'; - value: string; + type: 'INLINE_KATEX'; + value: string; }; export type Paragraph = { - type: 'PARAGRAPH'; - value: Array>; + type: 'PARAGRAPH'; + value: Array>; }; export type Image = { - type: 'IMAGE'; - value: { - src: Plain; - label: Markup; - }; + type: 'IMAGE'; + value: { + src: Plain; + label: Markup; + }; }; export type Link = { - type: 'LINK'; - value: { - src: Plain; - label: Markup | Markup[]; - }; + type: 'LINK'; + value: { + src: Plain; + label: Markup | Markup[]; + }; }; export type UserMention = { - type: 'MENTION_USER'; - value: Plain; + type: 'MENTION_USER'; + value: Plain; }; export type ChannelMention = { - type: 'MENTION_CHANNEL'; - value: Plain; + type: 'MENTION_CHANNEL'; + value: Plain; }; export type Timestamp = { - type: 'TIMESTAMP'; - value: { - timestamp: string; - format: 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R'; - }; - fallback?: Plain; + type: 'TIMESTAMP'; + value: { + timestamp: string; + format: 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R'; + }; + fallback?: Plain; }; export type Types = { - BOLD: Bold; - PARAGRAPH: Paragraph; - PLAIN_TEXT: Plain; - ITALIC: Italic; - STRIKE: Strike; - CODE: Code; - CODE_LINE: CodeLine; - INLINE_CODE: InlineCode; - HEADING: Heading; - QUOTE: Quote; - LINK: Link; - MENTION_USER: UserMention; - MENTION_CHANNEL: ChannelMention; - EMOJI: Emoji; - BIG_EMOJI: BigEmoji; - COLOR: Color; - TASKS: Tasks; - TASK: Task; - UNORDERED_LIST: UnorderedList; - ORDERED_LIST: OrderedList; - LIST_ITEM: ListItem; - IMAGE: Image; - LINE_BREAK: LineBreak; + BOLD: Bold; + PARAGRAPH: Paragraph; + PLAIN_TEXT: Plain; + ITALIC: Italic; + STRIKE: Strike; + CODE: Code; + CODE_LINE: CodeLine; + INLINE_CODE: InlineCode; + HEADING: Heading; + QUOTE: Quote; + LINK: Link; + MENTION_USER: UserMention; + MENTION_CHANNEL: ChannelMention; + EMOJI: Emoji; + BIG_EMOJI: BigEmoji; + COLOR: Color; + TASKS: Tasks; + TASK: Task; + UNORDERED_LIST: UnorderedList; + ORDERED_LIST: OrderedList; + LIST_ITEM: ListItem; + IMAGE: Image; + LINE_BREAK: LineBreak; }; export type ASTNode = - | BigEmoji - | Bold - | Paragraph - | Plain - | Italic - | Strike - | Code - | CodeLine - | InlineCode - | Heading - | Quote - | Link - | UserMention - | ChannelMention - | Emoji - | Color - | Tasks; + | BigEmoji + | Bold + | Paragraph + | Plain + | Italic + | Strike + | Code + | CodeLine + | InlineCode + | Heading + | Quote + | Link + | UserMention + | ChannelMention + | Emoji + | Color + | Tasks; export type TypesKeys = keyof Types; export type Inlines = - | Timestamp - | Bold - | Plain - | Italic - | Strike - | InlineCode - | Image - | Link - | UserMention - | ChannelMention - | Emoji - | Color - | InlineKaTeX; + | Timestamp + | Bold + | Plain + | Italic + | Strike + | InlineCode + | Image + | Link + | UserMention + | ChannelMention + | Emoji + | Color + | InlineKaTeX; -export type Blocks = - | Code - | Heading - | Quote - | ListItem - | Tasks - | OrderedList - | UnorderedList - | LineBreak - | KaTeX; +export type Blocks = Code | Heading | Quote | ListItem | Tasks | OrderedList | UnorderedList | LineBreak | KaTeX; export type Root = Array | [BigEmoji]; diff --git a/packages/message-parser/src/guards.ts b/packages/message-parser/src/guards.ts index c8d35071b9c..8dcabca2f85 100644 --- a/packages/message-parser/src/guards.ts +++ b/packages/message-parser/src/guards.ts @@ -1,10 +1,4 @@ import type { ASTNode } from './definitions'; -export const isNodeOfType = ( - value: unknown, - type: N['type'], -): value is N => - typeof value === 'object' && - value !== null && - 'type' in value && - (value as { type: unknown }).type === type; +export const isNodeOfType = (value: unknown, type: N['type']): value is N => + typeof value === 'object' && value !== null && 'type' in value && (value as { type: unknown }).type === type; diff --git a/packages/message-parser/src/index.ts b/packages/message-parser/src/index.ts index cbdae1382cb..805db0e8a5d 100644 --- a/packages/message-parser/src/index.ts +++ b/packages/message-parser/src/index.ts @@ -6,21 +6,20 @@ export * from './definitions'; export { isNodeOfType } from './guards'; export type Options = { - colors?: boolean; - emoticons?: boolean; - katex?: { - dollarSyntax?: boolean; - parenthesisSyntax?: boolean; - }; - customDomains?: string[]; + colors?: boolean; + emoticons?: boolean; + katex?: { + dollarSyntax?: boolean; + parenthesisSyntax?: boolean; + }; + customDomains?: string[]; }; -export const parse = (input: string, options?: Options): Root => - grammar.parse(input, options); +export const parse = (input: string, options?: Options): Root => grammar.parse(input, options); export { - /** @deprecated */ - parse as parser, - /** @deprecated */ - Root as MarkdownAST, + /** @deprecated */ + parse as parser, + /** @deprecated */ + Root as MarkdownAST, }; diff --git a/packages/message-parser/src/typings/peg.d.ts b/packages/message-parser/src/typings/peg.d.ts index 9485bc0f0f8..cce48d87f16 100644 --- a/packages/message-parser/src/typings/peg.d.ts +++ b/packages/message-parser/src/typings/peg.d.ts @@ -1,7 +1,7 @@ declare module '*.pegjs' { - import type { ParserOptions } from 'peggy'; + import type { ParserOptions } from 'peggy'; - import type { ASTMessage } from '../definitions'; + import type { ASTMessage } from '../definitions'; - export const parse: (input: string, options?: ParserOptions) => ASTMessage; + export const parse: (input: string, options?: ParserOptions) => ASTMessage; } diff --git a/packages/message-parser/src/utils.ts b/packages/message-parser/src/utils.ts index 75ab4e9d6cc..bd38d1aa9f6 100644 --- a/packages/message-parser/src/utils.ts +++ b/packages/message-parser/src/utils.ts @@ -1,65 +1,59 @@ import { parse as tldParse } from 'tldts'; import type { - BigEmoji, - Code, - Color, - Heading, - Markup, - Paragraph, - Types, - Task, - ListItem, - Inlines, - LineBreak, - Emoji, - KaTeX, - InlineKaTeX, - Link, - Timestamp, + BigEmoji, + Code, + Color, + Heading, + Markup, + Paragraph, + Types, + Task, + ListItem, + Inlines, + LineBreak, + Emoji, + KaTeX, + InlineKaTeX, + Link, + Timestamp, } from './definitions'; const generate = - (type: Type) => - (value: Types[Type]['value']): Types[Type] => - ({ type, value }) as any; + (type: Type) => + (value: Types[Type]['value']): Types[Type] => + ({ type, value }) as any; export const paragraph = generate('PARAGRAPH'); export const bold = generate('BOLD'); export const color = (r: number, g: number, b: number, a = 255): Color => ({ - type: 'COLOR', - value: { r, g, b, a }, + type: 'COLOR', + value: { r, g, b, a }, }); -export const heading = ( - value: Heading['value'], - level: Heading['level'] = 1, -): Heading => ({ - type: 'HEADING', - level, - value, +export const heading = (value: Heading['value'], level: Heading['level'] = 1): Heading => ({ + type: 'HEADING', + level, + value, }); -export const code = ( - value: Code['value'], - language?: Code['language'], -): Code => ({ - type: 'CODE', - language: language || 'none', - value, +export const code = (value: Code['value'], language?: Code['language']): Code => ({ + type: 'CODE', + language: language || 'none', + value, }); export const bigEmoji = (value: BigEmoji['value']): BigEmoji => ({ - type: 'BIG_EMOJI', - value, + type: 'BIG_EMOJI', + value, }); export const task = (value: Task['value'], status: boolean): Task => ({ - type: 'TASK', - status, - value, + type: 'TASK', + status, + value, }); export const inlineCode = generate('INLINE_CODE'); @@ -73,63 +67,60 @@ export const strike = generate('STRIKE'); export const codeLine = generate('CODE_LINE'); const isValidLink = (link: string) => { - try { - return Boolean(new URL(link)); - } catch (error) { - return false; - } + try { + return Boolean(new URL(link)); + } catch (error) { + return false; + } }; export const link = (src: string, label?: Markup[]): Link => ({ - type: 'LINK', - value: { src: plain(src), label: label ?? [plain(src)] }, + type: 'LINK', + value: { src: plain(src), label: label ?? [plain(src)] }, }); export const autoLink = (src: string, customDomains?: string[]) => { - const validHosts = ['localhost', ...(customDomains ?? [])]; - const { isIcann, isIp, isPrivate, domain } = tldParse(src, { - detectIp: false, - allowPrivateDomains: true, - validHosts, - }); + const validHosts = ['localhost', ...(customDomains ?? [])]; + const { isIcann, isIp, isPrivate, domain } = tldParse(src, { + detectIp: false, + allowPrivateDomains: true, + validHosts, + }); - if ( - !(isIcann || isIp || isPrivate || (domain && validHosts.includes(domain))) - ) { - return plain(src); - } + if (!(isIcann || isIp || isPrivate || (domain && validHosts.includes(domain)))) { + return plain(src); + } - const href = isValidLink(src) || src.startsWith('//') ? src : `//${src}`; + const href = isValidLink(src) || src.startsWith('//') ? src : `//${src}`; - return link(href, [plain(src)]); + return link(href, [plain(src)]); }; export const autoEmail = (src: string) => { - const href = `mailto:${src}`; + const href = `mailto:${src}`; - const { isIcann, isIp, isPrivate } = tldParse(href, { - detectIp: false, - allowPrivateDomains: true, - }); + const { isIcann, isIp, isPrivate } = tldParse(href, { + detectIp: false, + allowPrivateDomains: true, + }); - if (!(isIcann || isIp || isPrivate)) { - return plain(src); - } + if (!(isIcann || isIp || isPrivate)) { + return plain(src); + } - return link(href, [plain(src)]); + return link(href, [plain(src)]); }; export const image = (() => { - const fn = generate('IMAGE'); - return (src: string, label?: Markup) => - fn({ src: plain(src), label: label || plain(src) }); + const fn = generate('IMAGE'); + return (src: string, label?: Markup) => fn({ src: plain(src), label: label || plain(src) }); })(); export const quote = generate('QUOTE'); export const mentionChannel = (() => { - const fn = generate('MENTION_CHANNEL'); - return (value: string) => fn(plain(value)); + const fn = generate('MENTION_CHANNEL'); + return (value: string) => fn(plain(value)); })(); export const orderedList = generate('ORDERED_LIST'); @@ -137,174 +128,149 @@ export const orderedList = generate('ORDERED_LIST'); export const unorderedList = generate('UNORDERED_LIST'); export const listItem = (text: Inlines[], number?: number): ListItem => ({ - type: 'LIST_ITEM', - value: text, - ...(number && { number }), + type: 'LIST_ITEM', + value: text, + ...(number && { number }), }); export const mentionUser = (() => { - const fn = generate('MENTION_USER'); - return (value: string) => fn(plain(value)); + const fn = generate('MENTION_USER'); + return (value: string) => fn(plain(value)); })(); export const emoji = (shortCode: string): Emoji => ({ - type: 'EMOJI', - value: plain(shortCode), - shortCode, + type: 'EMOJI', + value: plain(shortCode), + shortCode, }); export const emojiUnicode = (unicode: string): Emoji => ({ - type: 'EMOJI', - value: undefined, - unicode, + type: 'EMOJI', + value: undefined, + unicode, }); export const emoticon = (emoticon: string, shortCode: string): Emoji => ({ - type: 'EMOJI', - value: plain(emoticon), - shortCode, + type: 'EMOJI', + value: plain(emoticon), + shortCode, }); -const joinEmoji = ( - current: Inlines, - previous: Inlines | undefined, - next: Inlines | undefined, -): Inlines => { - if (current.type !== 'EMOJI' || !current.value || (!previous && !next)) { - return current; - } +const joinEmoji = (current: Inlines, previous: Inlines | undefined, next: Inlines | undefined): Inlines => { + if (current.type !== 'EMOJI' || !current.value || (!previous && !next)) { + return current; + } - const hasEmojiAsNeighbor = - previous?.type === current.type || current.type === next?.type; - const hasPlainAsNeighbor = - (previous?.type === 'PLAIN_TEXT' && previous.value.trim() !== '') || - (next?.type === 'PLAIN_TEXT' && next.value.trim() !== ''); - const isEmoticon = current.shortCode !== current.value.value; + const hasEmojiAsNeighbor = previous?.type === current.type || current.type === next?.type; + const hasPlainAsNeighbor = + (previous?.type === 'PLAIN_TEXT' && previous.value.trim() !== '') || (next?.type === 'PLAIN_TEXT' && next.value.trim() !== ''); + const isEmoticon = current.shortCode !== current.value.value; - if (current.value && (hasEmojiAsNeighbor || hasPlainAsNeighbor)) { - if (isEmoticon) { - return current.value; - } + if (current.value && (hasEmojiAsNeighbor || hasPlainAsNeighbor)) { + if (isEmoticon) { + return current.value; + } - return { - ...current.value, - value: `:${current.value.value}:`, - }; - } + return { + ...current.value, + value: `:${current.value.value}:`, + }; + } - return current; + return current; }; -export const reducePlainTexts = ( - values: Paragraph['value'], -): Paragraph['value'] => - values.flat().reduce( - (result, item, index, values) => { - const next = values[index + 1]; - const current = joinEmoji(item, values[index - 1], next); - const previous: Inlines = result[result.length - 1]; +export const reducePlainTexts = (values: Paragraph['value']): Paragraph['value'] => + values.flat().reduce( + (result, item, index, values) => { + const next = values[index + 1]; + const current = joinEmoji(item, values[index - 1], next); + const previous: Inlines = result[result.length - 1]; - if (previous) { - if (current.type === 'PLAIN_TEXT' && current.type === previous.type) { - previous.value += current.value; - return result; - } - } - return [...result, current]; - }, - [] as Paragraph['value'], - ); + if (previous) { + if (current.type === 'PLAIN_TEXT' && current.type === previous.type) { + previous.value += current.value; + return result; + } + } + return [...result, current]; + }, + [] as Paragraph['value'], + ); export const lineBreak = (): LineBreak => ({ - type: 'LINE_BREAK', - value: undefined, + type: 'LINE_BREAK', + value: undefined, }); export const katex = (content: string): KaTeX => ({ - type: 'KATEX', - value: content, + type: 'KATEX', + value: content, }); export const inlineKatex = (content: string): InlineKaTeX => ({ - type: 'INLINE_KATEX', - value: content, + type: 'INLINE_KATEX', + value: content, }); export const phoneChecker = (text: string, number: string) => { - if (number.length < 5) { - return plain(text); - } + if (number.length < 5) { + return plain(text); + } - return link(`tel:${number}`, [plain(text)]); + return link(`tel:${number}`, [plain(text)]); }; -export const timestamp = ( - value: string, - type?: 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R', -): Timestamp => { - return { - type: 'TIMESTAMP', - value: { - timestamp: value, - format: type || 't', - }, - fallback: plain(``), - }; +export const timestamp = (value: string, type?: 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R'): Timestamp => { + return { + type: 'TIMESTAMP', + value: { + timestamp: value, + format: type || 't', + }, + fallback: plain(``), + }; }; -export const timestampFromHours = ( - hours: string, - minutes = '00', - seconds = '00', - timezone = '', -) => { - const date = new Date(); +export const timestampFromHours = (hours: string, minutes = '00', seconds = '00', timezone = '') => { + const date = new Date(); - const yearMonthDay = date.toISOString().split('T')[0]; + const yearMonthDay = date.toISOString().split('T')[0]; - const timestamp = - (new Date( - `${yearMonthDay}T${hours}:${minutes}:${seconds}${timezone}`, - ).getTime() / - 1000) | - 0; + const timestamp = (new Date(`${yearMonthDay}T${hours}:${minutes}:${seconds}${timezone}`).getTime() / 1000) | 0; - return timestamp.toString(); + return timestamp.toString(); }; export const timestampFromIsoTime = ({ - year, - month, - day, - hours, - minutes, - seconds, - milliseconds, - timezone, + year, + month, + day, + hours, + minutes, + seconds, + milliseconds, + timezone, }: { - year: string[]; - month: string[]; - day: string[]; - hours: string[]; - minutes: string[]; - seconds: string[]; - milliseconds?: string[]; - timezone?: string; + year: string[]; + month: string[]; + day: string[]; + hours: string[]; + minutes: string[]; + seconds: string[]; + milliseconds?: string[]; + timezone?: string; }) => { - const date = - (new Date( - `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds || '000'}${timezone ? `${timezone}` : ''}`, - ).getTime() / - 1000) | - 0; - return date.toString(); + const date = + (new Date(`${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds || '000'}${timezone ? `${timezone}` : ''}`).getTime() / + 1000) | + 0; + return date.toString(); }; -export const extractFirstResult = ( - value: Types[keyof Types]['value'], -): Types[keyof Types]['value'] => { - if (typeof value !== 'object' || !Array.isArray(value)) { - return value; - } +export const extractFirstResult = (value: Types[keyof Types]['value']): Types[keyof Types]['value'] => { + if (typeof value !== 'object' || !Array.isArray(value)) { + return value; + } - return value.filter((item) => item).shift() as Types[keyof Types]['value']; + return value.filter((item) => item).shift() as Types[keyof Types]['value']; }; diff --git a/packages/message-parser/tests/abuse.test.ts b/packages/message-parser/tests/abuse.test.ts index 8630deb9179..525efe37fc7 100644 --- a/packages/message-parser/tests/abuse.test.ts +++ b/packages/message-parser/tests/abuse.test.ts @@ -2,267 +2,257 @@ import { parse } from '../src'; import { paragraph, plain, bold, italic, strike } from '../src/utils'; test.each([ - [ - `This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. , REPEATx2 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. REPEAT x3 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. REPEAT x4 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. REPEATx 5 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. , REPEAT x6 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. this can go long for some time, repeat x7 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. ,repeat x8 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some.`, - [ - paragraph([ - plain( - 'This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&', - ), - bold([ - plain('()'), - italic([ - plain( - `+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`, - ), - strike([ - plain( - `, from now on we repeat some. , REPEATx2 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`, - ), - ]), - plain( - ', from now on we repeat some. REPEAT x3 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()', - ), - ]), - plain( - `+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`, - ), - strike([ - plain( - ', from now on we repeat some. REPEAT x4 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()', - ), - italic([ - plain( - `+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. REPEATx 5 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()`, - ), - ]), - plain( - `+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`, - ), - ]), - plain( - `, from now on we repeat some. , REPEAT x6 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&`, - ), - ]), - plain( - `()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`, - ), - strike([ - plain( - `, from now on we repeat some. this can go long for some time, repeat x7 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()`, - ), - italic([ - plain( - `+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. ,repeat x8 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()`, - ), - ]), - plain( - `+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`, - ), - ]), - plain(', from now on we repeat some.'), - ]), - ], - ], - [ - '**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__', - [ - paragraph([ - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - italic([bold([plain('_')])]), - bold([italic([plain('**')]), italic([plain('**')])]), - plain('__'), - ]), - ], - ], + [ + `This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. , REPEATx2 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. REPEAT x3 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. REPEAT x4 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. REPEATx 5 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. , REPEAT x6 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. this can go long for some time, repeat x7 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. ,repeat x8 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some.`, + [ + paragraph([ + plain( + 'This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&', + ), + bold([ + plain('()'), + italic([ + plain(`+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`), + strike([ + plain( + `, from now on we repeat some. , REPEATx2 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`, + ), + ]), + plain( + ', from now on we repeat some. REPEAT x3 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()', + ), + ]), + plain(`+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`), + strike([ + plain( + ', from now on we repeat some. REPEAT x4 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()', + ), + italic([ + plain( + `+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. REPEATx 5 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()`, + ), + ]), + plain(`+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`), + ]), + plain( + `, from now on we repeat some. , REPEAT x6 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&`, + ), + ]), + plain(`()_+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`), + strike([ + plain( + `, from now on we repeat some. this can go long for some time, repeat x7 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()`, + ), + italic([ + plain( + `+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok~, from now on we repeat some. ,repeat x8 This a message designed to stress test the message parser, trying to force several rules to stack at the same time !!@#$%^&*()`, + ), + ]), + plain(`+, overloading the symbols {}:"|<>?, some more text ,./;'\\[], numbers too 1234567890-= let it call s o s ok`), + ]), + plain(', from now on we repeat some.'), + ]), + ], + ], + [ + '**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__**_**__', + [ + paragraph([ + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + italic([bold([plain('_')])]), + bold([italic([plain('**')]), italic([plain('**')])]), + plain('__'), + ]), + ], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/any.test.ts b/packages/message-parser/tests/any.test.ts index 63e9a72c91b..7dca7bbdde5 100644 --- a/packages/message-parser/tests/any.test.ts +++ b/packages/message-parser/tests/any.test.ts @@ -2,12 +2,9 @@ import { parse } from '../src'; import { paragraph, plain } from '../src/utils'; test.each([ - ['free text', [paragraph([plain('free text')])]], - ['free text, with comma', [paragraph([plain('free text, with comma')])]], - [ - 'free text with unxpected/unfinished blocks *bold_', - [paragraph([plain('free text with unxpected/unfinished blocks *bold_')])], - ], + ['free text', [paragraph([plain('free text')])]], + ['free text, with comma', [paragraph([plain('free text, with comma')])]], + ['free text with unxpected/unfinished blocks *bold_', [paragraph([plain('free text with unxpected/unfinished blocks *bold_')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/blockquotes.test.ts b/packages/message-parser/tests/blockquotes.test.ts index 835074ec7fa..b42368daacc 100644 --- a/packages/message-parser/tests/blockquotes.test.ts +++ b/packages/message-parser/tests/blockquotes.test.ts @@ -2,39 +2,30 @@ import { parse } from '../src'; import { paragraph, plain, quote, bold } from '../src/utils'; test.each([ - [ - ` + [ + ` As Rocket Cat said: > meowww > grr. `.trim(), - [ - paragraph([plain('As Rocket Cat said:')]), - quote([paragraph([plain('meowww')]), paragraph([plain('grr.')])]), - ], - ], - [ - ` + [paragraph([plain('As Rocket Cat said:')]), quote([paragraph([plain('meowww')]), paragraph([plain('grr.')])])], + ], + [ + ` As Rocket Cat said: > *meowww* > grr. `.trim(), - [ - paragraph([plain('As Rocket Cat said:')]), - quote([paragraph([bold([plain('meowww')])]), paragraph([plain('grr.')])]), - ], - ], - [ - ` + [paragraph([plain('As Rocket Cat said:')]), quote([paragraph([bold([plain('meowww')])]), paragraph([plain('grr.')])])], + ], + [ + ` As Rocket Cat said: >meowww >grr. `.trim(), - [ - paragraph([plain('As Rocket Cat said:')]), - quote([paragraph([plain('meowww')]), paragraph([plain('grr.')])]), - ], - ], + [paragraph([plain('As Rocket Cat said:')]), quote([paragraph([plain('meowww')]), paragraph([plain('grr.')])])], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/codeFence.test.ts b/packages/message-parser/tests/codeFence.test.ts index 3c13ca3b8e6..c84f515983a 100644 --- a/packages/message-parser/tests/codeFence.test.ts +++ b/packages/message-parser/tests/codeFence.test.ts @@ -1,12 +1,11 @@ import { parse } from '../src'; import { paragraph, plain, codeLine, code } from '../src/utils'; -const multiply = (a: number, element: T): Array => - Array.from({ length: a }, () => element); +const multiply = (a: number, element: T): Array => Array.from({ length: a }, () => element); test.each([ - [ - `\`\`\` + [ + `\`\`\` code @@ -14,70 +13,60 @@ code code \`\`\``, - [ - code([ - codeLine(plain('code')), - ...multiply(4, codeLine(plain(''))), - codeLine(plain('code')), - ]), - ], - ], - [ - `\`\`\` + [code([codeLine(plain('code')), ...multiply(4, codeLine(plain(''))), codeLine(plain('code'))])], + ], + [ + `\`\`\` code \`\`\``, - [code([codeLine(plain('code')), ...multiply(2, codeLine(plain('')))])], - ], - [ - `\`\`\` + [code([codeLine(plain('code')), ...multiply(2, codeLine(plain('')))])], + ], + [ + `\`\`\` code \`\`\``, - [code([codeLine(plain('code'))])], - ], - [ - `\`\`\` + [code([codeLine(plain('code'))])], + ], + [ + `\`\`\` var a = "teste"; \`\`\``, - [code([codeLine(plain('var a = "teste";'))])], - ], - [ - `\`\`\`javascript + [code([codeLine(plain('var a = "teste";'))])], + ], + [ + `\`\`\`javascript code \`\`\``, - [code([codeLine(plain('code'))], 'javascript')], - ], - [ - `\`\`\`bash c + [code([codeLine(plain('code'))], 'javascript')], + ], + [ + `\`\`\`bash c code \`\`\``, - [code([codeLine(plain('code'))], 'bash c')], - ], - [ - ` \`\`\` + [code([codeLine(plain('code'))], 'bash c')], + ], + [ + ` \`\`\` code \`\`\``, - [ - paragraph([plain(` \`\`\``)]), - paragraph([plain(`code`)]), - paragraph([plain(`\`\`\``)]), - ], - ], - [ - `\`\`\` + [paragraph([plain(` \`\`\``)]), paragraph([plain(`code`)]), paragraph([plain(`\`\`\``)])], + ], + [ + `\`\`\` code code \`\`\``, - [code([codeLine(plain(`code`)), codeLine(plain(`code`))])], - ], - [ - `\`\`\` + [code([codeLine(plain(`code`)), codeLine(plain(`code`))])], + ], + [ + `\`\`\` # code **code** \`\`\``, - [code([codeLine(plain(`# code`)), codeLine(plain(`**code**`))])], - ], + [code([codeLine(plain(`# code`)), codeLine(plain(`**code**`))])], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/color.test.ts b/packages/message-parser/tests/color.test.ts index 9e492dbcfb2..099fe41779c 100644 --- a/packages/message-parser/tests/color.test.ts +++ b/packages/message-parser/tests/color.test.ts @@ -2,33 +2,17 @@ import { parse } from '../src'; import { color, paragraph, plain } from '../src/utils'; test.each([ - [ - 'color:#ccc', - [paragraph([color(0xcc, 0xcc, 0xcc)])], - [paragraph([plain('color:#ccc')])], - ], - [ - 'color:#cccc', - [paragraph([color(0xcc, 0xcc, 0xcc, 0xcc)])], - [paragraph([plain('color:#cccc')])], - ], - [ - 'color:#c7c7c7', - [paragraph([color(0xc7, 0xc7, 0xc7)])], - [paragraph([plain('color:#c7c7c7')])], - ], - [ - 'color:#c7c7c7c7', - [paragraph([color(0xc7, 0xc7, 0xc7, 0xc7)])], - [paragraph([plain('color:#c7c7c7c7')])], - ], - ['color:#c7c7c7c7c7', [paragraph([plain('color:#c7c7c7c7c7')])], undefined], - ['color:#c7', [paragraph([plain('color:#c7')])], undefined], - ['color:#zzz', [paragraph([plain('color:#zzz')])], undefined], + ['color:#ccc', [paragraph([color(0xcc, 0xcc, 0xcc)])], [paragraph([plain('color:#ccc')])]], + ['color:#cccc', [paragraph([color(0xcc, 0xcc, 0xcc, 0xcc)])], [paragraph([plain('color:#cccc')])]], + ['color:#c7c7c7', [paragraph([color(0xc7, 0xc7, 0xc7)])], [paragraph([plain('color:#c7c7c7')])]], + ['color:#c7c7c7c7', [paragraph([color(0xc7, 0xc7, 0xc7, 0xc7)])], [paragraph([plain('color:#c7c7c7c7')])]], + ['color:#c7c7c7c7c7', [paragraph([plain('color:#c7c7c7c7c7')])], undefined], + ['color:#c7', [paragraph([plain('color:#c7')])], undefined], + ['color:#zzz', [paragraph([plain('color:#zzz')])], undefined], ])('parses %p', (input, output, disabledOutput) => { - expect(parse(input, { colors: true })).toMatchObject(output); + expect(parse(input, { colors: true })).toMatchObject(output); - if (disabledOutput) { - expect(parse(input, { colors: false })).toMatchObject(disabledOutput); - } + if (disabledOutput) { + expect(parse(input, { colors: false })).toMatchObject(disabledOutput); + } }); diff --git a/packages/message-parser/tests/email.test.ts b/packages/message-parser/tests/email.test.ts index 4e841385a99..30aade61511 100644 --- a/packages/message-parser/tests/email.test.ts +++ b/packages/message-parser/tests/email.test.ts @@ -2,143 +2,50 @@ import { parse } from '../src'; import { link, paragraph, plain } from '../src/utils'; test.each([ - [ - 'joe@joe.com', - [paragraph([link('mailto:joe@joe.com', [plain('joe@joe.com')])])], - ], - [ - "joe@joe.com is Joe's email", - [ - paragraph([ - link('mailto:joe@joe.com', [plain('joe@joe.com')]), - plain(" is Joe's email"), - ]), - ], - ], - [ - "Joe's email is joe@joe.com because it is", - [ - paragraph([ - plain("Joe's email is "), - link('mailto:joe@joe.com', [plain('joe@joe.com')]), - plain(' because it is'), - ]), - ], - ], - [ - "Joe's email is joe@joe.com", - [ - paragraph([ - plain("Joe's email is "), - link('mailto:joe@joe.com', [plain('joe@joe.com')]), - ]), - ], - ], - [ - "Joe's email is joe@joe.com. Try emailing him", - [ - paragraph([ - plain("Joe's email is "), - link('mailto:joe@joe.com', [plain('joe@joe.com')]), - plain('. Try emailing him'), - ]), - ], - ], - [ - "Joe's email is joe.smith@joe.com", - [ - paragraph([ - plain("Joe's email is "), - link('mailto:joe.smith@joe.com', [plain('joe.smith@joe.com')]), - ]), - ], - ], - [ - "Joe's email is JOE@JOE.COM", - [ - paragraph([ - plain("Joe's email is "), - link('mailto:JOE@JOE.COM', [plain('JOE@JOE.COM')]), - ]), - ], - ], - [ - "Joe's email is (joe@joe.com)", - [ - paragraph([ - plain("Joe's email is ("), - link('mailto:joe@joe.com', [plain('joe@joe.com')]), - plain(')'), - ]), - ], - ], - [ - "Joe's email is (joe_roe@joe.com)", - [ - paragraph([ - plain("Joe's email is ("), - link('mailto:joe_roe@joe.com', [plain('joe_roe@joe.com')]), - plain(')'), - ]), - ], - ], - [ - "Joe's email is (joe'roe@joe.com)", - [ - paragraph([ - plain("Joe's email is ("), - link("mailto:joe'roe@joe.com", [plain("joe'roe@joe.com")]), - plain(')'), - ]), - ], - ], - [ - "Joe's email is mañana@mañana.com", - [ - paragraph([ - plain("Joe's email is "), - link('mailto:mañana@mañana.com', [plain('mañana@mañana.com')]), - ]), - ], - ], - [ - "Joe's email is Кириллица@Кириллица.com", - [ - paragraph([ - plain("Joe's email is "), - link('mailto:Кириллица@Кириллица.com', [ - plain('Кириллица@Кириллица.com'), - ]), - ]), - ], - ], - ['Hi there@stuff', [paragraph([plain('Hi there@stuff')])]], - [ - 'My email is busueng.kim@aaa.com', - [ - paragraph([ - plain('My email is '), - link('mailto:busueng.kim@aaa.com', [plain('busueng.kim@aaa.com')]), - ]), - ], - ], - [ - 'My email is mailto:asdf@asdf.com', - [ - paragraph([ - plain('My email is '), - link('mailto:asdf@asdf.com', [plain('asdf@asdf.com')]), - ]), - ], - ], - [ - 'My email is fake@gmail.c', - [paragraph([plain('My email is fake@gmail.c')])], - ], - [ - 'My email is fake@gmail.comf', - [paragraph([plain('My email is fake@gmail.comf')])], - ], + ['joe@joe.com', [paragraph([link('mailto:joe@joe.com', [plain('joe@joe.com')])])]], + ["joe@joe.com is Joe's email", [paragraph([link('mailto:joe@joe.com', [plain('joe@joe.com')]), plain(" is Joe's email")])]], + [ + "Joe's email is joe@joe.com because it is", + [paragraph([plain("Joe's email is "), link('mailto:joe@joe.com', [plain('joe@joe.com')]), plain(' because it is')])], + ], + ["Joe's email is joe@joe.com", [paragraph([plain("Joe's email is "), link('mailto:joe@joe.com', [plain('joe@joe.com')])])]], + [ + "Joe's email is joe@joe.com. Try emailing him", + [paragraph([plain("Joe's email is "), link('mailto:joe@joe.com', [plain('joe@joe.com')]), plain('. Try emailing him')])], + ], + [ + "Joe's email is joe.smith@joe.com", + [paragraph([plain("Joe's email is "), link('mailto:joe.smith@joe.com', [plain('joe.smith@joe.com')])])], + ], + ["Joe's email is JOE@JOE.COM", [paragraph([plain("Joe's email is "), link('mailto:JOE@JOE.COM', [plain('JOE@JOE.COM')])])]], + [ + "Joe's email is (joe@joe.com)", + [paragraph([plain("Joe's email is ("), link('mailto:joe@joe.com', [plain('joe@joe.com')]), plain(')')])], + ], + [ + "Joe's email is (joe_roe@joe.com)", + [paragraph([plain("Joe's email is ("), link('mailto:joe_roe@joe.com', [plain('joe_roe@joe.com')]), plain(')')])], + ], + [ + "Joe's email is (joe'roe@joe.com)", + [paragraph([plain("Joe's email is ("), link("mailto:joe'roe@joe.com", [plain("joe'roe@joe.com")]), plain(')')])], + ], + [ + "Joe's email is mañana@mañana.com", + [paragraph([plain("Joe's email is "), link('mailto:mañana@mañana.com', [plain('mañana@mañana.com')])])], + ], + [ + "Joe's email is Кириллица@Кириллица.com", + [paragraph([plain("Joe's email is "), link('mailto:Кириллица@Кириллица.com', [plain('Кириллица@Кириллица.com')])])], + ], + ['Hi there@stuff', [paragraph([plain('Hi there@stuff')])]], + [ + 'My email is busueng.kim@aaa.com', + [paragraph([plain('My email is '), link('mailto:busueng.kim@aaa.com', [plain('busueng.kim@aaa.com')])])], + ], + ['My email is mailto:asdf@asdf.com', [paragraph([plain('My email is '), link('mailto:asdf@asdf.com', [plain('asdf@asdf.com')])])]], + ['My email is fake@gmail.c', [paragraph([plain('My email is fake@gmail.c')])]], + ['My email is fake@gmail.comf', [paragraph([plain('My email is fake@gmail.comf')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/emoji.test.ts b/packages/message-parser/tests/emoji.test.ts index 841a05b0e4c..325f29a4f7b 100644 --- a/packages/message-parser/tests/emoji.test.ts +++ b/packages/message-parser/tests/emoji.test.ts @@ -2,91 +2,61 @@ import { parse } from '../src'; import { emoji, bigEmoji, paragraph, plain, emojiUnicode } from '../src/utils'; test.each([ - [':smile: asd', [paragraph([emoji('smile'), plain(' asd')])]], - [':smile:asd', [paragraph([plain(':smile:asd')])]], - ['text:inner:outer', [paragraph([plain('text:inner:outer')])]], - ['10:20:30', [paragraph([plain('10:20:30')])]], - ['10:20:30:', [paragraph([plain('10:20:30:')])]], - ['":smile:"', [paragraph([plain('":smile:"')])]], - ['":smile: "', [paragraph([plain('":smile: "')])]], - ['" :smile: "', [paragraph([plain('" '), emoji('smile'), plain(' "')])]], - [ - `:smile: + [':smile: asd', [paragraph([emoji('smile'), plain(' asd')])]], + [':smile:asd', [paragraph([plain(':smile:asd')])]], + ['text:inner:outer', [paragraph([plain('text:inner:outer')])]], + ['10:20:30', [paragraph([plain('10:20:30')])]], + ['10:20:30:', [paragraph([plain('10:20:30:')])]], + ['":smile:"', [paragraph([plain('":smile:"')])]], + ['":smile: "', [paragraph([plain('":smile: "')])]], + ['" :smile: "', [paragraph([plain('" '), emoji('smile'), plain(' "')])]], + [ + `:smile: :smile: `, - [bigEmoji([emoji('smile'), emoji('smile')])], - ], - [ - 'asdas :smile: asd', - [paragraph([plain('asdas '), emoji('smile'), plain(' asd')])], - ], - [ - 'normal emojis :smile: :smile: :smile:', - [ - paragraph([ - plain('normal emojis '), - emoji('smile'), - plain(' '), - emoji('smile'), - plain(' '), - emoji('smile'), - ]), - ], - ], - [ - ':smile::smile::smile:', - [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], - ], - [ - ' :smile::smile::smile: ', - [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], - ], - [ - '\n :smile::smile::smile: \n', - [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], - ], - [ - ':smile: :smile: :smile:', - [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], - ], - [':smile::smile:', [bigEmoji([emoji('smile'), emoji('smile')])]], - [':smile:a:smile:', [paragraph([plain(':smile:a:smile:')])]], - [':smile:', [bigEmoji([emoji('smile')])]], - ['Hi :+1:', [paragraph([plain('Hi '), emoji('+1')])]], - ['Hi :+1_tone4:', [paragraph([plain('Hi '), emoji('+1_tone4')])]], + [bigEmoji([emoji('smile'), emoji('smile')])], + ], + ['asdas :smile: asd', [paragraph([plain('asdas '), emoji('smile'), plain(' asd')])]], + [ + 'normal emojis :smile: :smile: :smile:', + [paragraph([plain('normal emojis '), emoji('smile'), plain(' '), emoji('smile'), plain(' '), emoji('smile')])], + ], + [':smile::smile::smile:', [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])]], + [' :smile::smile::smile: ', [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])]], + ['\n :smile::smile::smile: \n', [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])]], + [':smile: :smile: :smile:', [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])]], + [':smile::smile:', [bigEmoji([emoji('smile'), emoji('smile')])]], + [':smile:a:smile:', [paragraph([plain(':smile:a:smile:')])]], + [':smile:', [bigEmoji([emoji('smile')])]], + ['Hi :+1:', [paragraph([plain('Hi '), emoji('+1')])]], + ['Hi :+1_tone4:', [paragraph([plain('Hi '), emoji('+1_tone4')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); // Tests for unicode emojis test.each([ - ['😀', [bigEmoji([emojiUnicode('😀')])]], - ['😃', [bigEmoji([emojiUnicode('😃')])]], - ['🥵', [bigEmoji([emojiUnicode('🥵')])]], - ['🧿', [bigEmoji([emojiUnicode('🧿')])]], - ['🐶', [bigEmoji([emojiUnicode('🐶')])]], - ['🍏', [bigEmoji([emojiUnicode('🍏')])]], - ['⚽', [bigEmoji([emojiUnicode('⚽')])]], - ['⚽️', [bigEmoji([emojiUnicode('⚽️')])]], - ['👨‍👩‍👧‍👦', [bigEmoji([emojiUnicode('👨‍👩‍👧‍👦')])]], - ['🚗', [bigEmoji([emojiUnicode('🚗')])]], - ['⌚️', [bigEmoji([emojiUnicode('⌚️')])]], - ['❤️', [bigEmoji([emojiUnicode('❤️')])]], - ['🏳️', [bigEmoji([emojiUnicode('🏳️')])]], - ['🧑🏾‍💻', [bigEmoji([emojiUnicode('🧑🏾‍💻')])]], - ['🧑🏾‍💻🧑🏾‍💻', [bigEmoji([emojiUnicode('🧑🏾‍💻'), emojiUnicode('🧑🏾‍💻')])]], - [ - '🧑🏾‍💻🧑🏾‍💻🧑🏾‍💻', - [bigEmoji([emojiUnicode('🧑🏾‍💻'), emojiUnicode('🧑🏾‍💻'), emojiUnicode('🧑🏾‍💻')])], - ], - ['👆🏽', [bigEmoji([emojiUnicode('👆🏽')])]], - ['👆🏽👆🏽', [bigEmoji([emojiUnicode('👆🏽'), emojiUnicode('👆🏽')])]], - [ - '👆🏽👆🏽👆🏽', - [bigEmoji([emojiUnicode('👆🏽'), emojiUnicode('👆🏽'), emojiUnicode('👆🏽')])], - ], - ['👆🏺', [bigEmoji([emojiUnicode('👆'), emojiUnicode('🏺')])]], - ['Hi 👍', [paragraph([plain('Hi '), emojiUnicode('👍')])]], + ['😀', [bigEmoji([emojiUnicode('😀')])]], + ['😃', [bigEmoji([emojiUnicode('😃')])]], + ['🥵', [bigEmoji([emojiUnicode('🥵')])]], + ['🧿', [bigEmoji([emojiUnicode('🧿')])]], + ['🐶', [bigEmoji([emojiUnicode('🐶')])]], + ['🍏', [bigEmoji([emojiUnicode('🍏')])]], + ['⚽', [bigEmoji([emojiUnicode('⚽')])]], + ['⚽️', [bigEmoji([emojiUnicode('⚽️')])]], + ['👨‍👩‍👧‍👦', [bigEmoji([emojiUnicode('👨‍👩‍👧‍👦')])]], + ['🚗', [bigEmoji([emojiUnicode('🚗')])]], + ['⌚️', [bigEmoji([emojiUnicode('⌚️')])]], + ['❤️', [bigEmoji([emojiUnicode('❤️')])]], + ['🏳️', [bigEmoji([emojiUnicode('🏳️')])]], + ['🧑🏾‍💻', [bigEmoji([emojiUnicode('🧑🏾‍💻')])]], + ['🧑🏾‍💻🧑🏾‍💻', [bigEmoji([emojiUnicode('🧑🏾‍💻'), emojiUnicode('🧑🏾‍💻')])]], + ['🧑🏾‍💻🧑🏾‍💻🧑🏾‍💻', [bigEmoji([emojiUnicode('🧑🏾‍💻'), emojiUnicode('🧑🏾‍💻'), emojiUnicode('🧑🏾‍💻')])]], + ['👆🏽', [bigEmoji([emojiUnicode('👆🏽')])]], + ['👆🏽👆🏽', [bigEmoji([emojiUnicode('👆🏽'), emojiUnicode('👆🏽')])]], + ['👆🏽👆🏽👆🏽', [bigEmoji([emojiUnicode('👆🏽'), emojiUnicode('👆🏽'), emojiUnicode('👆🏽')])]], + ['👆🏺', [bigEmoji([emojiUnicode('👆'), emojiUnicode('🏺')])]], + ['Hi 👍', [paragraph([plain('Hi '), emojiUnicode('👍')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/emoticons.test.ts b/packages/message-parser/tests/emoticons.test.ts index b2ffbc5ab55..715712ae715 100644 --- a/packages/message-parser/tests/emoticons.test.ts +++ b/packages/message-parser/tests/emoticons.test.ts @@ -2,146 +2,69 @@ import { parse } from '../src'; import { bigEmoji, paragraph, plain, emoticon } from '../src/utils'; test.each([ - // Should render normal Emojis - [ - `test + // Should render normal Emojis + [ + `test :) test`, - [ - paragraph([plain('test')]), - paragraph([ - plain(' '), - emoticon(':)', 'slight_smile'), - plain(' test'), - ]), - ], - ], - [':) asd', [paragraph([emoticon(':)', 'slight_smile'), plain(' asd')])]], - [ - ' :) asd', - [paragraph([plain(' '), emoticon(':)', 'slight_smile'), plain(' asd')])], - ], - ['Hi :)', [paragraph([plain('Hi '), emoticon(':)', 'slight_smile')])]], - [ - 'asdas :) asd', - [ - paragraph([ - plain('asdas '), - emoticon(':)', 'slight_smile'), - plain(' asd'), - ]), - ], - ], - [ - ':) :) :) :)', - [ - paragraph([ - emoticon(':)', 'slight_smile'), - plain(' '), - emoticon(':)', 'slight_smile'), - plain(' '), - emoticon(':)', 'slight_smile'), - plain(' '), - emoticon(':)', 'slight_smile'), - ]), - ], - ], + [paragraph([plain('test')]), paragraph([plain(' '), emoticon(':)', 'slight_smile'), plain(' test')])], + ], + [':) asd', [paragraph([emoticon(':)', 'slight_smile'), plain(' asd')])]], + [' :) asd', [paragraph([plain(' '), emoticon(':)', 'slight_smile'), plain(' asd')])]], + ['Hi :)', [paragraph([plain('Hi '), emoticon(':)', 'slight_smile')])]], + ['asdas :) asd', [paragraph([plain('asdas '), emoticon(':)', 'slight_smile'), plain(' asd')])]], + [ + ':) :) :) :)', + [ + paragraph([ + emoticon(':)', 'slight_smile'), + plain(' '), + emoticon(':)', 'slight_smile'), + plain(' '), + emoticon(':)', 'slight_smile'), + plain(' '), + emoticon(':)', 'slight_smile'), + ]), + ], + ], - // Should render BigEmojis - [ - `:) + // Should render BigEmojis + [ + `:) :) `, - [ - bigEmoji([ - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - ]), - ], - ], - [ - ':):):)', - [ - bigEmoji([ - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - ]), - ], - ], + [bigEmoji([emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile')])], + ], + [':):):)', [bigEmoji([emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile')])]], - [ - ' :):):) ', - [ - bigEmoji([ - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - ]), - ], - ], + [' :):):) ', [bigEmoji([emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile')])]], - [ - '\n :):):) \n', - [ - bigEmoji([ - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - ]), - ], - ], - [ - ':) :) :)', - [ - bigEmoji([ - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - ]), - ], - ], + ['\n :):):) \n', [bigEmoji([emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile')])]], + [':) :) :)', [bigEmoji([emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile')])]], - [ - ':) :)', - [ - bigEmoji([ - emoticon(':)', 'slight_smile'), - emoticon(':)', 'slight_smile'), - ]), - ], - ], - [':)', [bigEmoji([emoticon(':)', 'slight_smile')])]], - [' :)', [bigEmoji([emoticon(':)', 'slight_smile')])]], - [':) ', [bigEmoji([emoticon(':)', 'slight_smile')])]], - [' :) ', [bigEmoji([emoticon(':)', 'slight_smile')])]], - ['D:', [bigEmoji([emoticon('D:', 'fearful')])]], - ['D: D:', [bigEmoji([emoticon('D:', 'fearful'), emoticon('D:', 'fearful')])]], - [ - ' D: D: D: ', - [ - bigEmoji([ - emoticon('D:', 'fearful'), - emoticon('D:', 'fearful'), - emoticon('D:', 'fearful'), - ]), - ], - ], - ['Hi D:', [paragraph([plain('Hi '), emoticon('D:', 'fearful')])]], + [':) :)', [bigEmoji([emoticon(':)', 'slight_smile'), emoticon(':)', 'slight_smile')])]], + [':)', [bigEmoji([emoticon(':)', 'slight_smile')])]], + [' :)', [bigEmoji([emoticon(':)', 'slight_smile')])]], + [':) ', [bigEmoji([emoticon(':)', 'slight_smile')])]], + [' :) ', [bigEmoji([emoticon(':)', 'slight_smile')])]], + ['D:', [bigEmoji([emoticon('D:', 'fearful')])]], + ['D: D:', [bigEmoji([emoticon('D:', 'fearful'), emoticon('D:', 'fearful')])]], + [' D: D: D: ', [bigEmoji([emoticon('D:', 'fearful'), emoticon('D:', 'fearful'), emoticon('D:', 'fearful')])]], + ['Hi D:', [paragraph([plain('Hi '), emoticon('D:', 'fearful')])]], - // Should not render Emojis or BigEmojis if they are not surrounded by spaces - ['normal emojis :):):)', [paragraph([plain('normal emojis :):):)')])]], - [':)10:30', [paragraph([plain(':)10:30')])]], - [':smile::)text', [paragraph([plain(':smile::)text')])]], - ['text:):smile:', [paragraph([plain('text:):smile:')])]], - ['text:):)', [paragraph([plain('text:):)')])]], - [':):):) normal emojis', [paragraph([plain(':):):) normal emojis')])]], - [':):):):)', [paragraph([plain(':):):):)')])]], - ['10:30', [paragraph([plain('10:30')])]], - ['he:)llo', [paragraph([plain('he:)llo')])]], - [':)Hi', [paragraph([plain(':)Hi')])]], - ['Hi:) Hi', [paragraph([plain('Hi:) Hi')])]], - ['Hi:)', [paragraph([plain('Hi:)')])]], - ['@#@#! :)@!@', [paragraph([plain('@#@#! :)@!@')])]], + // Should not render Emojis or BigEmojis if they are not surrounded by spaces + ['normal emojis :):):)', [paragraph([plain('normal emojis :):):)')])]], + [':)10:30', [paragraph([plain(':)10:30')])]], + [':smile::)text', [paragraph([plain(':smile::)text')])]], + ['text:):smile:', [paragraph([plain('text:):smile:')])]], + ['text:):)', [paragraph([plain('text:):)')])]], + [':):):) normal emojis', [paragraph([plain(':):):) normal emojis')])]], + [':):):):)', [paragraph([plain(':):):):)')])]], + ['10:30', [paragraph([plain('10:30')])]], + ['he:)llo', [paragraph([plain('he:)llo')])]], + [':)Hi', [paragraph([plain(':)Hi')])]], + ['Hi:) Hi', [paragraph([plain('Hi:) Hi')])]], + ['Hi:)', [paragraph([plain('Hi:)')])]], + ['@#@#! :)@!@', [paragraph([plain('@#@#! :)@!@')])]], ])('parses %p', (input, output) => { - expect(parse(input, { emoticons: true })).toMatchObject(output); + expect(parse(input, { emoticons: true })).toMatchObject(output); }); diff --git a/packages/message-parser/tests/emphasis.test.ts b/packages/message-parser/tests/emphasis.test.ts index a3b220ce821..5c26f118428 100644 --- a/packages/message-parser/tests/emphasis.test.ts +++ b/packages/message-parser/tests/emphasis.test.ts @@ -1,283 +1,131 @@ import { parse } from '../src'; import { - italic, - paragraph, - plain, - strike, - bold, - emoji, - link, - bigEmoji, - emojiUnicode, - mentionChannel, - mentionUser, - inlineCode, + italic, + paragraph, + plain, + strike, + bold, + emoji, + link, + bigEmoji, + emojiUnicode, + mentionChannel, + mentionUser, + inlineCode, } from '../src/utils'; test.each([ - ['_:smile:_', [paragraph([italic([emoji('smile')])])]], - ['_:slight_smile:_', [paragraph([italic([emoji('slight_smile')])])]], - [ - '_test :smile: test_', - [paragraph([italic([plain('test '), emoji('smile'), plain(' test')])])], - ], - [ - '_test :slight_smile: test_', - [ - paragraph([ - italic([plain('test '), emoji('slight_smile'), plain(' test')]), - ]), - ], - ], - ['_😀_', [paragraph([italic([emojiUnicode('😀')])])]], - ['_test 😀_', [paragraph([italic([plain('test '), emojiUnicode('😀')])])]], - [ - '_test @guilherme.gazzo test_', - [ - paragraph([ - italic([ - plain('test '), - mentionUser('guilherme.gazzo'), - plain(' test'), - ]), - ]), - ], - ], - [ - '_test #GENERAL test_', - [ - paragraph([ - italic([plain('test '), mentionChannel('GENERAL'), plain(' test')]), - ]), - ], - ], - [ - '_[A brand new Gist](https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4)_', - [ - paragraph([ - italic([ - link('https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4', [ - plain('A brand new Gist'), - ]), - ]), - ]), - ], - ], - ['__italic__', [paragraph([italic([plain('italic')])])]], - ['__italic__non', [paragraph([plain('__italic__non')])]], - ['__test__test__', [paragraph([plain('__test__test__')])]], - ['pre__italic__post', [paragraph([plain('pre__italic__post')])]], - [' pre__italic__post', [paragraph([plain(' pre__italic__post')])]], - [ - ' pre__**~~boldstrikeitalic~~**__post ', - [ - paragraph([ - plain(' pre__'), - bold([strike([plain('boldstrikeitalic')])]), - plain('__post '), - ]), - ], - ], - ['__', [paragraph([plain('__')])]], - ['_ _', [paragraph([plain('_ _')])]], - ['__ _', [paragraph([plain('__ _')])]], - ['__ __', [paragraph([plain('__ __')])]], - ['_ Hello_', [paragraph([italic([plain(' Hello')])])]], - ['_Hello _', [paragraph([italic([plain('Hello ')])])]], - [':custom_emoji_case:', [bigEmoji([emoji('custom_emoji_case')])]], - ['_Hel lo_', [paragraph([italic([plain('Hel lo')])])]], - ['_Hello_', [paragraph([italic([plain('Hello')])])]], - ['__Hello__', [paragraph([italic([plain('Hello')])])]], - ['__Hello_', [paragraph([plain('_'), italic([plain('Hello')])])]], - ['_Hello__', [paragraph([italic([plain('Hello')]), plain('_')])]], - ['_Hello', [paragraph([plain('_Hello')])]], - ['Hello_', [paragraph([plain('Hello_')])]], - ['He_llo', [paragraph([plain('He_llo')])]], - [ - '___Hello___', - [paragraph([plain('_'), italic([plain('Hello')]), plain('_')])], - ], - ['___Hello__', [paragraph([plain('_'), italic([plain('Hello')])])]], - [ - '_Hello_ this is dog', - [paragraph([italic([plain('Hello')]), plain(` this is dog`)])], - ], - [ - 'Rocket cat says _Hello_', - [paragraph([plain(`Rocket cat says `), italic([plain('Hello')])])], - ], - [ - 'He said _Hello_ to her', - [ - paragraph([ - plain(`He said `), - italic([plain('Hello')]), - plain(` to her`), - ]), - ], - ], - [ - '__Hello__ this is dog', - [paragraph([italic([plain('Hello')]), plain(` this is dog`)])], - ], - [ - 'Rocket cat says __Hello__', - [paragraph([plain(`Rocket cat says `), italic([plain('Hello')])])], - ], - [ - 'He said __Hello__ to her', - [ - paragraph([ - plain(`He said `), - italic([plain('Hello')]), - plain(` to her`), - ]), - ], - ], - ['text_hello_text', [paragraph([plain('text_hello_text')])]], - ['_hello_text', [paragraph([plain('_hello_text')])]], - ['text_hello_', [paragraph([plain('text_hello_')])]], - ['_italic@test_', [paragraph([italic([plain('italic@test')])])]], - ['_italic#test_', [paragraph([italic([plain('italic#test')])])]], - ['paragraph@test__', [paragraph([plain('paragraph@test__')])]], - [ - '_ @guilherme_gazzo_ _', - [ - paragraph([ - italic([plain(' '), mentionUser('guilherme_gazzo_'), plain(' ')]), - ]), - ], - ], - [ - '_ @guilherme.gazzo _', - [ - paragraph([ - italic([plain(' '), mentionUser('guilherme.gazzo'), plain(' ')]), - ]), - ], - ], - [ - '**reference link inside [emphasis with more [references](https://rocket.chat)](https://rocket.chat)**', - [ - paragraph([ - bold([ - plain('reference link inside '), - link('https://rocket.chat', [ - plain('emphasis with more [references'), - ]), - plain('](https://rocket.chat)'), - ]), - ]), - ], - ], - ['_ouch_ouch', [paragraph([plain('_ouch_ouch')])]], - [ - `_@mention _gone`, - [paragraph([plain('_'), mentionUser('mention'), plain(' _gone')])], - ], - [ - '_nothing `should` be _gone', - [ - paragraph([ - plain('_nothing '), - inlineCode(plain('should')), - plain(' be _gone'), - ]), - ], - ], - [ - '**bold ~~and strike~~** **not bold ~~but strike** ~~ not strike~~', - [ - paragraph([ - bold([plain('bold '), strike([plain('and strike')])]), - plain(' **not bold '), - strike([plain('but strike** ')]), - plain(' not strike~~'), - ]), - ], - ], - [ - '**bold** **another bold** ~~strike~~ ~~another strike~~ **bold ~~and strike~~** **not bold ~~but strike** ~~ not strike~~', - [ - paragraph([ - bold([plain('bold')]), - plain(' '), - bold([plain('another bold')]), - plain(' '), - strike([plain('strike')]), - plain(' '), - strike([plain('another strike')]), - plain(' '), - bold([plain('bold '), strike([plain('and strike')])]), - plain(' **not bold '), - strike([plain('but strike** ')]), - plain(' not strike~~'), - ]), - ], - ], - [ - 'some_snake_case_text and even_more', - [paragraph([plain('some_snake_case_text and even_more')])], - ], - [ - 'some_snake_case_text and some __italic__ text', - [ - paragraph([ - plain('some_snake_case_text and some '), - italic([plain('italic')]), - plain(' text'), - ]), - ], - ], - [ - 'some__double__snake__case__text and even_more', - [paragraph([plain('some__double__snake__case__text and even_more')])], - ], - [ - 'some__double__snake__case__text and some __italic__ text', - [ - paragraph([ - plain('some__double__snake__case__text and some '), - italic([plain('italic')]), - plain(' text'), - ]), - ], - ], - [ - 'something__ __and italic__', - [paragraph([plain('something__ '), italic([plain('and italic')])])], - ], - ['*test:*', [paragraph([bold([plain('test:')])])]], - [ - '*bold ending with colon:*', - [paragraph([bold([plain('bold ending with colon:')])])], - ], - [ - '*bold ending with colon:* and some more text', - [ - paragraph([ - bold([plain('bold ending with colon:')]), - plain(' and some more text'), - ]), - ], - ], - [ - '*bold ending with colon :*and some more text', - [ - paragraph([ - bold([plain('bold ending with colon :')]), - plain('and some more text'), - ]), - ], - ], - [ - '*bold with a kissing emoji :* *', - [paragraph([bold([plain('bold with a kissing emoji :')]), plain(' *')])], - ], - [ - '*bold with a kissing emoji :* ', - [paragraph([bold([plain('bold with a kissing emoji :')]), plain(' ')])], - ], + ['_:smile:_', [paragraph([italic([emoji('smile')])])]], + ['_:slight_smile:_', [paragraph([italic([emoji('slight_smile')])])]], + ['_test :smile: test_', [paragraph([italic([plain('test '), emoji('smile'), plain(' test')])])]], + ['_test :slight_smile: test_', [paragraph([italic([plain('test '), emoji('slight_smile'), plain(' test')])])]], + ['_😀_', [paragraph([italic([emojiUnicode('😀')])])]], + ['_test 😀_', [paragraph([italic([plain('test '), emojiUnicode('😀')])])]], + ['_test @guilherme.gazzo test_', [paragraph([italic([plain('test '), mentionUser('guilherme.gazzo'), plain(' test')])])]], + ['_test #GENERAL test_', [paragraph([italic([plain('test '), mentionChannel('GENERAL'), plain(' test')])])]], + [ + '_[A brand new Gist](https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4)_', + [paragraph([italic([link('https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4', [plain('A brand new Gist')])])])], + ], + ['__italic__', [paragraph([italic([plain('italic')])])]], + ['__italic__non', [paragraph([plain('__italic__non')])]], + ['__test__test__', [paragraph([plain('__test__test__')])]], + ['pre__italic__post', [paragraph([plain('pre__italic__post')])]], + [' pre__italic__post', [paragraph([plain(' pre__italic__post')])]], + [' pre__**~~boldstrikeitalic~~**__post ', [paragraph([plain(' pre__'), bold([strike([plain('boldstrikeitalic')])]), plain('__post ')])]], + ['__', [paragraph([plain('__')])]], + ['_ _', [paragraph([plain('_ _')])]], + ['__ _', [paragraph([plain('__ _')])]], + ['__ __', [paragraph([plain('__ __')])]], + ['_ Hello_', [paragraph([italic([plain(' Hello')])])]], + ['_Hello _', [paragraph([italic([plain('Hello ')])])]], + [':custom_emoji_case:', [bigEmoji([emoji('custom_emoji_case')])]], + ['_Hel lo_', [paragraph([italic([plain('Hel lo')])])]], + ['_Hello_', [paragraph([italic([plain('Hello')])])]], + ['__Hello__', [paragraph([italic([plain('Hello')])])]], + ['__Hello_', [paragraph([plain('_'), italic([plain('Hello')])])]], + ['_Hello__', [paragraph([italic([plain('Hello')]), plain('_')])]], + ['_Hello', [paragraph([plain('_Hello')])]], + ['Hello_', [paragraph([plain('Hello_')])]], + ['He_llo', [paragraph([plain('He_llo')])]], + ['___Hello___', [paragraph([plain('_'), italic([plain('Hello')]), plain('_')])]], + ['___Hello__', [paragraph([plain('_'), italic([plain('Hello')])])]], + ['_Hello_ this is dog', [paragraph([italic([plain('Hello')]), plain(` this is dog`)])]], + ['Rocket cat says _Hello_', [paragraph([plain(`Rocket cat says `), italic([plain('Hello')])])]], + ['He said _Hello_ to her', [paragraph([plain(`He said `), italic([plain('Hello')]), plain(` to her`)])]], + ['__Hello__ this is dog', [paragraph([italic([plain('Hello')]), plain(` this is dog`)])]], + ['Rocket cat says __Hello__', [paragraph([plain(`Rocket cat says `), italic([plain('Hello')])])]], + ['He said __Hello__ to her', [paragraph([plain(`He said `), italic([plain('Hello')]), plain(` to her`)])]], + ['text_hello_text', [paragraph([plain('text_hello_text')])]], + ['_hello_text', [paragraph([plain('_hello_text')])]], + ['text_hello_', [paragraph([plain('text_hello_')])]], + ['_italic@test_', [paragraph([italic([plain('italic@test')])])]], + ['_italic#test_', [paragraph([italic([plain('italic#test')])])]], + ['paragraph@test__', [paragraph([plain('paragraph@test__')])]], + ['_ @guilherme_gazzo_ _', [paragraph([italic([plain(' '), mentionUser('guilherme_gazzo_'), plain(' ')])])]], + ['_ @guilherme.gazzo _', [paragraph([italic([plain(' '), mentionUser('guilherme.gazzo'), plain(' ')])])]], + [ + '**reference link inside [emphasis with more [references](https://rocket.chat)](https://rocket.chat)**', + [ + paragraph([ + bold([ + plain('reference link inside '), + link('https://rocket.chat', [plain('emphasis with more [references')]), + plain('](https://rocket.chat)'), + ]), + ]), + ], + ], + ['_ouch_ouch', [paragraph([plain('_ouch_ouch')])]], + [`_@mention _gone`, [paragraph([plain('_'), mentionUser('mention'), plain(' _gone')])]], + ['_nothing `should` be _gone', [paragraph([plain('_nothing '), inlineCode(plain('should')), plain(' be _gone')])]], + [ + '**bold ~~and strike~~** **not bold ~~but strike** ~~ not strike~~', + [ + paragraph([ + bold([plain('bold '), strike([plain('and strike')])]), + plain(' **not bold '), + strike([plain('but strike** ')]), + plain(' not strike~~'), + ]), + ], + ], + [ + '**bold** **another bold** ~~strike~~ ~~another strike~~ **bold ~~and strike~~** **not bold ~~but strike** ~~ not strike~~', + [ + paragraph([ + bold([plain('bold')]), + plain(' '), + bold([plain('another bold')]), + plain(' '), + strike([plain('strike')]), + plain(' '), + strike([plain('another strike')]), + plain(' '), + bold([plain('bold '), strike([plain('and strike')])]), + plain(' **not bold '), + strike([plain('but strike** ')]), + plain(' not strike~~'), + ]), + ], + ], + ['some_snake_case_text and even_more', [paragraph([plain('some_snake_case_text and even_more')])]], + [ + 'some_snake_case_text and some __italic__ text', + [paragraph([plain('some_snake_case_text and some '), italic([plain('italic')]), plain(' text')])], + ], + ['some__double__snake__case__text and even_more', [paragraph([plain('some__double__snake__case__text and even_more')])]], + [ + 'some__double__snake__case__text and some __italic__ text', + [paragraph([plain('some__double__snake__case__text and some '), italic([plain('italic')]), plain(' text')])], + ], + ['something__ __and italic__', [paragraph([plain('something__ '), italic([plain('and italic')])])]], + ['*test:*', [paragraph([bold([plain('test:')])])]], + ['*bold ending with colon:*', [paragraph([bold([plain('bold ending with colon:')])])]], + ['*bold ending with colon:* and some more text', [paragraph([bold([plain('bold ending with colon:')]), plain(' and some more text')])]], + ['*bold ending with colon :*and some more text', [paragraph([bold([plain('bold ending with colon :')]), plain('and some more text')])]], + ['*bold with a kissing emoji :* *', [paragraph([bold([plain('bold with a kissing emoji :')]), plain(' *')])]], + ['*bold with a kissing emoji :* ', [paragraph([bold([plain('bold with a kissing emoji :')]), plain(' ')])]], ])('parses %p', (input, output) => { - expect(parse(input, { emoticons: false })).toMatchObject(output); + expect(parse(input, { emoticons: false })).toMatchObject(output); }); diff --git a/packages/message-parser/tests/emphasisWithEmoticons.test.ts b/packages/message-parser/tests/emphasisWithEmoticons.test.ts index 4bbb746f3d5..324ef9076c8 100644 --- a/packages/message-parser/tests/emphasisWithEmoticons.test.ts +++ b/packages/message-parser/tests/emphasisWithEmoticons.test.ts @@ -2,166 +2,57 @@ import { parse } from '../src'; import { paragraph, plain, bold, italic, emoticon } from '../src/utils'; test.each([ - ['*test:*', [paragraph([bold([plain('test:')])])]], - ['_test:_', [paragraph([italic([plain('test:')])])]], - [ - // :* is an emoticon, but it shouldn't be parsed as one if its glued to a word - '*bold ending with colon:*', - [paragraph([bold([plain('bold ending with colon:')])])], - ], - [ - '*bold ending with colon:* and some more text', - [ - paragraph([ - bold([plain('bold ending with colon:')]), - plain(' and some more text'), - ]), - ], - ], - [ - '*bold ending with colon :*and some more text', - [ - paragraph([ - bold([plain('bold ending with colon :')]), - plain('and some more text'), - ]), - ], - ], - [ - '*bold with a kissing emoji :* *', - [ - paragraph([ - bold([ - plain('bold with a kissing emoji '), - emoticon(':*', 'kissing_heart'), - plain(' '), - ]), - ]), - ], - ], - [ - '*bold with a broken kissing emoji:**', - [ - paragraph([ - bold([plain('bold with a broken kissing emoji:')]), - plain('*'), - ]), - ], - ], - [ - '*bold with a broken kissing emoji:*:*', - [ - paragraph([ - bold([plain('bold with a broken kissing emoji:')]), - emoticon(':*', 'kissing_heart'), - ]), - ], - ], - [ - '*bold with a broken kissing emoji :*text *', - [ - paragraph([ - bold([plain('bold with a broken kissing emoji :')]), - plain('text *'), - ]), - ], - ], - [ - '*broken bold with a kissing emoji :*', - [ - paragraph([ - plain('*broken bold with a kissing emoji '), - emoticon(':*', 'kissing_heart'), - ]), - ], - ], - [ - '*broken bold with a kissing emoji :* ', - [ - paragraph([ - plain('*broken bold with a kissing emoji '), - emoticon(':*', 'kissing_heart'), - plain(' '), - ]), - ], - ], - [ - '*two bolds**second*', - [paragraph([bold([plain('two bolds')]), bold([plain('second')])])], - ], - [ - '*two bolds*:**separated by kissing emoji*', - [ - paragraph([ - bold([plain('two bolds')]), - emoticon(':*', 'kissing_heart'), - bold([plain('separated by kissing emoji')]), - ]), - ], - ], - ['_test-_-', [paragraph([italic([plain('test-')]), plain('-')])]], - [ - '_test -_- _', - [ - paragraph([ - italic([plain('test '), emoticon('-_-', 'expressionless'), plain(' ')]), - ]), - ], - ], - [ - '_test -_-_', - [paragraph([italic([plain('test '), emoticon('-_-', 'expressionless')])])], - ], - [ - '_two italics__second_', - [paragraph([italic([plain('two italics')]), italic([plain('second')])])], - ], - [ - '_italic with broken emoticon-_-_', - [paragraph([italic([plain('italic with broken emoticon-')]), plain('-_')])], - ], - [ - '_italic with broken emoticon-_-_ and more text', - [ - paragraph([ - italic([plain('italic with broken emoticon-')]), - plain('-_ and more text'), - ]), - ], - ], - [ - '_italic with broken emoticon -_-and more text', - [ - paragraph([ - italic([plain('italic with broken emoticon -')]), - plain('-and more text'), - ]), - ], - ], - [ - '_italic with broken emoticon -_-and more text -_-', - [ - paragraph([ - italic([plain('italic with broken emoticon -')]), - plain('-and more text '), - emoticon('-_-', 'expressionless'), - ]), - ], - ], - [ - '_italic with broken emoticon -_-and more text -_-_', - [ - paragraph([ - italic([plain('italic with broken emoticon -')]), - plain('-and more text -'), - italic([plain('-')]), - ]), - ], - ], - [ - '-_-italic content-_-', - [paragraph([plain('-'), italic([plain('-italic content-')]), plain('-')])], - ], + ['*test:*', [paragraph([bold([plain('test:')])])]], + ['_test:_', [paragraph([italic([plain('test:')])])]], + [ + // :* is an emoticon, but it shouldn't be parsed as one if its glued to a word + '*bold ending with colon:*', + [paragraph([bold([plain('bold ending with colon:')])])], + ], + ['*bold ending with colon:* and some more text', [paragraph([bold([plain('bold ending with colon:')]), plain(' and some more text')])]], + ['*bold ending with colon :*and some more text', [paragraph([bold([plain('bold ending with colon :')]), plain('and some more text')])]], + [ + '*bold with a kissing emoji :* *', + [paragraph([bold([plain('bold with a kissing emoji '), emoticon(':*', 'kissing_heart'), plain(' ')])])], + ], + ['*bold with a broken kissing emoji:**', [paragraph([bold([plain('bold with a broken kissing emoji:')]), plain('*')])]], + [ + '*bold with a broken kissing emoji:*:*', + [paragraph([bold([plain('bold with a broken kissing emoji:')]), emoticon(':*', 'kissing_heart')])], + ], + ['*bold with a broken kissing emoji :*text *', [paragraph([bold([plain('bold with a broken kissing emoji :')]), plain('text *')])]], + ['*broken bold with a kissing emoji :*', [paragraph([plain('*broken bold with a kissing emoji '), emoticon(':*', 'kissing_heart')])]], + [ + '*broken bold with a kissing emoji :* ', + [paragraph([plain('*broken bold with a kissing emoji '), emoticon(':*', 'kissing_heart'), plain(' ')])], + ], + ['*two bolds**second*', [paragraph([bold([plain('two bolds')]), bold([plain('second')])])]], + [ + '*two bolds*:**separated by kissing emoji*', + [paragraph([bold([plain('two bolds')]), emoticon(':*', 'kissing_heart'), bold([plain('separated by kissing emoji')])])], + ], + ['_test-_-', [paragraph([italic([plain('test-')]), plain('-')])]], + ['_test -_- _', [paragraph([italic([plain('test '), emoticon('-_-', 'expressionless'), plain(' ')])])]], + ['_test -_-_', [paragraph([italic([plain('test '), emoticon('-_-', 'expressionless')])])]], + ['_two italics__second_', [paragraph([italic([plain('two italics')]), italic([plain('second')])])]], + ['_italic with broken emoticon-_-_', [paragraph([italic([plain('italic with broken emoticon-')]), plain('-_')])]], + [ + '_italic with broken emoticon-_-_ and more text', + [paragraph([italic([plain('italic with broken emoticon-')]), plain('-_ and more text')])], + ], + [ + '_italic with broken emoticon -_-and more text', + [paragraph([italic([plain('italic with broken emoticon -')]), plain('-and more text')])], + ], + [ + '_italic with broken emoticon -_-and more text -_-', + [paragraph([italic([plain('italic with broken emoticon -')]), plain('-and more text '), emoticon('-_-', 'expressionless')])], + ], + [ + '_italic with broken emoticon -_-and more text -_-_', + [paragraph([italic([plain('italic with broken emoticon -')]), plain('-and more text -'), italic([plain('-')])])], + ], + ['-_-italic content-_-', [paragraph([plain('-'), italic([plain('-italic content-')]), plain('-')])]], ])('parses emphasisWithEmoticons %p', (input, output) => { - expect(parse(input, { emoticons: true })).toMatchObject(output); + expect(parse(input, { emoticons: true })).toMatchObject(output); }); diff --git a/packages/message-parser/tests/escaped.test.ts b/packages/message-parser/tests/escaped.test.ts index ffe297aee29..7c0a3a2df35 100644 --- a/packages/message-parser/tests/escaped.test.ts +++ b/packages/message-parser/tests/escaped.test.ts @@ -2,37 +2,19 @@ import { parse } from '../src'; import { paragraph, plain, bold } from '../src/utils'; test.each([ - ['¯\\\\_(ツ)_/¯', [paragraph([plain('¯\\_(ツ)_/¯')])]], - [ - '\\*escaped as*bold*escaped*', - [ - paragraph([ - plain('*escaped as'), - bold([plain('bold')]), - plain('escaped*'), - ]), - ], - ], - ['\\*not bold*', [paragraph([plain('*not bold*')])]], - ['*_~`#.'.split('').join('\\'), [paragraph([plain('*_~`#.')])]], - ['\\*not emphasized*', [paragraph([plain('*not emphasized*')])]], - ['\\
tag plain text', [paragraph([plain('\\
tag plain text')])]], - [ - '\\[it is not a link](/foo)', - [paragraph([plain('\\[it is not a link](/foo)')])], - ], - ['\\`not code`', [paragraph([plain('`not code`')])]], - ['1\\. not a list', [paragraph([plain('1. not a list')])]], - ['\\* not a list', [paragraph([plain('* not a list')])]], - ['\\# not a heading', [paragraph([plain('# not a heading')])]], - [ - '\\[foo]: /url "not a reference"', - [paragraph([plain('\\[foo]: /url "not a reference"')])], - ], - [ - '\\ö not a character entity', - [paragraph([plain('\\ö not a character entity')])], - ], + ['¯\\\\_(ツ)_/¯', [paragraph([plain('¯\\_(ツ)_/¯')])]], + ['\\*escaped as*bold*escaped*', [paragraph([plain('*escaped as'), bold([plain('bold')]), plain('escaped*')])]], + ['\\*not bold*', [paragraph([plain('*not bold*')])]], + ['*_~`#.'.split('').join('\\'), [paragraph([plain('*_~`#.')])]], + ['\\*not emphasized*', [paragraph([plain('*not emphasized*')])]], + ['\\
tag plain text', [paragraph([plain('\\
tag plain text')])]], + ['\\[it is not a link](/foo)', [paragraph([plain('\\[it is not a link](/foo)')])]], + ['\\`not code`', [paragraph([plain('`not code`')])]], + ['1\\. not a list', [paragraph([plain('1. not a list')])]], + ['\\* not a list', [paragraph([plain('* not a list')])]], + ['\\# not a heading', [paragraph([plain('# not a heading')])]], + ['\\[foo]: /url "not a reference"', [paragraph([plain('\\[foo]: /url "not a reference"')])]], + ['\\ö not a character entity', [paragraph([plain('\\ö not a character entity')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/heading.test.ts b/packages/message-parser/tests/heading.test.ts index 84b9463bb63..abcbed075ef 100644 --- a/packages/message-parser/tests/heading.test.ts +++ b/packages/message-parser/tests/heading.test.ts @@ -1,58 +1,49 @@ import { parse } from '../src'; -import { - heading, - lineBreak, - mentionChannel, - paragraph, - plain, -} from '../src/utils'; +import { heading, lineBreak, mentionChannel, paragraph, plain } from '../src/utils'; test.each([ - ['# h1', [heading([plain('h1')], 1)]], - ['# Hello', [heading([plain('Hello')], 1)]], - ['# Rocket.Cat', [heading([plain('Rocket.Cat')], 1)]], - ['# Hi', [heading([plain('Hi')], 1)]], - ['# Hello this is dog', [heading([plain('Hello this is dog')], 1)]], - ['# Rocket cat says Hello', [heading([plain('Rocket cat says Hello')], 1)]], - ['# He said Hello to her', [heading([plain('He said Hello to her')], 1)]], - ['#Hello', [paragraph([mentionChannel('Hello')])]], - ['#Hello#', [paragraph([mentionChannel('Hello'), plain('#')])]], - ['He#llo', [paragraph([plain('He#llo')])]], + ['# h1', [heading([plain('h1')], 1)]], + ['# Hello', [heading([plain('Hello')], 1)]], + ['# Rocket.Cat', [heading([plain('Rocket.Cat')], 1)]], + ['# Hi', [heading([plain('Hi')], 1)]], + ['# Hello this is dog', [heading([plain('Hello this is dog')], 1)]], + ['# Rocket cat says Hello', [heading([plain('Rocket cat says Hello')], 1)]], + ['# He said Hello to her', [heading([plain('He said Hello to her')], 1)]], + ['#Hello', [paragraph([mentionChannel('Hello')])]], + ['#Hello#', [paragraph([mentionChannel('Hello'), plain('#')])]], + ['He#llo', [paragraph([plain('He#llo')])]], - ['## Hello', [heading([plain('Hello')], 2)]], - ['## Rocket.Cat', [heading([plain('Rocket.Cat')], 2)]], - ['## Hi', [heading([plain('Hi')], 2)]], - ['## Hello this is dog', [heading([plain('Hello this is dog')], 2)]], - ['## Rocket cat says Hello', [heading([plain('Rocket cat says Hello')], 2)]], - ['## He said Hello to her', [heading([plain('He said Hello to her')], 2)]], - ['##Hello', [paragraph([plain('##Hello')])]], - ['##Hello##', [paragraph([plain('##Hello##')])]], - ['He##llo', [paragraph([plain('He##llo')])]], + ['## Hello', [heading([plain('Hello')], 2)]], + ['## Rocket.Cat', [heading([plain('Rocket.Cat')], 2)]], + ['## Hi', [heading([plain('Hi')], 2)]], + ['## Hello this is dog', [heading([plain('Hello this is dog')], 2)]], + ['## Rocket cat says Hello', [heading([plain('Rocket cat says Hello')], 2)]], + ['## He said Hello to her', [heading([plain('He said Hello to her')], 2)]], + ['##Hello', [paragraph([plain('##Hello')])]], + ['##Hello##', [paragraph([plain('##Hello##')])]], + ['He##llo', [paragraph([plain('He##llo')])]], - ['### Hello', [heading([plain('Hello')], 3)]], - ['### Rocket.Cat', [heading([plain('Rocket.Cat')], 3)]], - ['### Hi', [heading([plain('Hi')], 3)]], - ['### Hello this is dog', [heading([plain('Hello this is dog')], 3)]], - ['### Rocket cat says Hello', [heading([plain('Rocket cat says Hello')], 3)]], - ['### He said Hello to her', [heading([plain('He said Hello to her')], 3)]], - ['###Hello', [paragraph([plain('###Hello')])]], - ['###Hello###', [paragraph([plain('###Hello###')])]], - ['He###llo', [paragraph([plain('He###llo')])]], + ['### Hello', [heading([plain('Hello')], 3)]], + ['### Rocket.Cat', [heading([plain('Rocket.Cat')], 3)]], + ['### Hi', [heading([plain('Hi')], 3)]], + ['### Hello this is dog', [heading([plain('Hello this is dog')], 3)]], + ['### Rocket cat says Hello', [heading([plain('Rocket cat says Hello')], 3)]], + ['### He said Hello to her', [heading([plain('He said Hello to her')], 3)]], + ['###Hello', [paragraph([plain('###Hello')])]], + ['###Hello###', [paragraph([plain('###Hello###')])]], + ['He###llo', [paragraph([plain('He###llo')])]], - ['#### Hello', [heading([plain('Hello')], 4)]], - ['#### Rocket.Cat', [heading([plain('Rocket.Cat')], 4)]], - ['#### Hi', [heading([plain('Hi')], 4)]], - ['#### Hello this is dog', [heading([plain('Hello this is dog')], 4)]], - [ - '#### Rocket cat says Hello', - [heading([plain('Rocket cat says Hello')], 4)], - ], - ['#### He said Hello to her', [heading([plain('He said Hello to her')], 4)]], - ['####Hello', [paragraph([plain('####Hello')])]], - ['####Hello####', [paragraph([plain('####Hello####')])]], - ['He####llo', [paragraph([plain('He####llo')])]], - ['# Hello\n', [heading([plain('Hello')], 1), lineBreak()]], - ['# # Hello\n', [heading([plain('# Hello')], 1), lineBreak()]], + ['#### Hello', [heading([plain('Hello')], 4)]], + ['#### Rocket.Cat', [heading([plain('Rocket.Cat')], 4)]], + ['#### Hi', [heading([plain('Hi')], 4)]], + ['#### Hello this is dog', [heading([plain('Hello this is dog')], 4)]], + ['#### Rocket cat says Hello', [heading([plain('Rocket cat says Hello')], 4)]], + ['#### He said Hello to her', [heading([plain('He said Hello to her')], 4)]], + ['####Hello', [paragraph([plain('####Hello')])]], + ['####Hello####', [paragraph([plain('####Hello####')])]], + ['He####llo', [paragraph([plain('He####llo')])]], + ['# Hello\n', [heading([plain('Hello')], 1), lineBreak()]], + ['# # Hello\n', [heading([plain('# Hello')], 1), lineBreak()]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/image.test.ts b/packages/message-parser/tests/image.test.ts index a9e0306bbf2..c68c1f70fe6 100644 --- a/packages/message-parser/tests/image.test.ts +++ b/packages/message-parser/tests/image.test.ts @@ -2,18 +2,11 @@ import { parse } from '../src'; import { image, paragraph, plain } from '../src/utils'; test.each([ - [ - '![image](https://rocket.chat/assets/img/header/logo.svg)', - [ - paragraph([ - image('https://rocket.chat/assets/img/header/logo.svg', plain('image')), - ]), - ], - ], - [ - '![](https://rocket.chat/assets/img/header/logo.svg)', - [paragraph([image('https://rocket.chat/assets/img/header/logo.svg')])], - ], + [ + '![image](https://rocket.chat/assets/img/header/logo.svg)', + [paragraph([image('https://rocket.chat/assets/img/header/logo.svg', plain('image'))])], + ], + ['![](https://rocket.chat/assets/img/header/logo.svg)', [paragraph([image('https://rocket.chat/assets/img/header/logo.svg')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/inlineCode.test.ts b/packages/message-parser/tests/inlineCode.test.ts index 72d86adcff3..457bc16e188 100644 --- a/packages/message-parser/tests/inlineCode.test.ts +++ b/packages/message-parser/tests/inlineCode.test.ts @@ -2,26 +2,11 @@ import { parse } from '../src'; import { inlineCode, paragraph, plain } from '../src/utils'; test.each([ - [ - '`[asd](https://localhost)`', - [paragraph([inlineCode(plain('[asd](https://localhost)'))])], - ], - [`\`code\``, [paragraph([inlineCode(plain('code'))])]], - [ - `File extension (\`.mov\`)`, - [ - paragraph([ - plain('File extension ('), - inlineCode(plain('.mov')), - plain(')'), - ]), - ], - ], - ['`@rocket.chat`', [paragraph([inlineCode(plain('@rocket.chat'))])]], - [ - '`@rocket.chat/message-parser`', - [paragraph([inlineCode(plain('@rocket.chat/message-parser'))])], - ], + ['`[asd](https://localhost)`', [paragraph([inlineCode(plain('[asd](https://localhost)'))])]], + [`\`code\``, [paragraph([inlineCode(plain('code'))])]], + [`File extension (\`.mov\`)`, [paragraph([plain('File extension ('), inlineCode(plain('.mov')), plain(')')])]], + ['`@rocket.chat`', [paragraph([inlineCode(plain('@rocket.chat'))])]], + ['`@rocket.chat/message-parser`', [paragraph([inlineCode(plain('@rocket.chat/message-parser'))])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/inlineCodeStrike.test.ts b/packages/message-parser/tests/inlineCodeStrike.test.ts index cdd3e039cd2..84d82f7e4e4 100644 --- a/packages/message-parser/tests/inlineCodeStrike.test.ts +++ b/packages/message-parser/tests/inlineCodeStrike.test.ts @@ -1,46 +1,14 @@ import { parse } from '../src'; -import { - bold, - inlineCode, - italic, - paragraph, - plain, - strike, -} from '../src/utils'; +import { bold, inlineCode, italic, paragraph, plain, strike } from '../src/utils'; test.each([ - [ - '~~`Striking Inline Code`~~', - [paragraph([strike([inlineCode(plain('Striking Inline Code'))])])], - ], - [ - '~~_`Striking Inline Code with Italics`_~~', - [ - paragraph([ - strike([ - italic([inlineCode(plain('Striking Inline Code with Italics'))]), - ]), - ]), - ], - ], - [ - '~~**`Striking Inline Code with Bold`**~~', - [ - paragraph([ - strike([bold([inlineCode(plain('Striking Inline Code with Bold'))])]), - ]), - ], - ], - [ - '~~__*`Striking Inline Code with Bold`*__~~', - [ - paragraph([ - strike([ - italic([bold([inlineCode(plain('Striking Inline Code with Bold'))])]), - ]), - ]), - ], - ], + ['~~`Striking Inline Code`~~', [paragraph([strike([inlineCode(plain('Striking Inline Code'))])])]], + ['~~_`Striking Inline Code with Italics`_~~', [paragraph([strike([italic([inlineCode(plain('Striking Inline Code with Italics'))])])])]], + ['~~**`Striking Inline Code with Bold`**~~', [paragraph([strike([bold([inlineCode(plain('Striking Inline Code with Bold'))])])])]], + [ + '~~__*`Striking Inline Code with Bold`*__~~', + [paragraph([strike([italic([bold([inlineCode(plain('Striking Inline Code with Bold'))])])])])], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/katex.test.ts b/packages/message-parser/tests/katex.test.ts index 581e848f225..10bb47243de 100644 --- a/packages/message-parser/tests/katex.test.ts +++ b/packages/message-parser/tests/katex.test.ts @@ -2,32 +2,21 @@ import { parse } from '../src'; import { inlineKatex, katex, paragraph, plain } from '../src/utils'; test.each([ - [ - `\\[ + [ + `\\[ \\f\\relax{x} = \\int_{-\\infty}^\\infty \\f\\hat\\xi\\,e^{2 \\pi i \\xi x} \\,d\\xi \\]`, - [ - katex(` + [ + katex(` \\f\\relax{x} = \\int_{-\\infty}^\\infty \\f\\hat\\xi\\,e^{2 \\pi i \\xi x} \\,d\\xi `), - ], - ], - [ - 'Easy as \\(E = mc^2\\), right?', - [ - paragraph([ - plain('Easy as '), - inlineKatex('E = mc^2'), - plain(', right?'), - ]), - ], - ], + ], + ], + ['Easy as \\(E = mc^2\\), right?', [paragraph([plain('Easy as '), inlineKatex('E = mc^2'), plain(', right?')])]], ])('parses %p', (input, output) => { - expect(parse(input, { katex: { parenthesisSyntax: true } })).toMatchObject( - output, - ); + expect(parse(input, { katex: { parenthesisSyntax: true } })).toMatchObject(output); }); diff --git a/packages/message-parser/tests/lineBreak.test.ts b/packages/message-parser/tests/lineBreak.test.ts index e4faf67b17f..082cf7b5485 100644 --- a/packages/message-parser/tests/lineBreak.test.ts +++ b/packages/message-parser/tests/lineBreak.test.ts @@ -2,34 +2,28 @@ import { parse } from '../src'; import { lineBreak, paragraph, plain } from '../src/utils'; test.each([ - [ - `test + [ + `test test2`, - [paragraph([plain('test')]), lineBreak(), paragraph([plain('test2')])], - ], - [ - `test + [paragraph([plain('test')]), lineBreak(), paragraph([plain('test2')])], + ], + [ + `test test2 `, - [paragraph([plain('test')]), lineBreak(), paragraph([plain('test2')])], - ], - [ - `test + [paragraph([plain('test')]), lineBreak(), paragraph([plain('test2')])], + ], + [ + `test test2 `, - [ - paragraph([plain('test')]), - lineBreak(), - lineBreak(), - lineBreak(), - paragraph([plain('test2')]), - ], - ], + [paragraph([plain('test')]), lineBreak(), lineBreak(), lineBreak(), paragraph([plain('test2')])], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/link.test.ts b/packages/message-parser/tests/link.test.ts index c5f880b84e0..f90ab1629b7 100644 --- a/packages/message-parser/tests/link.test.ts +++ b/packages/message-parser/tests/link.test.ts @@ -1,613 +1,390 @@ import { parse } from '../src'; -import { - link, - paragraph, - plain, - bold, - strike, - italic, - quote, - lineBreak, - unorderedList, - listItem, - orderedList, -} from '../src/utils'; +import { link, paragraph, plain, bold, strike, italic, quote, lineBreak, unorderedList, listItem, orderedList } from '../src/utils'; test.each([ - [ - '', - [paragraph([link('https://domain.com', [plain('Test')])])], - ], + ['', [paragraph([link('https://domain.com', [plain('Test')])])]], - [ - ``, - [paragraph([plain('')])], - ], - [ - `')])], + ], + [ + ` quote here`, - [ - paragraph([plain('', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [plain('Test')], - ), - ]), - ], - ], - [ - '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [plain('title')], - ), - ]), - ], - ], - [ - '[**title**](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [bold([plain('title')])], - ), - ]), - ], - ], - [ - '[~~title~~](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [strike([plain('title')])], - ), - ]), - ], - ], - [ - '[__title__](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [italic([plain('title')])], - ), - ]), - ], - ], - [ - '[__**~~title~~**__](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [italic([bold([strike([plain('title')])])])], - ), - ]), - ], - ], - [ - '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34', - [plain('title')], - ), - ]), - ], - ], - [ - '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do?query=test12-34#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do?query=test12-34#Cases/dv/413244000073043351', - [plain('title')], - ), - ]), - ], - ], - [ - '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abc123)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abc123', - [plain('title')], - ), - ]), - ], - ], - [ - '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases?query=test12-34&query2=abcd!e/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases?query=test12-34&query2=abcd!e/dv/413244000073043351', - [plain('title')], - ), - ]), - ], - ], - [ - '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abcd!~-._%2B+)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abcd!~-._%2B+', - [plain('title')], - ), - ]), - ], - ], - ['google.com', [paragraph([link('//google.com', [plain('google.com')])])]], - [ - 'www.google.com', - [paragraph([link('//www.google.com', [plain('www.google.com')])])], - ], - ['rocket.chat:8080', [paragraph([link('rocket.chat:8080')])]], - ['ShouldNotBeALink', [paragraph([plain('ShouldNotBeALink')])]], - [ - 'http:/ google.com', - [ - paragraph([ - plain('http:/ '), - link('//google.com', [plain('google.com')]), - ]), - ], - ], - [ - '[custom](custom://google.com)', - [paragraph([link('custom://google.com', [plain('custom')])])], - ], - [ - '[thing](https://www.thingiverse.com/thing:5451684)', - [ - paragraph([ - link('https://www.thingiverse.com/thing:5451684', [plain('thing')]), - ]), - ], - ], - [ - 'https://t.me/joinchat/chatexample', - [paragraph([link('https://t.me/joinchat/chatexample')])], - ], - [ - '[telegram invite](https://t.me/joinchat/chatexample)', - [ - paragraph([ - link('https://t.me/joinchat/chatexample', [plain('telegram invite')]), - ]), - ], - ], - [ - '[Github link with hash](https://github.com/RocketChat/Rocket.Chat/pull/26751/files#diff-c87b108ecf1ede549f8ede68eca840fbb330180b927df0b8a0b4df5d06cbd89b)', - [ - paragraph([ - link( - 'https://github.com/RocketChat/Rocket.Chat/pull/26751/files#diff-c87b108ecf1ede549f8ede68eca840fbb330180b927df0b8a0b4df5d06cbd89b', - [plain('Github link with hash')], - ), - ]), - ], - ], - [ - '[Github link with hash](https://github.com/RocketChat/Rocket.Chat/pull/26751/files#diff)', - [ - paragraph([ - link( - 'https://github.com/RocketChat/Rocket.Chat/pull/26751/files#diff', - [plain('Github link with hash')], - ), - ]), - ], - ], - [ - '[Github link without hash](https://github.com/RocketChat/Rocket.Chat/pull/26751/files)', - [ - paragraph([ - link('https://github.com/RocketChat/Rocket.Chat/pull/26751/files', [ - plain('Github link without hash'), - ]), - ]), - ], - ], - [ - '[Link with special chars](https://github.com/RocketChat/Rocket.Chat*[/]^_`{}~)', - [ - paragraph([ - link('https://github.com/RocketChat/Rocket.Chat*[/]^_`{}~', [ - plain('Link with special chars'), - ]), - ]), - ], - ], - [ - '[Google complex Link](https://www.google.com/url?rct=j&sa=t&url=https://ga.de/freizeit/region-erleben/bonn-und-region-tipps-fuers-wochenende-flohmarkt-rheinaue-weltkindertag-stadtfest_aid-53876987&ct=ga&cd=CAIyHDQ0NzEyYWE3MDA1MGNhNTQ6Y29tOmRlOkRFOlI&usg=AOvVaw3ySYrO9lM0iNSnk43gPVwZ)', - [ - paragraph([ - link( - 'https://www.google.com/url?rct=j&sa=t&url=https://ga.de/freizeit/region-erleben/bonn-und-region-tipps-fuers-wochenende-flohmarkt-rheinaue-weltkindertag-stadtfest_aid-53876987&ct=ga&cd=CAIyHDQ0NzEyYWE3MDA1MGNhNTQ6Y29tOmRlOkRFOlI&usg=AOvVaw3ySYrO9lM0iNSnk43gPVwZ', - [plain('Google complex Link')], - ), - ]), - ], - ], - [ - '[Rocket.Chat](https://rocket.chat) Inline Text', - [ - paragraph([ - link('https://rocket.chat', [plain('Rocket.Chat')]), - plain(' Inline Text'), - ]), - ], - ], - [ - 'https://analytics.zoho.com/open-view/123456789 Same Line', - [ - paragraph([ - link('https://analytics.zoho.com/open-view/123456789', [ - plain('https://analytics.zoho.com/open-view/123456789'), - ]), - plain(' Same Line'), - ]), - ], - ], - [ - `[Rocket.Chat](https://rocket.chat) + ['[ test](https://rocket.chat)', [paragraph([link('https://rocket.chat', [plain(' test')])])]], + ['[ test ](https://rocket.chat)', [paragraph([link('https://rocket.chat', [plain(' test ')])])]], + ['[title](https://rocket.chat)', [paragraph([link('https://rocket.chat', [plain('title')])])]], + ['[title](http://localhost)', [paragraph([link('http://localhost', [plain('title')])])]], + ['[title](http://localhost?testing=true)', [paragraph([link('http://localhost?testing=true', [plain('title')])])]], + ['[**title**](https://rocket.chat)', [paragraph([link('https://rocket.chat', [bold([plain('title')])])])]], + ['[~~title~~](https://rocket.chat)', [paragraph([link('https://rocket.chat', [strike([plain('title')])])])]], + ['[__title__](https://rocket.chat)', [paragraph([link('https://rocket.chat', [italic([plain('title')])])])]], + ['[__**~~title~~**__](https://rocket.chat)', [paragraph([link('https://rocket.chat', [italic([bold([strike([plain('title')])])])])])]], + [ + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', + [paragraph([link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351')])], + ], + [ + '', + [paragraph([link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [plain('Test')])])], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [paragraph([link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [plain('title')])])], + ], + [ + '[**title**](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [bold([plain('title')])]), + ]), + ], + ], + [ + '[~~title~~](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [strike([plain('title')])]), + ]), + ], + ], + [ + '[__title__](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [italic([plain('title')])]), + ]), + ], + ], + [ + '[__**~~title~~**__](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [ + italic([bold([strike([plain('title')])])]), + ]), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34', [plain('title')]), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do?query=test12-34#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do?query=test12-34#Cases/dv/413244000073043351', [plain('title')]), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abc123)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abc123', [ + plain('title'), + ]), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases?query=test12-34&query2=abcd!e/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases?query=test12-34&query2=abcd!e/dv/413244000073043351', [ + plain('title'), + ]), + ]), + ], + ], + [ + '[title](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abcd!~-._%2B+)', + [ + paragraph([ + link( + 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351?query=test12-34&query2=abcd!~-._%2B+', + [plain('title')], + ), + ]), + ], + ], + ['google.com', [paragraph([link('//google.com', [plain('google.com')])])]], + ['www.google.com', [paragraph([link('//www.google.com', [plain('www.google.com')])])]], + ['rocket.chat:8080', [paragraph([link('rocket.chat:8080')])]], + ['ShouldNotBeALink', [paragraph([plain('ShouldNotBeALink')])]], + ['http:/ google.com', [paragraph([plain('http:/ '), link('//google.com', [plain('google.com')])])]], + ['[custom](custom://google.com)', [paragraph([link('custom://google.com', [plain('custom')])])]], + [ + '[thing](https://www.thingiverse.com/thing:5451684)', + [paragraph([link('https://www.thingiverse.com/thing:5451684', [plain('thing')])])], + ], + ['https://t.me/joinchat/chatexample', [paragraph([link('https://t.me/joinchat/chatexample')])]], + [ + '[telegram invite](https://t.me/joinchat/chatexample)', + [paragraph([link('https://t.me/joinchat/chatexample', [plain('telegram invite')])])], + ], + [ + '[Github link with hash](https://github.com/RocketChat/Rocket.Chat/pull/26751/files#diff-c87b108ecf1ede549f8ede68eca840fbb330180b927df0b8a0b4df5d06cbd89b)', + [ + paragraph([ + link( + 'https://github.com/RocketChat/Rocket.Chat/pull/26751/files#diff-c87b108ecf1ede549f8ede68eca840fbb330180b927df0b8a0b4df5d06cbd89b', + [plain('Github link with hash')], + ), + ]), + ], + ], + [ + '[Github link with hash](https://github.com/RocketChat/Rocket.Chat/pull/26751/files#diff)', + [paragraph([link('https://github.com/RocketChat/Rocket.Chat/pull/26751/files#diff', [plain('Github link with hash')])])], + ], + [ + '[Github link without hash](https://github.com/RocketChat/Rocket.Chat/pull/26751/files)', + [paragraph([link('https://github.com/RocketChat/Rocket.Chat/pull/26751/files', [plain('Github link without hash')])])], + ], + [ + '[Link with special chars](https://github.com/RocketChat/Rocket.Chat*[/]^_`{}~)', + [paragraph([link('https://github.com/RocketChat/Rocket.Chat*[/]^_`{}~', [plain('Link with special chars')])])], + ], + [ + '[Google complex Link](https://www.google.com/url?rct=j&sa=t&url=https://ga.de/freizeit/region-erleben/bonn-und-region-tipps-fuers-wochenende-flohmarkt-rheinaue-weltkindertag-stadtfest_aid-53876987&ct=ga&cd=CAIyHDQ0NzEyYWE3MDA1MGNhNTQ6Y29tOmRlOkRFOlI&usg=AOvVaw3ySYrO9lM0iNSnk43gPVwZ)', + [ + paragraph([ + link( + 'https://www.google.com/url?rct=j&sa=t&url=https://ga.de/freizeit/region-erleben/bonn-und-region-tipps-fuers-wochenende-flohmarkt-rheinaue-weltkindertag-stadtfest_aid-53876987&ct=ga&cd=CAIyHDQ0NzEyYWE3MDA1MGNhNTQ6Y29tOmRlOkRFOlI&usg=AOvVaw3ySYrO9lM0iNSnk43gPVwZ', + [plain('Google complex Link')], + ), + ]), + ], + ], + [ + '[Rocket.Chat](https://rocket.chat) Inline Text', + [paragraph([link('https://rocket.chat', [plain('Rocket.Chat')]), plain(' Inline Text')])], + ], + [ + 'https://analytics.zoho.com/open-view/123456789 Same Line', + [ + paragraph([ + link('https://analytics.zoho.com/open-view/123456789', [plain('https://analytics.zoho.com/open-view/123456789')]), + plain(' Same Line'), + ]), + ], + ], + [ + `[Rocket.Chat](https://rocket.chat) Text after in a new line after link`, - [ - paragraph([link('https://rocket.chat', [plain('Rocket.Chat')])]), - paragraph([plain('Text after in a new line after link')]), - ], - ], - [ - `https://analytics.zoho.com/open-view/123456789 + [paragraph([link('https://rocket.chat', [plain('Rocket.Chat')])]), paragraph([plain('Text after in a new line after link')])], + ], + [ + `https://analytics.zoho.com/open-view/123456789 Second line`, - [ - paragraph([ - link('https://analytics.zoho.com/open-view/123456789', [ - plain('https://analytics.zoho.com/open-view/123456789'), - ]), - ]), - paragraph([plain('Second line')]), - ], - ], - [ - `[Rocket.Chat](https://rocket.chat) + [ + paragraph([link('https://analytics.zoho.com/open-view/123456789', [plain('https://analytics.zoho.com/open-view/123456789')])]), + paragraph([plain('Second line')]), + ], + ], + [ + `[Rocket.Chat](https://rocket.chat) Text after line break`, - [ - paragraph([link('https://rocket.chat', [plain('Rocket.Chat')])]), - lineBreak(), - paragraph([plain('Text after line break')]), - ], - ], - [ - ` + [paragraph([link('https://rocket.chat', [plain('Rocket.Chat')])]), lineBreak(), paragraph([plain('Text after line break')])], + ], + [ + ` [List Header Link](https://rocket.chat) - First item - Second item - Third item - *Fourth item* `.trim(), - [ - paragraph([link('https://rocket.chat', [plain('List Header Link')])]), - unorderedList([ - listItem([plain('First item')]), - listItem([plain('Second item')]), - listItem([plain('Third item')]), - listItem([bold([plain('Fourth item')])]), - ]), - ], - ], - [ - `[List Header Link](https://rocket.chat) + [ + paragraph([link('https://rocket.chat', [plain('List Header Link')])]), + unorderedList([ + listItem([plain('First item')]), + listItem([plain('Second item')]), + listItem([plain('Third item')]), + listItem([bold([plain('Fourth item')])]), + ]), + ], + ], + [ + `[List Header Link](https://rocket.chat) 7. First item 2. Second item 8. Third item 4. *Fourth item* 15. *Fifteenth item* `.trim(), - [ - paragraph([link('https://rocket.chat', [plain('List Header Link')])]), - orderedList([ - listItem([plain('First item')], 7), - listItem([plain('Second item')], 2), - listItem([plain('Third item')], 8), - listItem([bold([plain('Fourth item')])], 4), - listItem([bold([plain('Fifteenth item')])], 15), - ]), - ], - ], - [ - '[9gag](https://9gag.com/)', - [paragraph([link('https://9gag.com/', [plain('9gag')])])], - ], - ['[9gag](9gag.com)', [paragraph([link('9gag.com', [plain('9gag')])])]], - ['<9gag.com|9gag>', [paragraph([link('9gag.com', [plain('9gag')])])]], - ['9gag.com', [paragraph([link('//9gag.com', [plain('9gag.com')])])]], - [ - '[notes link](notes://Server/C3257116002CAD60/0/CCAF6BE2824A1F49432588D2001FA73E)', - [ - paragraph([ - link( - 'notes://Server/C3257116002CAD60/0/CCAF6BE2824A1F49432588D2001FA73E', - [plain('notes link')], - ), - ]), - ], - ], - [ - '[File Path](C:/Users/user1/Documents/projects/file.js)', - [ - paragraph([ - link('C:/Users/user1/Documents/projects/file.js', [plain('File Path')]), - ]), - ], - ], - [ - '[Test with **bold** element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [plain('Test with '), bold([plain('bold')]), plain(' element')], - ), - ]), - ], - ], - [ - '[Test with *bold* element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [plain('Test with '), bold([plain('bold')]), plain(' element')], - ), - ]), - ], - ], - [ - '[Test with _italic_ element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [plain('Test with '), italic([plain('italic')]), plain(' element')], - ), - ]), - ], - ], - [ - '[Test with ~strike~ element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [plain('Test with '), strike([plain('strike')]), plain(' element')], - ), - ]), - ], - ], - [ - '[Test with __**~~title~~**__ element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', - [ - paragraph([ - link( - 'https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', - [ - plain('Test with '), - italic([bold([strike([plain('title')])])]), - plain(' element'), - ], - ), - ]), - ], - ], - [ - '([Github Issue: #24929](https://github.com/RocketChat/Rocket.Chat/issues/24929))', - [ - paragraph([ - plain('('), - link('https://github.com/RocketChat/Rocket.Chat/issues/24929', [ - plain('Github Issue: #24929'), - ]), - plain(')'), - ]), - ], - ], - [ - 'the [audio_url and video_url for post message attachments](https://developer.rocket.chat/reference/api/rest-api/endpoints/core-endpoints/chat-endpoints/postmessage)', - [ - paragraph([ - plain('the '), - link( - 'https://developer.rocket.chat/reference/api/rest-api/endpoints/core-endpoints/chat-endpoints/postmessage', - [plain('audio_url and video_url for post message attachments')], - ), - ]), - ], - ], - [ - 'the [Jira [Task] parentheses not working](rocket.chat)', - [ - paragraph([ - plain('the '), - link('rocket.chat', [plain('Jira [Task] parentheses not working')]), - ]), - ], - ], - [ - 'the [Jira (Task) parentheses not working](rocket.chat)', - [ - paragraph([ - plain('the '), - link('rocket.chat', [plain('Jira (Task) parentheses not working')]), - ]), - ], - ], - [ - '[Jira [Task] parentheses not working](rocket.chat)', - [ - paragraph([ - link('rocket.chat', [plain('Jira [Task] parentheses not working')]), - ]), - ], - ], - [ - '[Jira (Task) parentheses not working](rocket.chat)', - [ - paragraph([ - link('rocket.chat', [plain('Jira (Task) parentheses not working')]), - ]), - ], - ], - // Should not parse as link - ['77.77%', [paragraph([plain('77.77%')])]], - ['77.77', [paragraph([plain('77.77')])]], - ['https://77.77', [paragraph([plain('https://77.77')])]], - ['test.9gag', [paragraph([plain('test.9gag')])]], - [ - '[here](https://github.com/RocketChat/Rocket.Chat/releases/tag/6.0.0-rc.3)', - [ - paragraph([ - link( - 'https://github.com/RocketChat/Rocket.Chat/releases/tag/6.0.0-rc.3', - [plain('here')], - ), - ]), - ], - ], - [ - '[ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [test](https://rocket.chat)', - [ - paragraph([ - link('https://rocket.chat', [ - plain(' '), - strike([plain(' [ ')]), - plain(' [ '), - strike([plain(' [ ')]), - plain(' [ '), - strike([plain(' [ ')]), - plain(' [ '), - strike([plain(' [ ')]), - plain(' [ '), - strike([plain(' [ ')]), - plain(' [ '), - strike([plain(' [ ')]), - plain(' [ '), - strike([plain(' [ ')]), - plain(' [test'), - ]), - ]), - ], - ], - [ - '[test **bold** and __italic__](https://rocket.chat)', - [ - paragraph([ - link('https://rocket.chat', [ - plain('test '), - bold([plain('bold')]), - plain(' and '), - italic([plain('italic')]), - ]), - ]), - ], - ], - [ - '[test **bold with __italic__**](https://rocket.chat)', - [ - paragraph([ - link('https://rocket.chat', [ - plain('test '), - bold([plain('bold with '), italic([plain('italic')])]), - ]), - ]), - ], - ], + [ + paragraph([link('https://rocket.chat', [plain('List Header Link')])]), + orderedList([ + listItem([plain('First item')], 7), + listItem([plain('Second item')], 2), + listItem([plain('Third item')], 8), + listItem([bold([plain('Fourth item')])], 4), + listItem([bold([plain('Fifteenth item')])], 15), + ]), + ], + ], + ['[9gag](https://9gag.com/)', [paragraph([link('https://9gag.com/', [plain('9gag')])])]], + ['[9gag](9gag.com)', [paragraph([link('9gag.com', [plain('9gag')])])]], + ['<9gag.com|9gag>', [paragraph([link('9gag.com', [plain('9gag')])])]], + ['9gag.com', [paragraph([link('//9gag.com', [plain('9gag.com')])])]], + [ + '[notes link](notes://Server/C3257116002CAD60/0/CCAF6BE2824A1F49432588D2001FA73E)', + [paragraph([link('notes://Server/C3257116002CAD60/0/CCAF6BE2824A1F49432588D2001FA73E', [plain('notes link')])])], + ], + [ + '[File Path](C:/Users/user1/Documents/projects/file.js)', + [paragraph([link('C:/Users/user1/Documents/projects/file.js', [plain('File Path')])])], + ], + [ + '[Test with **bold** element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [ + plain('Test with '), + bold([plain('bold')]), + plain(' element'), + ]), + ]), + ], + ], + [ + '[Test with *bold* element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [ + plain('Test with '), + bold([plain('bold')]), + plain(' element'), + ]), + ]), + ], + ], + [ + '[Test with _italic_ element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [ + plain('Test with '), + italic([plain('italic')]), + plain(' element'), + ]), + ]), + ], + ], + [ + '[Test with ~strike~ element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [ + plain('Test with '), + strike([plain('strike')]), + plain(' element'), + ]), + ]), + ], + ], + [ + '[Test with __**~~title~~**__ element](https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351)', + [ + paragraph([ + link('https://desk.rocket.chat/support/rocketchat/ShowHomePage.do#Cases/dv/413244000073043351', [ + plain('Test with '), + italic([bold([strike([plain('title')])])]), + plain(' element'), + ]), + ]), + ], + ], + [ + '([Github Issue: #24929](https://github.com/RocketChat/Rocket.Chat/issues/24929))', + [paragraph([plain('('), link('https://github.com/RocketChat/Rocket.Chat/issues/24929', [plain('Github Issue: #24929')]), plain(')')])], + ], + [ + 'the [audio_url and video_url for post message attachments](https://developer.rocket.chat/reference/api/rest-api/endpoints/core-endpoints/chat-endpoints/postmessage)', + [ + paragraph([ + plain('the '), + link('https://developer.rocket.chat/reference/api/rest-api/endpoints/core-endpoints/chat-endpoints/postmessage', [ + plain('audio_url and video_url for post message attachments'), + ]), + ]), + ], + ], + [ + 'the [Jira [Task] parentheses not working](rocket.chat)', + [paragraph([plain('the '), link('rocket.chat', [plain('Jira [Task] parentheses not working')])])], + ], + [ + 'the [Jira (Task) parentheses not working](rocket.chat)', + [paragraph([plain('the '), link('rocket.chat', [plain('Jira (Task) parentheses not working')])])], + ], + [ + '[Jira [Task] parentheses not working](rocket.chat)', + [paragraph([link('rocket.chat', [plain('Jira [Task] parentheses not working')])])], + ], + [ + '[Jira (Task) parentheses not working](rocket.chat)', + [paragraph([link('rocket.chat', [plain('Jira (Task) parentheses not working')])])], + ], + // Should not parse as link + ['77.77%', [paragraph([plain('77.77%')])]], + ['77.77', [paragraph([plain('77.77')])]], + ['https://77.77', [paragraph([plain('https://77.77')])]], + ['test.9gag', [paragraph([plain('test.9gag')])]], + [ + '[here](https://github.com/RocketChat/Rocket.Chat/releases/tag/6.0.0-rc.3)', + [paragraph([link('https://github.com/RocketChat/Rocket.Chat/releases/tag/6.0.0-rc.3', [plain('here')])])], + ], + [ + '[ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [ ~ [test](https://rocket.chat)', + [ + paragraph([ + link('https://rocket.chat', [ + plain(' '), + strike([plain(' [ ')]), + plain(' [ '), + strike([plain(' [ ')]), + plain(' [ '), + strike([plain(' [ ')]), + plain(' [ '), + strike([plain(' [ ')]), + plain(' [ '), + strike([plain(' [ ')]), + plain(' [ '), + strike([plain(' [ ')]), + plain(' [ '), + strike([plain(' [ ')]), + plain(' [test'), + ]), + ]), + ], + ], + [ + '[test **bold** and __italic__](https://rocket.chat)', + [paragraph([link('https://rocket.chat', [plain('test '), bold([plain('bold')]), plain(' and '), italic([plain('italic')])])])], + ], + [ + '[test **bold with __italic__**](https://rocket.chat)', + [paragraph([link('https://rocket.chat', [plain('test '), bold([plain('bold with '), italic([plain('italic')])])])])], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/mention.test.ts b/packages/message-parser/tests/mention.test.ts index 5a86d5587ac..77a64d50494 100644 --- a/packages/message-parser/tests/mention.test.ts +++ b/packages/message-parser/tests/mention.test.ts @@ -2,33 +2,21 @@ import { parse } from '../src'; import { paragraph, plain, mentionUser, mentionChannel } from '../src/utils'; test.each([ - ['@guilherme.gazzo', [paragraph([mentionUser('guilherme.gazzo')])]], - [ - '@guilherme.gazzo. ', - [paragraph([mentionUser('guilherme.gazzo.'), plain(' ')])], - ], - ['#GENERAL', [paragraph([mentionChannel('GENERAL')])]], - ['@user:server.com', [paragraph([mentionUser('user:server.com')])]], - [ - '@marcos.defendi:matrix.org', - [paragraph([mentionUser('marcos.defendi:matrix.org')])], - ], - ['@username@example.com', [paragraph([mentionUser('username@example.com')])]], - [ - '@099fnd2ee@example.com', - [paragraph([mentionUser('099fnd2ee@example.com')])], - ], - ['@téstãçâò', [paragraph([mentionUser('téstãçâò')])]], - ['@สมชาย', [paragraph([mentionUser('สมชาย')])]], - ['@李祖阳', [paragraph([mentionUser('李祖阳')])]], - ['@あおい', [paragraph([mentionUser('あおい')])]], - ['@アオイ', [paragraph([mentionUser('アオイ')])]], - ['@Владимир', [paragraph([mentionUser('Владимир')])]], - ['@Кириллица', [paragraph([mentionUser('Кириллица')])]], - [ - 'test @Кириллица test', - [paragraph([plain('test '), mentionUser('Кириллица'), plain(' test')])], - ], + ['@guilherme.gazzo', [paragraph([mentionUser('guilherme.gazzo')])]], + ['@guilherme.gazzo. ', [paragraph([mentionUser('guilherme.gazzo.'), plain(' ')])]], + ['#GENERAL', [paragraph([mentionChannel('GENERAL')])]], + ['@user:server.com', [paragraph([mentionUser('user:server.com')])]], + ['@marcos.defendi:matrix.org', [paragraph([mentionUser('marcos.defendi:matrix.org')])]], + ['@username@example.com', [paragraph([mentionUser('username@example.com')])]], + ['@099fnd2ee@example.com', [paragraph([mentionUser('099fnd2ee@example.com')])]], + ['@téstãçâò', [paragraph([mentionUser('téstãçâò')])]], + ['@สมชาย', [paragraph([mentionUser('สมชาย')])]], + ['@李祖阳', [paragraph([mentionUser('李祖阳')])]], + ['@あおい', [paragraph([mentionUser('あおい')])]], + ['@アオイ', [paragraph([mentionUser('アオイ')])]], + ['@Владимир', [paragraph([mentionUser('Владимир')])]], + ['@Кириллица', [paragraph([mentionUser('Кириллица')])]], + ['test @Кириллица test', [paragraph([plain('test '), mentionUser('Кириллица'), plain(' test')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/orderedList.test.ts b/packages/message-parser/tests/orderedList.test.ts index 26434ccd781..e7a453d32ad 100644 --- a/packages/message-parser/tests/orderedList.test.ts +++ b/packages/message-parser/tests/orderedList.test.ts @@ -2,8 +2,8 @@ import { parse } from '../src'; import { bold, plain, orderedList, listItem, emoji } from '../src/utils'; test.each([ - [ - ` + [ + ` 7. First item 2. Second item 8. Third item @@ -11,17 +11,17 @@ test.each([ 15. *Fifteenth item* 20. :smile: `.trim(), - [ - orderedList([ - listItem([plain('First item')], 7), - listItem([plain('Second item')], 2), - listItem([plain('Third item')], 8), - listItem([bold([plain('Fourth item')])], 4), - listItem([bold([plain('Fifteenth item')])], 15), - listItem([emoji('smile')], 20), - ]), - ], - ], + [ + orderedList([ + listItem([plain('First item')], 7), + listItem([plain('Second item')], 2), + listItem([plain('Third item')], 8), + listItem([bold([plain('Fourth item')])], 4), + listItem([bold([plain('Fifteenth item')])], 15), + listItem([emoji('smile')], 20), + ]), + ], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/phoneNumber.test.ts b/packages/message-parser/tests/phoneNumber.test.ts index 781bae3fcfe..f9faade94b6 100644 --- a/packages/message-parser/tests/phoneNumber.test.ts +++ b/packages/message-parser/tests/phoneNumber.test.ts @@ -2,62 +2,25 @@ import { parse } from '../src'; import { link, paragraph, plain, bold } from '../src/utils'; test.each([ - [ - '+07563546725', - [paragraph([link('tel:07563546725', [plain('+07563546725')])])], - ], - [ - '+075-63546725', - [paragraph([link('tel:07563546725', [plain('+075-63546725')])])], - ], - [ - '+(075)-63546725', - [paragraph([link('tel:07563546725', [plain('+(075)-63546725')])])], - ], - [ - '+(075)63546725', - [paragraph([link('tel:07563546725', [plain('+(075)63546725')])])], - ], - [ - '[here](+(075)63546725)', - [paragraph([link('tel:07563546725', [plain('here')])])], - ], - [ - '[**here**](+(075)63546725)', - [paragraph([link('tel:07563546725', [bold([plain('here')])])])], - ], - [ - '[**here**](+(075)63546725)', - [paragraph([link('tel:07563546725', [bold([plain('here')])])])], - ], - [ - '+(11)99999-9999', - [paragraph([link('tel:11999999999', [plain('+(11)99999-9999')])])], - ], - [ - '5 +51231', - [paragraph([plain('5 '), link('tel:51231', [plain('+51231')])])], - ], - [ - '5 +51231 5', - [ - paragraph([ - plain('5 '), - link('tel:51231', [plain('+51231')]), - plain(' 5'), - ]), - ], - ], - ['+(12)3-45', [paragraph([link('tel:12345', [plain('+(12)3-45')])])]], - ['+1.599123', [paragraph([plain('+1.599123')])]], - ['1+1=2', [paragraph([plain('1+1=2')])]], - ['1+1=2 text', [paragraph([plain('1+1=2 text')])]], - ['+1000,00', [paragraph([plain('+1000,00')])]], - ['+ 1199999999', [paragraph([plain('+ 1199999999')])]], - ['+1234', [paragraph([plain('+1234')])]], - ['+(12)3-4', [paragraph([plain('+(12)3-4')])]], - ['+123-4', [paragraph([plain('+123-4')])]], - ['5+51231', [paragraph([plain('5+51231')])]], + ['+07563546725', [paragraph([link('tel:07563546725', [plain('+07563546725')])])]], + ['+075-63546725', [paragraph([link('tel:07563546725', [plain('+075-63546725')])])]], + ['+(075)-63546725', [paragraph([link('tel:07563546725', [plain('+(075)-63546725')])])]], + ['+(075)63546725', [paragraph([link('tel:07563546725', [plain('+(075)63546725')])])]], + ['[here](+(075)63546725)', [paragraph([link('tel:07563546725', [plain('here')])])]], + ['[**here**](+(075)63546725)', [paragraph([link('tel:07563546725', [bold([plain('here')])])])]], + ['+(11)99999-9999', [paragraph([link('tel:11999999999', [plain('+(11)99999-9999')])])]], + ['5 +51231', [paragraph([plain('5 '), link('tel:51231', [plain('+51231')])])]], + ['5 +51231 5', [paragraph([plain('5 '), link('tel:51231', [plain('+51231')]), plain(' 5')])]], + ['+(12)3-45', [paragraph([link('tel:12345', [plain('+(12)3-45')])])]], + ['+1.599123', [paragraph([plain('+1.599123')])]], + ['1+1=2', [paragraph([plain('1+1=2')])]], + ['1+1=2 text', [paragraph([plain('1+1=2 text')])]], + ['+1000,00', [paragraph([plain('+1000,00')])]], + ['+ 1199999999', [paragraph([plain('+ 1199999999')])]], + ['+1234', [paragraph([plain('+1234')])]], + ['+(12)3-4', [paragraph([plain('+(12)3-4')])]], + ['+123-4', [paragraph([plain('+123-4')])]], + ['5+51231', [paragraph([plain('5+51231')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/strikethrough.test.ts b/packages/message-parser/tests/strikethrough.test.ts index 36b3439168f..f8d9e2d1e45 100644 --- a/packages/message-parser/tests/strikethrough.test.ts +++ b/packages/message-parser/tests/strikethrough.test.ts @@ -1,122 +1,48 @@ import { parse } from '../src'; -import { - emoji, - emojiUnicode, - link, - mentionChannel, - mentionUser, - paragraph, - plain, - strike, -} from '../src/utils'; +import { emoji, emojiUnicode, link, mentionChannel, mentionUser, paragraph, plain, strike } from '../src/utils'; test.each([ - ['~:smile:~', [paragraph([strike([emoji('smile')])])]], - [ - '~test :smile: test~', - [paragraph([strike([plain('test '), emoji('smile'), plain(' test')])])], - ], - ['~😀~', [paragraph([strike([emojiUnicode('😀')])])]], - ['~test 😀~', [paragraph([strike([plain('test '), emojiUnicode('😀')])])]], - [ - '~@guilherme.gazzo~', - [paragraph([strike([mentionUser('guilherme.gazzo')])])], - ], - ['~#GENERAL~', [paragraph([strike([mentionChannel('GENERAL')])])]], - [ - '~test @guilherme.gazzo~', - [paragraph([strike([plain('test '), mentionUser('guilherme.gazzo')])])], - ], - [ - '~test #GENERAL~', - [paragraph([strike([plain('test '), mentionChannel('GENERAL')])])], - ], - [ - '~~[A brand new Gist](https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4)~~', - [ - paragraph([ - strike([ - link('https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4', [ - plain('A brand new Gist'), - ]), - ]), - ]), - ], - ], - ['~~strike~~', [paragraph([strike([plain('strike')])])]], - [ - 'pre~~strike~~post', - [paragraph([plain('pre'), strike([plain('strike')]), plain('post')])], - ], - [ - ' pre~~strike~~post ', - [paragraph([plain(' pre'), strike([plain('strike')]), plain('post ')])], - ], - ['~~', [paragraph([plain('~~')])]], - ['~ ~', [paragraph([plain('~ ~')])]], - ['~~ ~', [paragraph([plain('~~ ~')])]], - ['~~ ~~', [paragraph([plain('~~ ~~')])]], - ['~ Hello~', [paragraph([strike([plain(' Hello')])])]], - ['~Hello ~', [paragraph([strike([plain('Hello ')])])]], - [ - ':custom~emoji~case:', - [paragraph([plain(`:custom`), strike([plain('emoji')]), plain(`case:`)])], - ], - [ - 'text~hello~text', - [paragraph([plain(`text`), strike([plain('hello')]), plain(`text`)])], - ], - ['~hello~text', [paragraph([strike([plain('hello')]), plain(`text`)])]], - ['text~hello~', [paragraph([plain(`text`), strike([plain('hello')])])]], - ['~Hel lo~', [paragraph([strike([plain('Hel lo')])])]], - ['~Hello~', [paragraph([strike([plain('Hello')])])]], - ['~~Hello~~', [paragraph([strike([plain('Hello')])])]], - ['~~Hello~', [paragraph([plain(`~`), strike([plain('Hello')])])]], - ['~Hello~~', [paragraph([strike([plain('Hello')]), plain(`~`)])]], - ['~Hello', [paragraph([plain('~Hello')])]], - ['Hello~', [paragraph([plain('Hello~')])]], - ['He~llo', [paragraph([plain('He~llo')])]], - [ - '~~~Hello~~~', - [paragraph([plain(`~`), strike([plain('Hello')]), plain(`~`)])], - ], - ['~~~Hello~~', [paragraph([plain(`~`), strike([plain('Hello')])])]], - [ - '~Hello~ this is dog', - [paragraph([strike([plain('Hello')]), plain(` this is dog`)])], - ], - [ - 'Rocket cat says ~Hello~', - [paragraph([plain(`Rocket cat says `), strike([plain('Hello')])])], - ], - [ - 'He said ~Hello~ to her', - [ - paragraph([ - plain(`He said `), - strike([plain('Hello')]), - plain(` to her`), - ]), - ], - ], - [ - '~~Hello~~ this is dog', - [paragraph([strike([plain('Hello')]), plain(` this is dog`)])], - ], - [ - 'Rocket cat says ~~Hello~~', - [paragraph([plain(`Rocket cat says `), strike([plain('Hello')])])], - ], - [ - 'He said ~~Hello~~ to her', - [ - paragraph([ - plain(`He said `), - strike([plain('Hello')]), - plain(` to her`), - ]), - ], - ], + ['~:smile:~', [paragraph([strike([emoji('smile')])])]], + ['~test :smile: test~', [paragraph([strike([plain('test '), emoji('smile'), plain(' test')])])]], + ['~😀~', [paragraph([strike([emojiUnicode('😀')])])]], + ['~test 😀~', [paragraph([strike([plain('test '), emojiUnicode('😀')])])]], + ['~@guilherme.gazzo~', [paragraph([strike([mentionUser('guilherme.gazzo')])])]], + ['~#GENERAL~', [paragraph([strike([mentionChannel('GENERAL')])])]], + ['~test @guilherme.gazzo~', [paragraph([strike([plain('test '), mentionUser('guilherme.gazzo')])])]], + ['~test #GENERAL~', [paragraph([strike([plain('test '), mentionChannel('GENERAL')])])]], + [ + '~~[A brand new Gist](https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4)~~', + [paragraph([strike([link('https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4', [plain('A brand new Gist')])])])], + ], + ['~~strike~~', [paragraph([strike([plain('strike')])])]], + ['pre~~strike~~post', [paragraph([plain('pre'), strike([plain('strike')]), plain('post')])]], + [' pre~~strike~~post ', [paragraph([plain(' pre'), strike([plain('strike')]), plain('post ')])]], + ['~~', [paragraph([plain('~~')])]], + ['~ ~', [paragraph([plain('~ ~')])]], + ['~~ ~', [paragraph([plain('~~ ~')])]], + ['~~ ~~', [paragraph([plain('~~ ~~')])]], + ['~ Hello~', [paragraph([strike([plain(' Hello')])])]], + ['~Hello ~', [paragraph([strike([plain('Hello ')])])]], + [':custom~emoji~case:', [paragraph([plain(`:custom`), strike([plain('emoji')]), plain(`case:`)])]], + ['text~hello~text', [paragraph([plain(`text`), strike([plain('hello')]), plain(`text`)])]], + ['~hello~text', [paragraph([strike([plain('hello')]), plain(`text`)])]], + ['text~hello~', [paragraph([plain(`text`), strike([plain('hello')])])]], + ['~Hel lo~', [paragraph([strike([plain('Hel lo')])])]], + ['~Hello~', [paragraph([strike([plain('Hello')])])]], + ['~~Hello~~', [paragraph([strike([plain('Hello')])])]], + ['~~Hello~', [paragraph([plain(`~`), strike([plain('Hello')])])]], + ['~Hello~~', [paragraph([strike([plain('Hello')]), plain(`~`)])]], + ['~Hello', [paragraph([plain('~Hello')])]], + ['Hello~', [paragraph([plain('Hello~')])]], + ['He~llo', [paragraph([plain('He~llo')])]], + ['~~~Hello~~~', [paragraph([plain(`~`), strike([plain('Hello')]), plain(`~`)])]], + ['~~~Hello~~', [paragraph([plain(`~`), strike([plain('Hello')])])]], + ['~Hello~ this is dog', [paragraph([strike([plain('Hello')]), plain(` this is dog`)])]], + ['Rocket cat says ~Hello~', [paragraph([plain(`Rocket cat says `), strike([plain('Hello')])])]], + ['He said ~Hello~ to her', [paragraph([plain(`He said `), strike([plain('Hello')]), plain(` to her`)])]], + ['~~Hello~~ this is dog', [paragraph([strike([plain('Hello')]), plain(` this is dog`)])]], + ['Rocket cat says ~~Hello~~', [paragraph([plain(`Rocket cat says `), strike([plain('Hello')])])]], + ['He said ~~Hello~~ to her', [paragraph([plain(`He said `), strike([plain('Hello')]), plain(` to her`)])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/strongEmphasis.test.ts b/packages/message-parser/tests/strongEmphasis.test.ts index 8384030aa11..52a1b1d30c1 100644 --- a/packages/message-parser/tests/strongEmphasis.test.ts +++ b/packages/message-parser/tests/strongEmphasis.test.ts @@ -1,156 +1,62 @@ import { parse } from '../src'; -import { - bold, - link, - paragraph, - plain, - italic, - strike, - emoji, - emojiUnicode, - mentionChannel, - mentionUser, -} from '../src/utils'; +import { bold, link, paragraph, plain, italic, strike, emoji, emojiUnicode, mentionChannel, mentionUser } from '../src/utils'; test.each([ - ['*:smile:*', [paragraph([bold([emoji('smile')])])]], - [ - '*test :smile: test*', - [paragraph([bold([plain('test '), emoji('smile'), plain(' test')])])], - ], - ['*😀*', [paragraph([bold([emojiUnicode('😀')])])]], - ['*test 😀*', [paragraph([bold([plain('test '), emojiUnicode('😀')])])]], - ['*@guilherme.gazzo*', [paragraph([bold([mentionUser('guilherme.gazzo')])])]], - ['*#GENERAL*', [paragraph([bold([mentionChannel('GENERAL')])])]], - [ - '*test @guilherme.gazzo*', - [paragraph([bold([plain('test '), mentionUser('guilherme.gazzo')])])], - ], - [ - '*test #GENERAL*', - [paragraph([bold([plain('test '), mentionChannel('GENERAL')])])], - ], - [ - '*[A brand new Gist](https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4)*', - [ - paragraph([ - bold([ - link('https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4', [ - plain('A brand new Gist'), - ]), - ]), - ]), - ], - ], - ['**bold**', [paragraph([bold([plain('bold')])])]], - ['** bold**', [paragraph([bold([plain(' bold')])])]], - ['** bold **', [paragraph([bold([plain(' bold ')])])]], - ['** bo ld **', [paragraph([bold([plain(' bo ld ')])])]], - ['pre**bold**', [paragraph([plain('pre'), bold([plain('bold')])])]], - ['**bold**pos', [paragraph([bold([plain('bold')]), plain('pos')])]], - [ - '**bold****bold**', - [paragraph([bold([plain('bold')]), bold([plain('bold')])])], - ], - [ - '**bold** **bold**', - [paragraph([bold([plain('bold')]), plain(' '), bold([plain('bold')])])], - ], - [ - '**bold** __italic__', - [paragraph([bold([plain('bold')]), plain(' '), italic([plain('italic')])])], - ], - ['**__italicbold__**', [paragraph([bold([italic([plain('italicbold')])])])]], - [ - 'plain **__italicbold__**', - [paragraph([plain('plain '), bold([italic([plain('italicbold')])])])], - ], - [ - 'plain **__~~strikeitalicbold~~__**', - [ - paragraph([ - plain('plain '), - bold([italic([strike([plain('strikeitalicbold')])])]), - ]), - ], - ], - ['**', [paragraph([plain('**')])]], - ['* *', [paragraph([plain('* *')])]], - ['** *', [paragraph([plain('** *')])]], - ['** **', [paragraph([plain('** **')])]], - ['** **', [paragraph([plain('** **')])]], - ['* Hello*', [paragraph([bold([plain(' Hello')])])]], - ['*Hello *', [paragraph([bold([plain('Hello ')])])]], - [ - ':custom*emoji*case:', - [paragraph([plain(':custom'), bold([plain('emoji')]), plain('case:')])], - ], - [ - 'text*hello*text', - [paragraph([plain('text'), bold([plain('hello')]), plain('text')])], - ], - ['*hello*text', [paragraph([bold([plain('hello')]), plain('text')])]], - ['text*hello*', [paragraph([plain('text'), bold([plain('hello')])])]], - ['*Hel lo*', [paragraph([bold([plain('Hel lo')])])]], - ['*Hello*', [paragraph([bold([plain('Hello')])])]], - ['**Hello*', [paragraph([plain('*'), bold([plain('Hello')])])]], - ['*Hello**', [paragraph([bold([plain('Hello')]), plain('*')])]], - ['*Hello', [paragraph([plain('*Hello')])]], - ['Hello*', [paragraph([plain('Hello*')])]], - ['He*llo', [paragraph([plain('He*llo')])]], - [ - '***Hello***', - [paragraph([plain('*'), bold([plain('Hello')]), plain('*')])], - ], - ['***Hello**', [paragraph([plain('*'), bold([plain('Hello')])])]], - [ - '*Hello* this is dog', - [paragraph([bold([plain('Hello')]), plain(' this is dog')])], - ], - [ - 'Rocket cat says *Hello*', - [paragraph([plain('Rocket cat says '), bold([plain('Hello')])])], - ], - [ - 'He said *Hello* to her', - [paragraph([plain('He said '), bold([plain('Hello')]), plain(' to her')])], - ], - [ - '**Hello** this is dog', - [paragraph([bold([plain('Hello')]), plain(' this is dog')])], - ], - [ - 'Rocket cat says **Hello**', - [paragraph([plain('Rocket cat says '), bold([plain('Hello')])])], - ], - [ - 'He said **Hello** to her', - [paragraph([plain('He said '), bold([plain('Hello')]), plain(' to her')])], - ], - [ - 'He was a**nn**oyed', - [paragraph([plain('He was a'), bold([plain('nn')]), plain('oyed')])], - ], - [ - 'There are two o in f*oo*tball', - [ - paragraph([ - plain('There are two o in f'), - bold([plain('oo')]), - plain('tball'), - ]), - ], - ], - ['*(teste*', [paragraph([bold([plain('(teste')])])]], - ['*(teste)*', [paragraph([bold([plain('(teste)')])])]], - [ - '*__~bolditalicstrike~_*', - [ - paragraph([ - bold([plain('_'), italic([strike([plain('bolditalicstrike')])])]), - ]), - ], - ], + ['*:smile:*', [paragraph([bold([emoji('smile')])])]], + ['*test :smile: test*', [paragraph([bold([plain('test '), emoji('smile'), plain(' test')])])]], + ['*😀*', [paragraph([bold([emojiUnicode('😀')])])]], + ['*test 😀*', [paragraph([bold([plain('test '), emojiUnicode('😀')])])]], + ['*@guilherme.gazzo*', [paragraph([bold([mentionUser('guilherme.gazzo')])])]], + ['*#GENERAL*', [paragraph([bold([mentionChannel('GENERAL')])])]], + ['*test @guilherme.gazzo*', [paragraph([bold([plain('test '), mentionUser('guilherme.gazzo')])])]], + ['*test #GENERAL*', [paragraph([bold([plain('test '), mentionChannel('GENERAL')])])]], + [ + '*[A brand new Gist](https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4)*', + [paragraph([bold([link('https://gist.github.com/24dddfa97bef58f46ac2ce0f80c58ba4', [plain('A brand new Gist')])])])], + ], + ['**bold**', [paragraph([bold([plain('bold')])])]], + ['** bold**', [paragraph([bold([plain(' bold')])])]], + ['** bold **', [paragraph([bold([plain(' bold ')])])]], + ['** bo ld **', [paragraph([bold([plain(' bo ld ')])])]], + ['pre**bold**', [paragraph([plain('pre'), bold([plain('bold')])])]], + ['**bold**pos', [paragraph([bold([plain('bold')]), plain('pos')])]], + ['**bold****bold**', [paragraph([bold([plain('bold')]), bold([plain('bold')])])]], + ['**bold** **bold**', [paragraph([bold([plain('bold')]), plain(' '), bold([plain('bold')])])]], + ['**bold** __italic__', [paragraph([bold([plain('bold')]), plain(' '), italic([plain('italic')])])]], + ['**__italicbold__**', [paragraph([bold([italic([plain('italicbold')])])])]], + ['plain **__italicbold__**', [paragraph([plain('plain '), bold([italic([plain('italicbold')])])])]], + ['plain **__~~strikeitalicbold~~__**', [paragraph([plain('plain '), bold([italic([strike([plain('strikeitalicbold')])])])])]], + ['**', [paragraph([plain('**')])]], + ['* *', [paragraph([plain('* *')])]], + ['** *', [paragraph([plain('** *')])]], + ['** **', [paragraph([plain('** **')])]], + ['** **', [paragraph([plain('** **')])]], + ['* Hello*', [paragraph([bold([plain(' Hello')])])]], + ['*Hello *', [paragraph([bold([plain('Hello ')])])]], + [':custom*emoji*case:', [paragraph([plain(':custom'), bold([plain('emoji')]), plain('case:')])]], + ['text*hello*text', [paragraph([plain('text'), bold([plain('hello')]), plain('text')])]], + ['*hello*text', [paragraph([bold([plain('hello')]), plain('text')])]], + ['text*hello*', [paragraph([plain('text'), bold([plain('hello')])])]], + ['*Hel lo*', [paragraph([bold([plain('Hel lo')])])]], + ['*Hello*', [paragraph([bold([plain('Hello')])])]], + ['**Hello*', [paragraph([plain('*'), bold([plain('Hello')])])]], + ['*Hello**', [paragraph([bold([plain('Hello')]), plain('*')])]], + ['*Hello', [paragraph([plain('*Hello')])]], + ['Hello*', [paragraph([plain('Hello*')])]], + ['He*llo', [paragraph([plain('He*llo')])]], + ['***Hello***', [paragraph([plain('*'), bold([plain('Hello')]), plain('*')])]], + ['***Hello**', [paragraph([plain('*'), bold([plain('Hello')])])]], + ['*Hello* this is dog', [paragraph([bold([plain('Hello')]), plain(' this is dog')])]], + ['Rocket cat says *Hello*', [paragraph([plain('Rocket cat says '), bold([plain('Hello')])])]], + ['He said *Hello* to her', [paragraph([plain('He said '), bold([plain('Hello')]), plain(' to her')])]], + ['**Hello** this is dog', [paragraph([bold([plain('Hello')]), plain(' this is dog')])]], + ['Rocket cat says **Hello**', [paragraph([plain('Rocket cat says '), bold([plain('Hello')])])]], + ['He said **Hello** to her', [paragraph([plain('He said '), bold([plain('Hello')]), plain(' to her')])]], + ['He was a**nn**oyed', [paragraph([plain('He was a'), bold([plain('nn')]), plain('oyed')])]], + ['There are two o in f*oo*tball', [paragraph([plain('There are two o in f'), bold([plain('oo')]), plain('tball')])]], + ['*(teste*', [paragraph([bold([plain('(teste')])])]], + ['*(teste)*', [paragraph([bold([plain('(teste)')])])]], + ['*__~bolditalicstrike~_*', [paragraph([bold([plain('_'), italic([strike([plain('bolditalicstrike')])])])])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/tasks.test.ts b/packages/message-parser/tests/tasks.test.ts index 26fd23d2ef6..8258aeeddf2 100644 --- a/packages/message-parser/tests/tasks.test.ts +++ b/packages/message-parser/tests/tasks.test.ts @@ -1,52 +1,36 @@ import { parse } from '../src'; -import { - plain, - tasks, - task, - mentionUser, - mentionChannel, - link, - bold, - emoji, -} from '../src/utils'; +import { plain, tasks, task, mentionUser, mentionChannel, link, bold, emoji } from '../src/utils'; test.each([ - [ - ` + [ + ` - [ ] this is an incomplete item - [x] this is a complete item - [x] @mentions, #refs, [links](http://localhost), **formatting** - [x] list syntax required (any unordered or ordered list supported) - [ ] :smile: `.trim(), - [ - tasks([ - task([plain('this is an incomplete item')], false), - task([plain('this is a complete item')], true), - task( - [ - mentionUser('mentions'), - plain(', '), - mentionChannel('refs'), - plain(', '), - link('http://localhost', [plain('links')]), - plain(', '), - bold([plain('formatting')]), - ], - true, - ), - task( - [ - plain( - 'list syntax required (any unordered or ordered list supported)', - ), - ], - true, - ), - task([emoji('smile')], false), - ]), - ], - ], + [ + tasks([ + task([plain('this is an incomplete item')], false), + task([plain('this is a complete item')], true), + task( + [ + mentionUser('mentions'), + plain(', '), + mentionChannel('refs'), + plain(', '), + link('http://localhost', [plain('links')]), + plain(', '), + bold([plain('formatting')]), + ], + true, + ), + task([plain('list syntax required (any unordered or ordered list supported)')], true), + task([emoji('smile')], false), + ]), + ], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/timestamp.test.ts b/packages/message-parser/tests/timestamp.test.ts index c1c9a20a8c9..b924ab184c6 100644 --- a/packages/message-parser/tests/timestamp.test.ts +++ b/packages/message-parser/tests/timestamp.test.ts @@ -1,123 +1,42 @@ import { parse } from '../src'; -import { - bold, - paragraph, - plain, - strike, - timestamp, - timestampFromHours, -} from '../src/utils'; +import { bold, paragraph, plain, strike, timestamp, timestampFromHours } from '../src/utils'; test.each([ - [``, [paragraph([timestamp('1708551317')])]], - [``, [paragraph([timestamp('1708551317', 'R')])]], - [ - 'hello ', - [paragraph([plain('hello '), timestamp('1708551317')])], - ], + [``, [paragraph([timestamp('1708551317')])]], + [``, [paragraph([timestamp('1708551317', 'R')])]], + ['hello ', [paragraph([plain('hello '), timestamp('1708551317')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); test.each([ - ['', [paragraph([plain('')])]], - ['', [paragraph([plain('')])]], + ['', [paragraph([plain('')])]], + ['', [paragraph([plain('')])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); test.each([ - ['~~', [paragraph([strike([timestamp('1708551317')])])]], - ['**', [paragraph([bold([plain('')])])]], + ['~~', [paragraph([strike([timestamp('1708551317')])])]], + ['**', [paragraph([bold([plain('')])])]], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); test.each([ - [ - '', - [ - paragraph([ - timestamp( - (Date.parse('2025-07-22T10:00:00.000+00:00') / 1000).toString(), - 'R', - ), - ]), - ], - ], - [ - '', - [ - paragraph([ - timestamp( - (Date.parse('2025-07-22T10:00:00.000+00:00') / 1000).toString(), - 'R', - ), - ]), - ], - ], - [ - '', - [ - paragraph([ - timestamp( - (Date.parse('2025-07-22T10:00:00.000+00:00') / 1000).toString(), - 'R', - ), - ]), - ], - ], - [ - '', - [ - paragraph([ - timestamp( - (Date.parse('2025-07-22T10:00:00+00:00') / 1000).toString(), - 'R', - ), - ]), - ], - ], - [ - '', - [ - paragraph([ - timestamp(timestampFromHours('10', '00', '00', '+00:00'), 'R'), - ]), - ], - ], - [ - '', - [ - paragraph([ - timestamp(timestampFromHours('10', '00', '00', '+00:00'), 'R'), - ]), - ], - ], - [ - '', - [ - paragraph([ - timestamp(timestampFromHours('10', '00', '05', '+00:00'), 't'), - ]), - ], - ], - [ - '', - [paragraph([timestamp(timestampFromHours('10', '00', '00'), 't')])], - ], + ['', [paragraph([timestamp((Date.parse('2025-07-22T10:00:00.000+00:00') / 1000).toString(), 'R')])]], + ['', [paragraph([timestamp((Date.parse('2025-07-22T10:00:00.000+00:00') / 1000).toString(), 'R')])]], + ['', [paragraph([timestamp((Date.parse('2025-07-22T10:00:00.000+00:00') / 1000).toString(), 'R')])]], + ['', [paragraph([timestamp((Date.parse('2025-07-22T10:00:00+00:00') / 1000).toString(), 'R')])]], + ['', [paragraph([timestamp(timestampFromHours('10', '00', '00', '+00:00'), 'R')])]], + ['', [paragraph([timestamp(timestampFromHours('10', '00', '00', '+00:00'), 'R')])]], + ['', [paragraph([timestamp(timestampFromHours('10', '00', '05', '+00:00'), 't')])]], + ['', [paragraph([timestamp(timestampFromHours('10', '00', '00'), 't')])]], - [ - '', - [ - paragraph([ - timestamp( - ((Date.parse('2025-07-24T20:19:58.154+00:00') / 1000) | 0).toString(), - 'R', - ), - ]), - ], - ], + [ + '', + [paragraph([timestamp(((Date.parse('2025-07-24T20:19:58.154+00:00') / 1000) | 0).toString(), 'R')])], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/unorderedList.test.ts b/packages/message-parser/tests/unorderedList.test.ts index de02867ae59..2ef56884e4a 100644 --- a/packages/message-parser/tests/unorderedList.test.ts +++ b/packages/message-parser/tests/unorderedList.test.ts @@ -2,79 +2,75 @@ import { parse } from '../src'; import { unorderedList, plain, listItem, bold, emoji } from '../src/utils'; test.each([ - [ - ` + [ + ` - First item - Second item - Third item - *Fourth item* - :smile: `.trim(), - [ - unorderedList([ - listItem([plain('First item')]), - listItem([plain('Second item')]), - listItem([plain('Third item')]), - listItem([bold([plain('Fourth item')])]), - listItem([emoji('smile')]), - ]), - ], - ], - [ - ` + [ + unorderedList([ + listItem([plain('First item')]), + listItem([plain('Second item')]), + listItem([plain('Third item')]), + listItem([bold([plain('Fourth item')])]), + listItem([emoji('smile')]), + ]), + ], + ], + [ + ` * First item * Second item * Third item * *Fourth item* `.trim(), - [ - unorderedList([ - listItem([plain('First item')]), - listItem([plain('Second item')]), - listItem([plain('Third item')]), - listItem([bold([plain('Fourth item')])]), - ]), - ], - ], + [ + unorderedList([ + listItem([plain('First item')]), + listItem([plain('Second item')]), + listItem([plain('Third item')]), + listItem([bold([plain('Fourth item')])]), + ]), + ], + ], - [ - ` + [ + ` - First item * Second item * Third item * *Fourth item* `.trim(), - [ - unorderedList([listItem([plain('First item')])]), - unorderedList([ - listItem([plain('Second item')]), - listItem([plain('Third item')]), - listItem([bold([plain('Fourth item')])]), - ]), - ], - ], - // [ - // ` - // * First item - // * Second item - // * Third item - // * Indented item - // * Indented item - // * Fourth item - // `.trim(), - // [paragraph([])], - // ], - // [ - // ` - // - First item - // - Second item - // - Third item - // - Indented item - // - Indented item - // - Fourth item - // `.trim(), - // [paragraph([])], - // ], + [ + unorderedList([listItem([plain('First item')])]), + unorderedList([listItem([plain('Second item')]), listItem([plain('Third item')]), listItem([bold([plain('Fourth item')])])]), + ], + ], + // [ + // ` + // * First item + // * Second item + // * Third item + // * Indented item + // * Indented item + // * Fourth item + // `.trim(), + // [paragraph([])], + // ], + // [ + // ` + // - First item + // - Second item + // - Third item + // - Indented item + // - Indented item + // - Fourth item + // `.trim(), + // [paragraph([])], + // ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); diff --git a/packages/message-parser/tests/url.test.ts b/packages/message-parser/tests/url.test.ts index fb178f22dd5..732385898bd 100644 --- a/packages/message-parser/tests/url.test.ts +++ b/packages/message-parser/tests/url.test.ts @@ -2,361 +2,174 @@ import { parse } from '../src'; import { lineBreak, autoLink, paragraph, plain, link } from '../src/utils'; test.each([ - [ - 'https://pt.wikipedia.org/wiki/Condi%C3%A7%C3%A3o_de_corrida#:~:text=Uma%20condi%C3%A7%C3%A3o%20de%20corrida%20%C3%A9,sequ%C3%AAncia%20ou%20sincronia%20doutros%20eventos', - [ - paragraph([ - autoLink( - 'https://pt.wikipedia.org/wiki/Condi%C3%A7%C3%A3o_de_corrida#:~:text=Uma%20condi%C3%A7%C3%A3o%20de%20corrida%20%C3%A9,sequ%C3%AAncia%20ou%20sincronia%20doutros%20eventos', - ), - ]), - ], - ], - [ - 'https://pt.wikipedia.org/', - [paragraph([autoLink('https://pt.wikipedia.org/')])], - ], - [ - 'https://pt.wikipedia.org/with-hyphen', - [paragraph([autoLink('https://pt.wikipedia.org/with-hyphen')])], - ], - [ - 'https://pt.wikipedia.org/with_underscore', - [paragraph([autoLink('https://pt.wikipedia.org/with_underscore')])], - ], - [ - 'https://www.npmjs.com/package/@rocket.chat/message-parser', - [ - paragraph([ - autoLink('https://www.npmjs.com/package/@rocket.chat/message-parser'), - ]), - ], - ], - ['http:/rocket.chat/teste', [paragraph([plain('http:/rocket.chat/teste')])]], - ['https:/rocket.chat/', [paragraph([plain('https:/rocket.chat/')])]], - ['https://test', [paragraph([plain('https://test')])]], - [ - 'httpsss://rocket.chat/test', - [paragraph([autoLink('httpsss://rocket.chat/test')])], - ], - [ - 'https://rocket.chat:3000/test', - [paragraph([autoLink('https://rocket.chat:3000/test')])], - ], - [ - 'https://rocket.chat/test?search', - [paragraph([autoLink('https://rocket.chat/test?search')])], - ], - [ - 'https://rocket.chat/test?search=test', - [paragraph([autoLink('https://rocket.chat/test?search=test')])], - ], - ['https://rocket.chat', [paragraph([autoLink('https://rocket.chat')])]], - ['https://localhost', [paragraph([autoLink('https://localhost')])]], - ['https://localhost:3000', [paragraph([autoLink('https://localhost:3000')])]], - [ - 'https://localhost:3000#fragment', - [paragraph([autoLink('https://localhost:3000#fragment')])], - ], - [ - 'https://localhost:3000#', - [paragraph([autoLink('https://localhost:3000#')])], - ], - [ - 'https://localhost:3000?', - [paragraph([autoLink('https://localhost:3000?')])], - ], - [ - 'https://localhost:3000/', - [paragraph([autoLink('https://localhost:3000/')])], - ], - [ - 'ftp://user:pass@localhost:21/etc/hosts', - [paragraph([autoLink('ftp://user:pass@localhost:21/etc/hosts')])], - ], - ['ssh://test@example.com', [paragraph([autoLink('ssh://test@example.com')])]], - [ - 'custom://test@example.com', - [paragraph([autoLink('custom://test@example.com')])], - ], - ['ftp://example.com', [paragraph([autoLink('ftp://example.com')])]], - [ - 'https://www.thingiverse.com/thing:5451684', - [paragraph([autoLink('https://www.thingiverse.com/thing:5451684')])], - ], - ['http://📙.la/❤️', [paragraph([autoLink('http://📙.la/❤️')])]], - [ - 'https://developer.rocket.chat/reference/api/rest-api#production-security-concerns look at this', - [ - paragraph([ - autoLink( - 'https://developer.rocket.chat/reference/api/rest-api#production-security-concerns', - ), - plain(' look at this'), - ]), - ], - ], - [ - 'https://developer.rocket.chat/reference/api/rest-api look at this', - [ - paragraph([ - autoLink('https://developer.rocket.chat/reference/api/rest-api'), - plain(' look at this'), - ]), - ], - ], + [ + 'https://pt.wikipedia.org/wiki/Condi%C3%A7%C3%A3o_de_corrida#:~:text=Uma%20condi%C3%A7%C3%A3o%20de%20corrida%20%C3%A9,sequ%C3%AAncia%20ou%20sincronia%20doutros%20eventos', + [ + paragraph([ + autoLink( + 'https://pt.wikipedia.org/wiki/Condi%C3%A7%C3%A3o_de_corrida#:~:text=Uma%20condi%C3%A7%C3%A3o%20de%20corrida%20%C3%A9,sequ%C3%AAncia%20ou%20sincronia%20doutros%20eventos', + ), + ]), + ], + ], + ['https://pt.wikipedia.org/', [paragraph([autoLink('https://pt.wikipedia.org/')])]], + ['https://pt.wikipedia.org/with-hyphen', [paragraph([autoLink('https://pt.wikipedia.org/with-hyphen')])]], + ['https://pt.wikipedia.org/with_underscore', [paragraph([autoLink('https://pt.wikipedia.org/with_underscore')])]], + [ + 'https://www.npmjs.com/package/@rocket.chat/message-parser', + [paragraph([autoLink('https://www.npmjs.com/package/@rocket.chat/message-parser')])], + ], + ['http:/rocket.chat/teste', [paragraph([plain('http:/rocket.chat/teste')])]], + ['https:/rocket.chat/', [paragraph([plain('https:/rocket.chat/')])]], + ['https://test', [paragraph([plain('https://test')])]], + ['httpsss://rocket.chat/test', [paragraph([autoLink('httpsss://rocket.chat/test')])]], + ['https://rocket.chat:3000/test', [paragraph([autoLink('https://rocket.chat:3000/test')])]], + ['https://rocket.chat/test?search', [paragraph([autoLink('https://rocket.chat/test?search')])]], + ['https://rocket.chat/test?search=test', [paragraph([autoLink('https://rocket.chat/test?search=test')])]], + ['https://rocket.chat', [paragraph([autoLink('https://rocket.chat')])]], + ['https://localhost', [paragraph([autoLink('https://localhost')])]], + ['https://localhost:3000', [paragraph([autoLink('https://localhost:3000')])]], + ['https://localhost:3000#fragment', [paragraph([autoLink('https://localhost:3000#fragment')])]], + ['https://localhost:3000#', [paragraph([autoLink('https://localhost:3000#')])]], + ['https://localhost:3000?', [paragraph([autoLink('https://localhost:3000?')])]], + ['https://localhost:3000/', [paragraph([autoLink('https://localhost:3000/')])]], + ['ftp://user:pass@localhost:21/etc/hosts', [paragraph([autoLink('ftp://user:pass@localhost:21/etc/hosts')])]], + ['ssh://test@example.com', [paragraph([autoLink('ssh://test@example.com')])]], + ['custom://test@example.com', [paragraph([autoLink('custom://test@example.com')])]], + ['ftp://example.com', [paragraph([autoLink('ftp://example.com')])]], + ['https://www.thingiverse.com/thing:5451684', [paragraph([autoLink('https://www.thingiverse.com/thing:5451684')])]], + ['http://📙.la/❤️', [paragraph([autoLink('http://📙.la/❤️')])]], + [ + 'https://developer.rocket.chat/reference/api/rest-api#production-security-concerns look at this', + [paragraph([autoLink('https://developer.rocket.chat/reference/api/rest-api#production-security-concerns'), plain(' look at this')])], + ], + [ + 'https://developer.rocket.chat/reference/api/rest-api look at this', + [paragraph([autoLink('https://developer.rocket.chat/reference/api/rest-api'), plain(' look at this')])], + ], - [ - 'https://developer.rocket.chat/reference/api/rest-api#fragment?query=query look at this', - [ - paragraph([ - autoLink( - 'https://developer.rocket.chat/reference/api/rest-api#fragment?query=query', - ), - plain(' look at this'), - ]), - ], - ], - [ - 'https://developer.rocket.chat look at this', - [ - paragraph([ - autoLink('https://developer.rocket.chat'), - plain(' look at this'), - ]), - ], - ], - [ - 'https://developer.rocket.chat?query=query look at this', - [ - paragraph([ - autoLink('https://developer.rocket.chat?query=query'), - plain(' look at this'), - ]), - ], - ], - [ - 'https://developer.rocket.chat?query=query\nline break', - [ - paragraph([autoLink('https://developer.rocket.chat?query=query')]), - paragraph([plain('line break')]), - ], - ], - [ - 'https://developer.rocket.chat?query=query\n\nline break', - [ - paragraph([autoLink('https://developer.rocket.chat?query=query')]), - lineBreak(), - paragraph([plain('line break')]), - ], - ], - [ - 'https://developer.rocket.chat?query=query_with_underscore look at this', - [ - paragraph([ - autoLink('https://developer.rocket.chat?query=query_with_underscore'), - plain(' look at this'), - ]), - ], - ], - [ - 'https://developer.rocket.chat/path_with_underscore look at this', - [ - paragraph([ - autoLink('https://developer.rocket.chat/path_with_underscore'), - plain(' look at this'), - ]), - ], - ], - [ - 'https://developer.rocket.chat#fragment_with_underscore look at this', - [ - paragraph([ - autoLink('https://developer.rocket.chat#fragment_with_underscore'), - plain(' look at this'), - ]), - ], - ], - [ - 'https://developer.rocket.chat followed by text', - [ - paragraph([ - autoLink('https://developer.rocket.chat'), - plain(' followed by text'), - ]), - ], - ], - [ - 'two urls https://developer.rocket.chat , https://rocket.chat', - [ - paragraph([ - plain('two urls '), - autoLink('https://developer.rocket.chat'), - plain(' , '), - autoLink('https://rocket.chat'), - ]), - ], - ], - [ - 'https://1developer.rocket.chat', - [paragraph([autoLink('https://1developer.rocket.chat')])], - ], - [ - 'https://en.m.wikipedia.org/wiki/Main_Page', - [paragraph([autoLink('https://en.m.wikipedia.org/wiki/Main_Page')])], - ], - ['test.1test.com', [paragraph([autoLink('test.1test.com')])]], - [ - 'http://test.e-xample.com', - [paragraph([autoLink('http://test.e-xample.com')])], - ], - ['www.n-tv.de', [paragraph([autoLink('www.n-tv.de')])]], - [ - 'www.n-tv.de/test, test', - [paragraph([autoLink('www.n-tv.de/test'), plain(', test')])], - ], - [ - 'www.n-tv.de/, test', - [paragraph([autoLink('www.n-tv.de/'), plain(', test')])], - ], - [ - 'www.n-tv.de, test', - [paragraph([autoLink('www.n-tv.de'), plain(', test')])], - ], - [ - 'https://www.n-tv.de, test', - [paragraph([autoLink('https://www.n-tv.de'), plain(', test')])], - ], - ['http://te_st.com', [paragraph([autoLink('http://te_st.com')])]], - ['www.te_st.com', [paragraph([autoLink('www.te_st.com')])]], - [ - '[google_search](http://google.com)', - [paragraph([link('http://google.com', [plain('google_search')])])], - ], - [ - 'app...https://rocket.chat https://rocket.chat', - [ - paragraph([ - plain('app...https://rocket.chat '), - autoLink('https://rocket.chat'), - ]), - ], - ], - [ - 'Hey check it out the best communication platform https://rocket.chat! There is not discussion about it.', - [ - paragraph([ - plain('Hey check it out the best communication platform '), - autoLink('https://rocket.chat'), - plain('! There is not discussion about it.'), - ]), - ], - ], - [ - 'This is a normal phrase.This in another phrase.', - [paragraph([plain('This is a normal phrase.This in another phrase.')])], - ], - [ - 'https://github.com/RocketChat/Rocket.Chat/releases/tag/6.0.0-rc.3', - [ - paragraph([ - autoLink( - 'https://github.com/RocketChat/Rocket.Chat/releases/tag/6.0.0-rc.3', - ), - ]), - ], - ], - [ - 'https://www.rocket.chat/(W(601))/Main?ScreenId=GI000027', - [ - paragraph([ - autoLink('https://www.rocket.chat/(W(601))/Main?ScreenId=GI000027'), - ]), - ], - ], - [ - 'https://rocketchat.atlassian.net/browse/OC-718?filter=10078&jql=%22Defect%20from%5BVersion%20Picker%20(multiple%20versions)%5D%22%20%3D%206.0.0%20AND%20%22Defect%20from%5BVersion%20Picker%20(multiple%20versions)%5D%22%20%3D%206.0.0%20AND%20created%20%3E%3D%20-48h%20ORDER%20BY%20cf%5B10070%5D%20ASC%2C%20status%20ASC%2C%20created%20DESC', - [ - paragraph([ - link( - 'https://rocketchat.atlassian.net/browse/OC-718?filter=10078&jql=%22Defect%20from%5BVersion%20Picker%20(multiple%20versions)%5D%22%20%3D%206.0.0%20AND%20%22Defect%20from%5BVersion%20Picker%20(multiple%20versions)%5D%22%20%3D%206.0.0%20AND%20created%20%3E%3D%20-48h%20ORDER%20BY%20cf%5B10070%5D%20ASC%2C%20status%20ASC%2C%20created%20DESC', - ), - ]), - ], - ], + [ + 'https://developer.rocket.chat/reference/api/rest-api#fragment?query=query look at this', + [paragraph([autoLink('https://developer.rocket.chat/reference/api/rest-api#fragment?query=query'), plain(' look at this')])], + ], + ['https://developer.rocket.chat look at this', [paragraph([autoLink('https://developer.rocket.chat'), plain(' look at this')])]], + [ + 'https://developer.rocket.chat?query=query look at this', + [paragraph([autoLink('https://developer.rocket.chat?query=query'), plain(' look at this')])], + ], + [ + 'https://developer.rocket.chat?query=query\nline break', + [paragraph([autoLink('https://developer.rocket.chat?query=query')]), paragraph([plain('line break')])], + ], + [ + 'https://developer.rocket.chat?query=query\n\nline break', + [paragraph([autoLink('https://developer.rocket.chat?query=query')]), lineBreak(), paragraph([plain('line break')])], + ], + [ + 'https://developer.rocket.chat?query=query_with_underscore look at this', + [paragraph([autoLink('https://developer.rocket.chat?query=query_with_underscore'), plain(' look at this')])], + ], + [ + 'https://developer.rocket.chat/path_with_underscore look at this', + [paragraph([autoLink('https://developer.rocket.chat/path_with_underscore'), plain(' look at this')])], + ], + [ + 'https://developer.rocket.chat#fragment_with_underscore look at this', + [paragraph([autoLink('https://developer.rocket.chat#fragment_with_underscore'), plain(' look at this')])], + ], + ['https://developer.rocket.chat followed by text', [paragraph([autoLink('https://developer.rocket.chat'), plain(' followed by text')])]], + [ + 'two urls https://developer.rocket.chat , https://rocket.chat', + [paragraph([plain('two urls '), autoLink('https://developer.rocket.chat'), plain(' , '), autoLink('https://rocket.chat')])], + ], + ['https://1developer.rocket.chat', [paragraph([autoLink('https://1developer.rocket.chat')])]], + ['https://en.m.wikipedia.org/wiki/Main_Page', [paragraph([autoLink('https://en.m.wikipedia.org/wiki/Main_Page')])]], + ['test.1test.com', [paragraph([autoLink('test.1test.com')])]], + ['http://test.e-xample.com', [paragraph([autoLink('http://test.e-xample.com')])]], + ['www.n-tv.de', [paragraph([autoLink('www.n-tv.de')])]], + ['www.n-tv.de/test, test', [paragraph([autoLink('www.n-tv.de/test'), plain(', test')])]], + ['www.n-tv.de/, test', [paragraph([autoLink('www.n-tv.de/'), plain(', test')])]], + ['www.n-tv.de, test', [paragraph([autoLink('www.n-tv.de'), plain(', test')])]], + ['https://www.n-tv.de, test', [paragraph([autoLink('https://www.n-tv.de'), plain(', test')])]], + ['http://te_st.com', [paragraph([autoLink('http://te_st.com')])]], + ['www.te_st.com', [paragraph([autoLink('www.te_st.com')])]], + ['[google_search](http://google.com)', [paragraph([link('http://google.com', [plain('google_search')])])]], + ['app...https://rocket.chat https://rocket.chat', [paragraph([plain('app...https://rocket.chat '), autoLink('https://rocket.chat')])]], + [ + 'Hey check it out the best communication platform https://rocket.chat! There is not discussion about it.', + [ + paragraph([ + plain('Hey check it out the best communication platform '), + autoLink('https://rocket.chat'), + plain('! There is not discussion about it.'), + ]), + ], + ], + ['This is a normal phrase.This in another phrase.', [paragraph([plain('This is a normal phrase.This in another phrase.')])]], + [ + 'https://github.com/RocketChat/Rocket.Chat/releases/tag/6.0.0-rc.3', + [paragraph([autoLink('https://github.com/RocketChat/Rocket.Chat/releases/tag/6.0.0-rc.3')])], + ], + [ + 'https://www.rocket.chat/(W(601))/Main?ScreenId=GI000027', + [paragraph([autoLink('https://www.rocket.chat/(W(601))/Main?ScreenId=GI000027')])], + ], + [ + 'https://rocketchat.atlassian.net/browse/OC-718?filter=10078&jql=%22Defect%20from%5BVersion%20Picker%20(multiple%20versions)%5D%22%20%3D%206.0.0%20AND%20%22Defect%20from%5BVersion%20Picker%20(multiple%20versions)%5D%22%20%3D%206.0.0%20AND%20created%20%3E%3D%20-48h%20ORDER%20BY%20cf%5B10070%5D%20ASC%2C%20status%20ASC%2C%20created%20DESC', + [ + paragraph([ + link( + 'https://rocketchat.atlassian.net/browse/OC-718?filter=10078&jql=%22Defect%20from%5BVersion%20Picker%20(multiple%20versions)%5D%22%20%3D%206.0.0%20AND%20%22Defect%20from%5BVersion%20Picker%20(multiple%20versions)%5D%22%20%3D%206.0.0%20AND%20created%20%3E%3D%20-48h%20ORDER%20BY%20cf%5B10070%5D%20ASC%2C%20status%20ASC%2C%20created%20DESC', + ), + ]), + ], + ], ])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + expect(parse(input)).toMatchObject(output); }); describe('autoLink with custom hosts settings comming from Rocket.Chat', () => { - test.each([ - [ - 'http://gitlab.local', - [paragraph([autoLink('http://gitlab.local', ['local'])])], - ], - ['gitlab.local', [paragraph([autoLink('gitlab.local', ['local'])])]], - [ - 'internaltool.intranet', - [paragraph([autoLink('internaltool.intranet', ['local', 'intranet'])])], - ], - ])('parses %p', (input, output) => { - expect( - parse(input, { customDomains: ['local', 'intranet'] }), - ).toMatchObject(output); - }); + test.each([ + ['http://gitlab.local', [paragraph([autoLink('http://gitlab.local', ['local'])])]], + ['gitlab.local', [paragraph([autoLink('gitlab.local', ['local'])])]], + ['internaltool.intranet', [paragraph([autoLink('internaltool.intranet', ['local', 'intranet'])])]], + ])('parses %p', (input, output) => { + expect(parse(input, { customDomains: ['local', 'intranet'] })).toMatchObject(output); + }); }); describe('autoLink WITHOUT custom hosts settings comming from Rocket.Chat', () => { - test.each([ - [ - 'https://internaltool.testt', - [paragraph([plain('https://internaltool.testt')])], - ], - ])('parses %p', (input, output) => { - expect(parse(input, { customDomains: ['local'] })).toMatchObject(output); - }); + test.each([['https://internaltool.testt', [paragraph([plain('https://internaltool.testt')])]]])('parses %p', (input, output) => { + expect(parse(input, { customDomains: ['local'] })).toMatchObject(output); + }); }); describe('autoLink helper function', () => { - it('should preserve the original protocol if the protocol is http or https', () => { - expect(autoLink('https://rocket.chat/test')).toMatchObject( - link('https://rocket.chat/test'), - ); + it('should preserve the original protocol if the protocol is http or https', () => { + expect(autoLink('https://rocket.chat/test')).toMatchObject(link('https://rocket.chat/test')); - expect(autoLink('http://rocket.chat/test')).toMatchObject( - link('http://rocket.chat/test'), - ); - }); + expect(autoLink('http://rocket.chat/test')).toMatchObject(link('http://rocket.chat/test')); + }); - it('should preserve the original protocol even if for custom protocols', () => { - expect(autoLink('custom://rocket.chat/test')).toMatchObject( - link('custom://rocket.chat/test'), - ); - }); + it('should preserve the original protocol even if for custom protocols', () => { + expect(autoLink('custom://rocket.chat/test')).toMatchObject(link('custom://rocket.chat/test')); + }); - it('should return // as the protocol if // is the protocol specified', () => { - expect(autoLink('//rocket.chat/test')).toMatchObject( - link('//rocket.chat/test'), - ); - }); + it('should return // as the protocol if // is the protocol specified', () => { + expect(autoLink('//rocket.chat/test')).toMatchObject(link('//rocket.chat/test')); + }); - it("should return an url concatenated '//' if the url has no protocol", () => { - expect(autoLink('rocket.chat/test')).toMatchObject( - link('//rocket.chat/test', [plain('rocket.chat/test')]), - ); - }); + it("should return an url concatenated '//' if the url has no protocol", () => { + expect(autoLink('rocket.chat/test')).toMatchObject(link('//rocket.chat/test', [plain('rocket.chat/test')])); + }); - it("should return an url concatenated '//' if the url has no protocol and has sub-domain", () => { - expect(autoLink('spark-public.s3.amazonaws.com')).toMatchObject( - link('//spark-public.s3.amazonaws.com', [ - plain('spark-public.s3.amazonaws.com'), - ]), - ); - }); + it("should return an url concatenated '//' if the url has no protocol and has sub-domain", () => { + expect(autoLink('spark-public.s3.amazonaws.com')).toMatchObject( + link('//spark-public.s3.amazonaws.com', [plain('spark-public.s3.amazonaws.com')]), + ); + }); - it("should return an plain text url due to invalid TLD that's validate with the external library TLDTS", () => { - expect(autoLink('rocket.chattt/url_path')).toMatchObject( - plain('rocket.chattt/url_path'), - ); - }); + it("should return an plain text url due to invalid TLD that's validate with the external library TLDTS", () => { + expect(autoLink('rocket.chattt/url_path')).toMatchObject(plain('rocket.chattt/url_path')); + }); }); diff --git a/packages/message-parser/tsconfig-bundle.json b/packages/message-parser/tsconfig-bundle.json deleted file mode 100644 index 77caa2b8f6c..00000000000 --- a/packages/message-parser/tsconfig-bundle.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "rootDir": "./src" - }, - "include": ["./src"] -} diff --git a/packages/message-parser/tsconfig.build.json b/packages/message-parser/tsconfig.build.json new file mode 100644 index 00000000000..f1e23e7000c --- /dev/null +++ b/packages/message-parser/tsconfig.build.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./dist", + "declaration": true, + "declarationMap": true, + }, + "include": ["./src"] +} diff --git a/packages/message-parser/tsconfig.json b/packages/message-parser/tsconfig.json index 619475cd791..2cf7eee3cc6 100644 --- a/packages/message-parser/tsconfig.json +++ b/packages/message-parser/tsconfig.json @@ -1,19 +1,8 @@ { + "extends": "@rocket.chat/tsconfig/server.json", "compilerOptions": { "rootDir": ".", - "target": "es5", - "module": "ESNext", - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "lib": ["es2019"], - "outDir": "./dist", - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "moduleResolution": "node", - "noImplicitThis": true, - "alwaysStrict": true + "target": "es2020", + "module": "esnext" } } diff --git a/packages/message-parser/typedoc.json b/packages/message-parser/typedoc.json deleted file mode 100644 index af0fd90acfc..00000000000 --- a/packages/message-parser/typedoc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "entryPoints": ["src/index.ts"], - "out": "../../static/message-parser" -} diff --git a/packages/message-parser/webpack.config.js b/packages/message-parser/webpack.config.js deleted file mode 100644 index 1bae39ea98a..00000000000 --- a/packages/message-parser/webpack.config.js +++ /dev/null @@ -1,86 +0,0 @@ -const path = require('path'); - -const config = (outputDeclarations = false) => ({ - entry: './src/index.ts', - module: { - rules: [ - { - test: /\.ts$/, - use: { - loader: 'ts-loader', - options: { - configFile: path.resolve(__dirname, './tsconfig-bundle.json'), - ...(!outputDeclarations && { - compilerOptions: { - declaration: false, - declarationMap: undefined, - }, - }), - }, - }, - include: [path.resolve(__dirname, './src')], - exclude: [path.resolve(__dirname, './tests')], - }, - { - test: /\.pegjs$/, - use: ['babel-loader', '@rocket.chat/peggy-loader'], - }, - ], - }, - resolve: { - extensions: ['.ts', '.js', '.pegjs'], - }, -}); - -module.exports = [ - { - ...config(), - mode: 'development', - output: { - path: path.resolve(__dirname, './dist'), - filename: 'messageParser.development.js', - library: { - type: 'commonjs2', - }, - }, - }, - { - ...config(), - mode: 'production', - output: { - path: path.resolve(__dirname, './dist'), - filename: 'messageParser.production.js', - library: { - type: 'commonjs2', - }, - }, - }, - { - ...config(), - mode: 'production', - experiments: { - outputModule: true, - }, - output: { - path: path.resolve(__dirname, './dist'), - filename: 'messageParser.mjs', - library: { - type: 'module', - }, - }, - }, - { - ...config(true), - mode: 'production', - output: { - path: path.resolve(__dirname, './dist'), - filename: 'messageParser.umd.js', - library: { - type: 'umd', - name: 'RocketChatMessageParser', - umdNamedDefine: true, - }, - globalObject: 'this', - }, - }, -]; diff --git a/packages/message-parser/webpack.config.ts b/packages/message-parser/webpack.config.ts new file mode 100644 index 00000000000..dd5e05742e6 --- /dev/null +++ b/packages/message-parser/webpack.config.ts @@ -0,0 +1,40 @@ +import { resolve } from 'node:path'; + +export default [ + { + entry: './src/index.ts', + module: { + rules: [ + { + test: /\.ts$/, + use: { + loader: 'ts-loader', + options: { + configFile: resolve('./tsconfig.build.json'), + }, + }, + include: [resolve('./src')], + exclude: [resolve('./tests')], + }, + { + test: /\.pegjs$/, + use: ['@rocket.chat/peggy-loader'], + }, + ], + }, + resolve: { + extensions: ['.ts', '.js', '.pegjs'], + }, + mode: 'production', + experiments: { + outputModule: true, + }, + output: { + path: resolve('./dist'), + filename: 'messageParser.js', + library: { + type: 'module', + }, + }, + }, +]; diff --git a/packages/peggy-loader/src/index.ts b/packages/peggy-loader/src/index.ts index a04c69c50f0..4227545fc34 100644 --- a/packages/peggy-loader/src/index.ts +++ b/packages/peggy-loader/src/index.ts @@ -18,14 +18,10 @@ type Options = BuildOptionsBase & ); function peggyLoader(this: LoaderContext, grammarContent: string): string { - const options: Options = { - format: 'commonjs', - ...this.getOptions(), - }; - return peggy.generate(grammarContent, { output: 'source', - ...options, + format: 'es', + ...this.getOptions(), }); } diff --git a/yarn.lock b/yarn.lock index af877dec39f..9296fc08d10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9093,27 +9093,21 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/message-parser@workspace:packages/message-parser" dependencies: - "@babel/core": "npm:~7.28.5" - "@babel/eslint-parser": "npm:~7.28.5" - "@babel/preset-env": "npm:~7.28.5" "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/jest-presets": "workspace:~" "@rocket.chat/peggy-loader": "workspace:~" "@rocket.chat/prettier-config": "npm:~0.31.25" "@types/jest": "npm:~30.0.0" "@types/node": "npm:~22.16.5" - "@typescript-eslint/parser": "npm:~5.58.0" - babel-loader: "npm:~10.0.0" + "@typescript-eslint/parser": "npm:~5.60.1" eslint: "npm:~8.45.0" jest: "npm:~30.2.0" npm-run-all: "npm:^4.1.5" peggy: "npm:4.1.1" - prettier: "npm:~3.3.3" prettier-plugin-pegjs: "npm:~0.5.4" rimraf: "npm:^6.0.1" tldts: "npm:~6.1.86" ts-loader: "npm:~9.5.4" - typedoc: "npm:~0.28.14" typescript: "npm:~5.9.3" webpack: "npm:~5.99.9" webpack-cli: "npm:~5.1.4" @@ -14667,23 +14661,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/parser@npm:~5.58.0": - version: 5.58.0 - resolution: "@typescript-eslint/parser@npm:5.58.0" - dependencies: - "@typescript-eslint/scope-manager": "npm:5.58.0" - "@typescript-eslint/types": "npm:5.58.0" - "@typescript-eslint/typescript-estree": "npm:5.58.0" - debug: "npm:^4.3.4" - peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - peerDependenciesMeta: - typescript: - optional: true - checksum: 10/e15b3e36b56d5a02068d5c125791134f27a241c4e1ed577b282292b467b9e56e1111d7dcee6abe28f5143296fe264d9a4f8b02f22a9d157b3f0dfc98102bd210 - languageName: node - linkType: hard - "@typescript-eslint/parser@npm:~5.60.1": version: 5.60.1 resolution: "@typescript-eslint/parser@npm:5.60.1" @@ -14701,16 +14678,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:5.58.0": - version: 5.58.0 - resolution: "@typescript-eslint/scope-manager@npm:5.58.0" - dependencies: - "@typescript-eslint/types": "npm:5.58.0" - "@typescript-eslint/visitor-keys": "npm:5.58.0" - checksum: 10/fd3295eae5c6031e03f18261120c6642bfe0b7619f74cba48399d5a12873081c1b572e105b14976e55bed5bc5217576e0fb58c35bc3000906afd90ba3a31c372 - languageName: node - linkType: hard - "@typescript-eslint/scope-manager@npm:5.60.1": version: 5.60.1 resolution: "@typescript-eslint/scope-manager@npm:5.60.1" @@ -14758,13 +14725,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/types@npm:5.58.0": - version: 5.58.0 - resolution: "@typescript-eslint/types@npm:5.58.0" - checksum: 10/c927754f463b9e570163d6818eb69e702f47f918095500281adb126973da8bcb872c82640e5ed1c8c0d255308eebca58f1ca89b6b8da613207d05b2e4bfce8ef - languageName: node - linkType: hard - "@typescript-eslint/types@npm:5.60.1": version: 5.60.1 resolution: "@typescript-eslint/types@npm:5.60.1" @@ -14786,24 +14746,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:5.58.0": - version: 5.58.0 - resolution: "@typescript-eslint/typescript-estree@npm:5.58.0" - dependencies: - "@typescript-eslint/types": "npm:5.58.0" - "@typescript-eslint/visitor-keys": "npm:5.58.0" - debug: "npm:^4.3.4" - globby: "npm:^11.1.0" - is-glob: "npm:^4.0.3" - semver: "npm:^7.3.7" - tsutils: "npm:^3.21.0" - peerDependenciesMeta: - typescript: - optional: true - checksum: 10/ab5eabf3204eab1b8d5f4e0e2c77a35f1f196ef9aff22f0c4771e02b6abd4f39811fef30b58163b4a8debec696a15e9c4689ad8a9d6bc5ec908d9c8c01fe249f - languageName: node - linkType: hard - "@typescript-eslint/typescript-estree@npm:5.60.1": version: 5.60.1 resolution: "@typescript-eslint/typescript-estree@npm:5.60.1" @@ -14909,16 +14851,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:5.58.0": - version: 5.58.0 - resolution: "@typescript-eslint/visitor-keys@npm:5.58.0" - dependencies: - "@typescript-eslint/types": "npm:5.58.0" - eslint-visitor-keys: "npm:^3.3.0" - checksum: 10/c7fd982b016bd4e6f6523ba68136269e430bf3688eaa45ab661000459ddf3625bc374e789719265401212fa9e4dfce4d179fb9b5faab09e0ca2033efe57deb62 - languageName: node - linkType: hard - "@typescript-eslint/visitor-keys@npm:5.60.1": version: 5.60.1 resolution: "@typescript-eslint/visitor-keys@npm:5.60.1"