@@ -55,4 +55,109 @@ describe('tokenizeMessage', () => {
5555 type : 'url' ,
5656 } ] ) ;
5757 } ) ;
58+
59+ it ( 'should tokenize a string markdown strings' , ( ) => {
60+ const tokens = tokenizeMessage ( {
61+ messageText : '**bold** https://www.naver.com ** https://www.naver.com ** [bold] **text** **text**' ,
62+ includeMarkdown : true ,
63+ } ) ;
64+ expect ( tokens ) . toEqual ( [
65+ { value : '' , type : 'string' } ,
66+ {
67+ type : 'markdown' ,
68+ markdownType : 'bold' ,
69+ value : '**bold**' ,
70+ groups : [ '**bold**' , 'bold' ] ,
71+ } ,
72+ { value : ' ' , type : 'string' } ,
73+ { value : 'https://www.naver.com' , type : 'url' } ,
74+ { value : ' ' , type : 'string' } ,
75+ {
76+ type : 'markdown' ,
77+ markdownType : 'bold' ,
78+ value : '** https://www.naver.com **' ,
79+ groups : [ '** https://www.naver.com **' , ' https://www.naver.com ' ] ,
80+ } ,
81+ { value : ' [bold] ' , type : 'string' } ,
82+ {
83+ type : 'markdown' ,
84+ markdownType : 'bold' ,
85+ value : '**text**' ,
86+ groups : [ '**text**' , 'text' ] ,
87+ } ,
88+ { value : ' ' , type : 'string' } ,
89+ {
90+ type : 'markdown' ,
91+ markdownType : 'bold' ,
92+ value : '**text**' ,
93+ groups : [ '**text**' , 'text' ] ,
94+ } ,
95+ ] ) ;
96+ } ) ;
97+
98+ it ( 'should tokenize a string with mention, markdown strings' , ( ) => {
99+ const tokens = tokenizeMessage ( {
100+ messageText : 'Hello @{userA}! This is a test for **tokenizeMessage**. Followings are urls with different '
101+ + 'syntaxes: https://example.com, and [here](https://example.com). Finally, the followings are nested '
102+ + 'markdown cases: [**this one**](https://example.com) and **[this one](https://example.com)**' ,
103+ mentionedUsers : [
104+ ( { userId : 'userA' , nickname : 'User A' } as User ) ,
105+ ] ,
106+ includeMarkdown : true ,
107+ } ) ;
108+ expect ( tokens ) . toEqual ( [
109+ { value : 'Hello ' , type : 'string' } ,
110+ { value : 'User A' , type : 'mention' , userId : 'userA' } ,
111+ { value : '! This is a test for ' , type : 'string' } ,
112+ {
113+ type : 'markdown' ,
114+ markdownType : 'bold' ,
115+ value : '**tokenizeMessage**' ,
116+ groups : [ '**tokenizeMessage**' , 'tokenizeMessage' ] ,
117+ } ,
118+ {
119+ value : '. Followings are urls with different syntaxes: ' ,
120+ type : 'string' ,
121+ } ,
122+ { value : 'https://example.com' , type : 'url' } ,
123+ { value : ', and ' , type : 'string' } ,
124+ {
125+ type : 'markdown' ,
126+ markdownType : 'url' ,
127+ value : '[here](https://example.com)' ,
128+ groups : [
129+ '[here](https://example.com)' ,
130+ 'here' ,
131+ 'https://example.com' ,
132+ ] ,
133+ } ,
134+ {
135+ value : '. Finally, the followings are nested markdown cases: ' ,
136+ type : 'string' ,
137+ } ,
138+ {
139+ groups : [
140+ '[**this one**](https://example.com)' ,
141+ '**this one**' ,
142+ 'https://example.com' ,
143+ ] ,
144+ markdownType : 'url' ,
145+ type : 'markdown' ,
146+ value : '[**this one**](https://example.com)' ,
147+ } ,
148+ {
149+ type : 'string' ,
150+ value : ' and ' ,
151+ } ,
152+ {
153+ groups : [
154+ '**[this one](https://example.com)**' ,
155+ '[this one](https://example.com)' ,
156+ ] ,
157+ markdownType : 'bold' ,
158+ type : 'markdown' ,
159+ value : '**[this one](https://example.com)**' ,
160+ } ,
161+ ] ) ;
162+ } ) ;
58163} ) ;
0 commit comments