github.com/tada-team/tdproto@v1.51.57/tdmarkup/testdata.go (about)

     1  package tdmarkup
     2  
     3  import "github.com/tada-team/tdproto"
     4  
     5  // Data for testing other implementation
     6  var MarkupTestCases = []struct {
     7  	Title string
     8  	Raw   string
     9  	Html  string
    10  	Plain string
    11  	Links []tdproto.MessageLink
    12  }{
    13  	{
    14  		Title: "noop",
    15  		Raw:   "123",
    16  		Html:  "123",
    17  		Plain: "123",
    18  	},
    19  	{
    20  		Title: "empty bold",
    21  		Raw:   "**",
    22  		Html:  "**",
    23  		Plain: "**",
    24  	},
    25  	{
    26  		Title: "one bold",
    27  		Raw:   "*1*",
    28  		Html:  "<b>1</b>",
    29  		Plain: "1",
    30  	},
    31  	{
    32  		Title: "bold",
    33  		Raw:   "123 *456* 789",
    34  		Html:  "123 <b>456</b> 789",
    35  		Plain: "123 456 789",
    36  	},
    37  	{
    38  		Title: "bold is inline only",
    39  		Raw:   "123 *45\n6* 789",
    40  		Html:  "123 *45\n6* 789",
    41  		Plain: "123 *45\n6* 789",
    42  	},
    43  	{
    44  		Title: "bold ru",
    45  		Raw:   "привет, *ромашки!*",
    46  		Html:  "привет, <b>ромашки!</b>",
    47  		Plain: "привет, ромашки!",
    48  	},
    49  	{
    50  		Title: "bold only",
    51  		Raw:   "*123*",
    52  		Html:  "<b>123</b>",
    53  		Plain: "123",
    54  	},
    55  	{
    56  		Title: "bold and punctuation",
    57  		Raw:   "*123*!",
    58  		Html:  "<b>123</b>!",
    59  		Plain: "123!",
    60  	},
    61  	{
    62  		Title: "not a bold",
    63  		Raw:   "*123\n456*",
    64  		Html:  "*123\n456*",
    65  		Plain: "*123\n456*",
    66  	},
    67  	{
    68  		Title: "bold eof",
    69  		Raw:   "123 *456*",
    70  		Html:  "123 <b>456</b>",
    71  		Plain: "123 456",
    72  	},
    73  	{
    74  		Title: "bold eol",
    75  		Raw:   "123 *456*\n*789*",
    76  		Html:  "123 <b>456</b>\n<b>789</b>",
    77  		Plain: "123 456\n789",
    78  	},
    79  	{
    80  		Title: "double bold",
    81  		Raw:   "123 *456* 789 *10*",
    82  		Html:  "123 <b>456</b> 789 <b>10</b>",
    83  		Plain: "123 456 789 10",
    84  	},
    85  	{
    86  		Title: "code only",
    87  		Raw:   "`123`",
    88  		Html:  "<code>123</code>",
    89  		Plain: "123",
    90  	},
    91  	{
    92  		Title: "no markup inside code",
    93  		Raw:   "`*123*`",
    94  		Html:  "<code>*123*</code>",
    95  		Plain: "*123*",
    96  	},
    97  	{
    98  		Title: "no markup inside code 2",
    99  		Raw:   "`123 ~456~ `",
   100  		Html:  "<code>123 ~456~ </code>",
   101  		Plain: "123 ~456~ ",
   102  	},
   103  	{
   104  		Title: "no markup inside code 3",
   105  		Raw:   "example: ` 123 ~456~ `",
   106  		Html:  "example: <code> 123 ~456~ </code>",
   107  		Plain: "example:  123 ~456~ ",
   108  	},
   109  	{
   110  		Title: "italic",
   111  		Raw:   "123 /456/ 789",
   112  		Html:  "123 <i>456</i> 789",
   113  		Plain: "123 456 789",
   114  	},
   115  	{
   116  		Title: "not italic",
   117  		Raw:   "123 / 456/ 789",
   118  		Html:  "123 / 456/ 789",
   119  		Plain: "123 / 456/ 789",
   120  	},
   121  	{
   122  		Title: "not italic 2",
   123  		Raw:   "123 / 456 / 789",
   124  		Html:  "123 / 456 / 789",
   125  		Plain: "123 / 456 / 789",
   126  	},
   127  	{
   128  		Title: "not italic 3",
   129  		Raw:   "123/ 456 /789",
   130  		Html:  "123/ 456 /789",
   131  		Plain: "123/ 456 /789",
   132  	},
   133  	{
   134  		Title: "path",
   135  		Raw:   "GET /path/to/ here",
   136  		Html:  "GET /path/to/ here",
   137  		Plain: "GET /path/to/ here",
   138  	},
   139  	{
   140  		Title: "not italic 4 without links",
   141  		Raw:   "https://ya.ru/",
   142  		Html:  "https://ya.ru/",
   143  		Plain: "https://ya.ru/",
   144  	},
   145  	{
   146  		Title: "not italic 4 with links",
   147  		Raw:   "https://ya.ru/",
   148  		Html:  `<a href="https://ya.ru">ya.ru</a>`,
   149  		Plain: "ya.ru",
   150  		Links: []tdproto.MessageLink{
   151  			{
   152  				Pattern: "https://ya.ru/",
   153  				Url:     "https://ya.ru",
   154  				Text:    "ya.ru",
   155  			},
   156  		},
   157  	},
   158  	{
   159  		Title: "bold italic",
   160  		Raw:   "*/123/*",
   161  		Html:  "<b><i>123</i></b>",
   162  		Plain: "123",
   163  	},
   164  	{
   165  		Title: "code block",
   166  		Raw:   "```code```",
   167  		Html:  "<pre>code</pre>",
   168  		Plain: "code",
   169  	},
   170  	{
   171  		Title: "code block multiline",
   172  		Raw:   "```code\nnl```",
   173  		Html:  "<pre>code\nnl</pre>",
   174  		Plain: "code\nnl",
   175  	},
   176  	{
   177  		Title: "code block with newlines",
   178  		Raw:   "```\ncode\nline\n```",
   179  		Html:  "<pre>code\nline</pre>",
   180  		Plain: "code\nline",
   181  	},
   182  	{
   183  		Title: "code block with newlines with spaces",
   184  		Raw:   "``` \ncode\nline\n```",
   185  		Html:  "<pre>code\nline</pre>",
   186  		Plain: "code\nline",
   187  	},
   188  	{
   189  		Title: "code incomplete",
   190  		Raw:   "```code\nnl``",
   191  		Html:  "```code\nnl``",
   192  		Plain: "```code\nnl``",
   193  	},
   194  	{
   195  		Title: "bold italic with spaces",
   196  		Raw:   "123 /4 *5* 6/ 789",
   197  		Html:  "123 <i>4 <b>5</b> 6</i> 789",
   198  		Plain: "123 4 5 6 789",
   199  	},
   200  	{
   201  		Title: "quote",
   202  		Raw:   "> 123\n456",
   203  		Html:  "<blockquote>123</blockquote>\n456",
   204  		Plain: "> 123\n456",
   205  	},
   206  	{
   207  		Title: "quote only",
   208  		Raw:   "> 123",
   209  		Html:  "<blockquote>123</blockquote>\n",
   210  		Plain: "> 123",
   211  	},
   212  	{
   213  		Title: "bold in quote",
   214  		Raw:   "> 12 *3*\n456",
   215  		Html:  "<blockquote>12 <b>3</b></blockquote>\n456",
   216  		Plain: "> 12 3\n456",
   217  	},
   218  	{
   219  		Title: "quote in quote",
   220  		Raw:   "> 3 > 4",
   221  		Html:  "<blockquote>3 &gt; 4</blockquote>\n",
   222  		Plain: "> 3 > 4",
   223  	},
   224  	{
   225  		Title: "not a quote",
   226  		Raw:   "3 > 4",
   227  		Html:  "3 &gt; 4",
   228  		Plain: "3 > 4",
   229  	},
   230  	{
   231  		Title: "quote from new line",
   232  		Raw:   "\n> b",
   233  		Html:  "\n<blockquote>b</blockquote>\n",
   234  	},
   235  	{
   236  		Title: "multiquotes",
   237  		Raw: `> 1
   238  2
   239  > 3
   240  4
   241  > 5
   242  6`,
   243  		Html: `<blockquote>1</blockquote>
   244  2
   245  <blockquote>3</blockquote>
   246  4
   247  <blockquote>5</blockquote>
   248  6`,
   249  	},
   250  	{
   251  		Title: "link only",
   252  		Raw:   "123 https://ya.ru 456",
   253  		Html:  `123 <a href="https://ya.ru">ya.ru</a> 456`,
   254  		Plain: `123 ya.ru 456`,
   255  		Links: []tdproto.MessageLink{
   256  			{
   257  				Pattern: "https://ya.ru",
   258  				Url:     "https://ya.ru",
   259  				Text:    "ya.ru",
   260  			},
   261  		},
   262  	},
   263  	{
   264  		Title: "mailto",
   265  		Raw:   "123 xxx@gmail.com 456",
   266  		Html:  `123 <a href="mailto:xxx@gmail.com">xxx@gmail.com</a> 456`,
   267  		Plain: `123 xxx@gmail.com 456`,
   268  		Links: []tdproto.MessageLink{
   269  			{
   270  				Pattern: "xxx@gmail.com",
   271  				Url:     "mailto:xxx@gmail.com",
   272  				Text:    "xxx@gmail.com",
   273  			},
   274  		},
   275  	},
   276  	{
   277  		Title: "link only with trailing slash",
   278  		Raw:   "123 https://ya.ru/? 456",
   279  		Html:  `123 <a href="https://ya.ru">ya.ru</a> 456`,
   280  		Plain: "123 ya.ru 456",
   281  		Links: []tdproto.MessageLink{
   282  			{
   283  				Pattern: "https://ya.ru/?",
   284  				Url:     "https://ya.ru",
   285  				Text:    "ya.ru",
   286  			},
   287  		},
   288  	},
   289  	{
   290  		Title: "manage.py",
   291  		Raw:   "123 manage.py 456",
   292  		Html:  `123 <a href="http://manage.py">manage.py</a> 456`,
   293  		Plain: "123 manage.py 456",
   294  		Links: []tdproto.MessageLink{
   295  			{
   296  				Pattern: "manage.py",
   297  				Url:     "http://manage.py",
   298  				Text:    "manage.py",
   299  			},
   300  		},
   301  	},
   302  	{
   303  		Title: "tag",
   304  		Raw:   "<br>",
   305  		Html:  "&lt;br&gt;",
   306  		Plain: "<br>",
   307  	},
   308  	{
   309  		Title: "lt",
   310  		Raw:   "<<<<<<",
   311  		Html:  "&lt;&lt;&lt;&lt;&lt;&lt;",
   312  		Plain: "<<<<<<",
   313  	},
   314  	{
   315  		Title: "bolditalic tag",
   316  		Raw:   "<b><i>123</i></b>",
   317  		Html:  "&lt;b&gt;&lt;i&gt;123&lt;/i&gt;&lt;/b&gt;",
   318  		Plain: "<b><i>123</i></b>",
   319  	},
   320  	{
   321  		Title: "bold italic without markup",
   322  		Raw:   "<b>1 <i>2</i> 3</b>",
   323  		Html:  "&lt;b&gt;1 &lt;i&gt;2&lt;/i&gt; 3&lt;/b&gt;",
   324  		Plain: "<b>1 <i>2</i> 3</b>",
   325  	},
   326  	{
   327  		Title: "tag after markup",
   328  		Raw:   "/*6688*/ 3<br>",
   329  		Html:  "<i><b>6688</b></i> 3&lt;br&gt;",
   330  		Plain: "6688 3<br>",
   331  	},
   332  	{
   333  		Title: "bold italic with markup",
   334  		Raw:   "<b>1 <i>2</i> /*6688*/ 3</b>",
   335  		Html:  "&lt;b&gt;1 &lt;i&gt;2&lt;/i&gt; <i><b>6688</b></i> 3&lt;/b&gt;",
   336  		Plain: "<b>1 <i>2</i> 6688 3</b>",
   337  	},
   338  	{
   339  		Title: "nested markup no spaces",
   340  		Raw:   `_1-*2-~34~-6*-7_`,
   341  		Html:  `<u>1-*2-~34~-6*-7</u>`,
   342  		Plain: `1-*2-~34~-6*-7`,
   343  	},
   344  	{
   345  		Title: "date",
   346  		Raw:   "<2000-01-02T10:15:00.000000-0700>",
   347  		Html:  "<time>02.01.00 10:15</time>",
   348  		Plain: "02.01.00 10:15",
   349  	},
   350  	{
   351  		Title: "date in text",
   352  		Raw:   "Тестовая задача с крайним сроком <2020-11-12T13:00:45.795000Z>",
   353  		Plain: "Тестовая задача с крайним сроком 12.11.20 13:00",
   354  	},
   355  	{
   356  		Title: "clear-all",
   357  		Raw:   "_x_ ~y~ *z* /a/ `b` ```c```",
   358  		Plain: "x y z a b c",
   359  	},
   360  	{
   361  		Title: "username",
   362  		Raw:   "aaa @user1_name1 @user2_name2",
   363  		Plain: "aaa @user1_name1 @user2_name2",
   364  	},
   365  	{
   366  		Title: "bold-username",
   367  		Raw:   "aaa *@user1_name1 @user2_name2*",
   368  		Plain: "aaa @user1_name1 @user2_name2",
   369  	},
   370  	{
   371  		Title: "punctuation",
   372  		Raw:   "_123_?",
   373  		Plain: "123?",
   374  	},
   375  	{
   376  		Title: "double",
   377  		Raw:   "_123__ f",
   378  		Html:  "_123__ f",
   379  		Plain: "_123__ f",
   380  	},
   381  	{
   382  		Title: "double-double",
   383  		Raw:   "_123 _ f",
   384  		Html:  "_123 _ f",
   385  		Plain: "_123 _ f",
   386  	},
   387  	{
   388  		Title: "emoji",
   389  		Raw:   "_hey_ *hop😂* _лалалей_",
   390  		Html:  "<u>hey</u> <b>hop😂</b> <u>лалалей</u>",
   391  		Plain: "hey hop😂 лалалей",
   392  	},
   393  	{
   394  		Title: "multi pre",
   395  		Raw:   "``` 1 ```2``` ```3",
   396  		Html:  "<pre>1</pre>2<pre></pre>3",
   397  		Plain: "123",
   398  	},
   399  	{
   400  		Title: "markdown link",
   401  		Raw:   `[ya.ru](https://ya.ru)`,
   402  		Html:  `<a href="https://ya.ru">ya.ru</a>`,
   403  		Plain: "ya.ru",
   404  	},
   405  	{
   406  		Title: "markdown link inside markup",
   407  		Raw:   `*[ya.ru](https://ya.ru)*`,
   408  		Html:  `<b><a href="https://ya.ru">ya.ru</a></b>`,
   409  		Plain: "ya.ru",
   410  	},
   411  	{
   412  		Title: "markdown link inside markup",
   413  		Raw:   `*[github](https://github.com)*`,
   414  		Html:  `<b><a href="https://github.com">github</a></b>`,
   415  		Plain: "github",
   416  	},
   417  	{
   418  		Title: "markdown link with space",
   419  		Raw:   `[ ya.ru ](https://ya.ru)`,
   420  		Html:  `<a href="https://ya.ru">ya.ru</a>`,
   421  		Plain: "ya.ru",
   422  	},
   423  	{
   424  		Title: "markdown link without scheme",
   425  		Raw:   `[ya.ru](ya.ru)`,
   426  		Html:  `[ya.ru](ya.ru)`,
   427  		Plain: `[ya.ru](ya.ru)`,
   428  	},
   429  	{
   430  		Title: "broken markdown link",
   431  		Raw:   `[ya.ru](https://ya.ru`,
   432  		Html:  `[ya.ru](https://ya.ru`,
   433  		Plain: `[ya.ru](https://ya.ru`,
   434  	},
   435  	{
   436  		Title: "markdown link with markup",
   437  		Raw:   `[ya.ru *bold*](https://ya.ru)`,
   438  		Html:  `<a href="https://ya.ru">ya.ru *bold*</a>`,
   439  		Plain: "ya.ru *bold*",
   440  	},
   441  	{
   442  		Title: "markdown link with smile",
   443  		Raw:   `[ =( ](app://path)`,
   444  		Html:  `<a href="app://path">=(</a>`,
   445  		Plain: "=(",
   446  	},
   447  	{
   448  		Title: "empty markdown link",
   449  		Raw:   `[ ](https://ya.ru)`,
   450  		Html:  `[ ](https://ya.ru)`,
   451  		Plain: `[ ](https://ya.ru)`,
   452  	},
   453  	{
   454  		Title: "markdown link with square braces",
   455  		Raw:   `[[x]](app://path)`,
   456  		Html:  `<a href="app://path">[x]</a>`,
   457  		Plain: "[x]",
   458  	},
   459  	{
   460  		Title: "markdown link with one square brace",
   461  		Raw:   `[x]y](app://path)`,
   462  		Html:  `<a href="app://path">x]y</a>`,
   463  		Plain: "x]y",
   464  	},
   465  	{
   466  		Title: "complex message with emoji and markup",
   467  		Raw:   "`branch` ℹ️ result #[15381](https://host/15381)\n\n - ✅ `test:unit` - xxx: #[72964](https://host/72964)",
   468  		Plain: "branch ℹ️ result #15381\n\n - ✅ test:unit - xxx: #72964",
   469  	},
   470  }