How to use TestS method of td Package

Best Go-testdeep code snippet using td.TestS

block_test.go

Source:block_test.go Github

copy

Full Screen

1//2// Blackfriday Markdown Processor3// Available at http://github.com/russross/blackfriday4//5// Copyright © 2011 Russ Ross <russ@russross.com>.6// Distributed under the Simplified BSD License.7// See README.md for details.8//9//10// Unit tests for block parsing11//12package blackfriday13import (14 "strings"15 "testing"16)17func TestPrefixHeaderNoExtensions(t *testing.T) {18 t.Parallel()19 var tests = []string{20 "# Header 1\n",21 "<h1>Header 1</h1>\n",22 "## Header 2\n",23 "<h2>Header 2</h2>\n",24 "### Header 3\n",25 "<h3>Header 3</h3>\n",26 "#### Header 4\n",27 "<h4>Header 4</h4>\n",28 "##### Header 5\n",29 "<h5>Header 5</h5>\n",30 "###### Header 6\n",31 "<h6>Header 6</h6>\n",32 "####### Header 7\n",33 "<h6># Header 7</h6>\n",34 "#Header 1\n",35 "<h1>Header 1</h1>\n",36 "##Header 2\n",37 "<h2>Header 2</h2>\n",38 "###Header 3\n",39 "<h3>Header 3</h3>\n",40 "####Header 4\n",41 "<h4>Header 4</h4>\n",42 "#####Header 5\n",43 "<h5>Header 5</h5>\n",44 "######Header 6\n",45 "<h6>Header 6</h6>\n",46 "#######Header 7\n",47 "<h6>#Header 7</h6>\n",48 "Hello\n# Header 1\nGoodbye\n",49 "<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",50 "* List\n# Header\n* List\n",51 "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",52 "* List\n#Header\n* List\n",53 "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",54 "* List\n * Nested list\n # Nested header\n",55 "<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +56 "<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",57 "#Header 1 \\#\n",58 "<h1>Header 1 #</h1>\n",59 "#Header 1 \\# foo\n",60 "<h1>Header 1 # foo</h1>\n",61 "#Header 1 #\\##\n",62 "<h1>Header 1 ##</h1>\n",63 }64 doTestsBlock(t, tests, 0)65}66func TestPrefixHeaderSpaceExtension(t *testing.T) {67 t.Parallel()68 var tests = []string{69 "# Header 1\n",70 "<h1>Header 1</h1>\n",71 "## Header 2\n",72 "<h2>Header 2</h2>\n",73 "### Header 3\n",74 "<h3>Header 3</h3>\n",75 "#### Header 4\n",76 "<h4>Header 4</h4>\n",77 "##### Header 5\n",78 "<h5>Header 5</h5>\n",79 "###### Header 6\n",80 "<h6>Header 6</h6>\n",81 "####### Header 7\n",82 "<p>####### Header 7</p>\n",83 "#Header 1\n",84 "<p>#Header 1</p>\n",85 "##Header 2\n",86 "<p>##Header 2</p>\n",87 "###Header 3\n",88 "<p>###Header 3</p>\n",89 "####Header 4\n",90 "<p>####Header 4</p>\n",91 "#####Header 5\n",92 "<p>#####Header 5</p>\n",93 "######Header 6\n",94 "<p>######Header 6</p>\n",95 "#######Header 7\n",96 "<p>#######Header 7</p>\n",97 "Hello\n# Header 1\nGoodbye\n",98 "<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",99 "* List\n# Header\n* List\n",100 "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",101 "* List\n#Header\n* List\n",102 "<ul>\n<li>List\n#Header</li>\n<li>List</li>\n</ul>\n",103 "* List\n * Nested list\n # Nested header\n",104 "<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +105 "<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",106 }107 doTestsBlock(t, tests, SpaceHeadings)108}109func TestPrefixHeaderIdExtension(t *testing.T) {110 t.Parallel()111 var tests = []string{112 "# Header 1 {#someid}\n",113 "<h1 id=\"someid\">Header 1</h1>\n",114 "# Header 1 {#someid} \n",115 "<h1 id=\"someid\">Header 1</h1>\n",116 "# Header 1 {#someid}\n",117 "<h1 id=\"someid\">Header 1</h1>\n",118 "# Header 1 {#someid\n",119 "<h1>Header 1 {#someid</h1>\n",120 "# Header 1 {#someid\n",121 "<h1>Header 1 {#someid</h1>\n",122 "# Header 1 {#someid}}\n",123 "<h1 id=\"someid\">Header 1</h1>\n\n<p>}</p>\n",124 "## Header 2 {#someid}\n",125 "<h2 id=\"someid\">Header 2</h2>\n",126 "### Header 3 {#someid}\n",127 "<h3 id=\"someid\">Header 3</h3>\n",128 "#### Header 4 {#someid}\n",129 "<h4 id=\"someid\">Header 4</h4>\n",130 "##### Header 5 {#someid}\n",131 "<h5 id=\"someid\">Header 5</h5>\n",132 "###### Header 6 {#someid}\n",133 "<h6 id=\"someid\">Header 6</h6>\n",134 "####### Header 7 {#someid}\n",135 "<h6 id=\"someid\"># Header 7</h6>\n",136 "# Header 1 # {#someid}\n",137 "<h1 id=\"someid\">Header 1</h1>\n",138 "## Header 2 ## {#someid}\n",139 "<h2 id=\"someid\">Header 2</h2>\n",140 "Hello\n# Header 1\nGoodbye\n",141 "<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",142 "* List\n# Header {#someid}\n* List\n",143 "<ul>\n<li><p>List</p>\n\n<h1 id=\"someid\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",144 "* List\n#Header {#someid}\n* List\n",145 "<ul>\n<li><p>List</p>\n\n<h1 id=\"someid\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",146 "* List\n * Nested list\n # Nested header {#someid}\n",147 "<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +148 "<h1 id=\"someid\">Nested header</h1></li>\n</ul></li>\n</ul>\n",149 }150 doTestsBlock(t, tests, HeadingIDs)151}152func TestPrefixHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {153 t.Parallel()154 var tests = []string{155 "# header 1 {#someid}\n",156 "<h1 id=\"PRE:someid:POST\">header 1</h1>\n",157 "## header 2 {#someid}\n",158 "<h2 id=\"PRE:someid:POST\">header 2</h2>\n",159 "### header 3 {#someid}\n",160 "<h3 id=\"PRE:someid:POST\">header 3</h3>\n",161 "#### header 4 {#someid}\n",162 "<h4 id=\"PRE:someid:POST\">header 4</h4>\n",163 "##### header 5 {#someid}\n",164 "<h5 id=\"PRE:someid:POST\">header 5</h5>\n",165 "###### header 6 {#someid}\n",166 "<h6 id=\"PRE:someid:POST\">header 6</h6>\n",167 "####### header 7 {#someid}\n",168 "<h6 id=\"PRE:someid:POST\"># header 7</h6>\n",169 "# header 1 # {#someid}\n",170 "<h1 id=\"PRE:someid:POST\">header 1</h1>\n",171 "## header 2 ## {#someid}\n",172 "<h2 id=\"PRE:someid:POST\">header 2</h2>\n",173 "* List\n# Header {#someid}\n* List\n",174 "<ul>\n<li><p>List</p>\n\n<h1 id=\"PRE:someid:POST\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",175 "* List\n#Header {#someid}\n* List\n",176 "<ul>\n<li><p>List</p>\n\n<h1 id=\"PRE:someid:POST\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",177 "* List\n * Nested list\n # Nested header {#someid}\n",178 "<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +179 "<h1 id=\"PRE:someid:POST\">Nested header</h1></li>\n</ul></li>\n</ul>\n",180 }181 parameters := HTMLRendererParameters{182 HeadingIDPrefix: "PRE:",183 HeadingIDSuffix: ":POST",184 }185 doTestsParam(t, tests, TestParams{186 extensions: HeadingIDs,187 HTMLFlags: UseXHTML,188 HTMLRendererParameters: parameters,189 })190}191func TestPrefixAutoHeaderIdExtension(t *testing.T) {192 t.Parallel()193 var tests = []string{194 "# Header 1\n",195 "<h1 id=\"header-1\">Header 1</h1>\n",196 "# Header 1 \n",197 "<h1 id=\"header-1\">Header 1</h1>\n",198 "## Header 2\n",199 "<h2 id=\"header-2\">Header 2</h2>\n",200 "### Header 3\n",201 "<h3 id=\"header-3\">Header 3</h3>\n",202 "#### Header 4\n",203 "<h4 id=\"header-4\">Header 4</h4>\n",204 "##### Header 5\n",205 "<h5 id=\"header-5\">Header 5</h5>\n",206 "###### Header 6\n",207 "<h6 id=\"header-6\">Header 6</h6>\n",208 "####### Header 7\n",209 "<h6 id=\"header-7\"># Header 7</h6>\n",210 "Hello\n# Header 1\nGoodbye\n",211 "<p>Hello</p>\n\n<h1 id=\"header-1\">Header 1</h1>\n\n<p>Goodbye</p>\n",212 "* List\n# Header\n* List\n",213 "<ul>\n<li><p>List</p>\n\n<h1 id=\"header\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",214 "* List\n#Header\n* List\n",215 "<ul>\n<li><p>List</p>\n\n<h1 id=\"header\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",216 "* List\n * Nested list\n # Nested header\n",217 "<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +218 "<h1 id=\"nested-header\">Nested header</h1></li>\n</ul></li>\n</ul>\n",219 "# Header\n\n# Header\n",220 "<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n",221 "# Header 1\n\n# Header 1",222 "<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n",223 "# Header\n\n# Header 1\n\n# Header\n\n# Header",224 "<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header</h1>\n\n<h1 id=\"header-1-2\">Header</h1>\n",225 }226 doTestsBlock(t, tests, AutoHeadingIDs)227}228func TestPrefixAutoHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {229 t.Parallel()230 var tests = []string{231 "# Header 1\n",232 "<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n",233 "# Header 1 \n",234 "<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n",235 "## Header 2\n",236 "<h2 id=\"PRE:header-2:POST\">Header 2</h2>\n",237 "### Header 3\n",238 "<h3 id=\"PRE:header-3:POST\">Header 3</h3>\n",239 "#### Header 4\n",240 "<h4 id=\"PRE:header-4:POST\">Header 4</h4>\n",241 "##### Header 5\n",242 "<h5 id=\"PRE:header-5:POST\">Header 5</h5>\n",243 "###### Header 6\n",244 "<h6 id=\"PRE:header-6:POST\">Header 6</h6>\n",245 "####### Header 7\n",246 "<h6 id=\"PRE:header-7:POST\"># Header 7</h6>\n",247 "Hello\n# Header 1\nGoodbye\n",248 "<p>Hello</p>\n\n<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n\n<p>Goodbye</p>\n",249 "* List\n# Header\n* List\n",250 "<ul>\n<li><p>List</p>\n\n<h1 id=\"PRE:header:POST\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",251 "* List\n#Header\n* List\n",252 "<ul>\n<li><p>List</p>\n\n<h1 id=\"PRE:header:POST\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",253 "* List\n * Nested list\n # Nested header\n",254 "<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +255 "<h1 id=\"PRE:nested-header:POST\">Nested header</h1></li>\n</ul></li>\n</ul>\n",256 "# Header\n\n# Header\n",257 "<h1 id=\"PRE:header:POST\">Header</h1>\n\n<h1 id=\"PRE:header-1:POST\">Header</h1>\n",258 "# Header 1\n\n# Header 1",259 "<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n\n<h1 id=\"PRE:header-1-1:POST\">Header 1</h1>\n",260 "# Header\n\n# Header 1\n\n# Header\n\n# Header",261 "<h1 id=\"PRE:header:POST\">Header</h1>\n\n<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n\n<h1 id=\"PRE:header-1-1:POST\">Header</h1>\n\n<h1 id=\"PRE:header-1-2:POST\">Header</h1>\n",262 }263 parameters := HTMLRendererParameters{264 HeadingIDPrefix: "PRE:",265 HeadingIDSuffix: ":POST",266 }267 doTestsParam(t, tests, TestParams{268 extensions: AutoHeadingIDs,269 HTMLFlags: UseXHTML,270 HTMLRendererParameters: parameters,271 })272}273func TestPrefixHeaderLevelOffset(t *testing.T) {274 t.Parallel()275 var offsetTests = []struct {276 offset int277 tests []string278 }{{279 offset: 0,280 tests: []string{281 "# Header 1\n",282 "<h1>Header 1</h1>\n",283 "## Header 2\n",284 "<h2>Header 2</h2>\n",285 "### Header 3\n",286 "<h3>Header 3</h3>\n",287 "#### Header 4\n",288 "<h4>Header 4</h4>\n",289 "##### Header 5\n",290 "<h5>Header 5</h5>\n",291 "###### Header 6\n",292 "<h6>Header 6</h6>\n",293 "####### Header 7\n",294 "<h6># Header 7</h6>\n",295 },296 }, {297 offset: 1,298 tests: []string{299 "# Header 1\n",300 "<h2>Header 1</h2>\n",301 "## Header 2\n",302 "<h3>Header 2</h3>\n",303 "### Header 3\n",304 "<h4>Header 3</h4>\n",305 "#### Header 4\n",306 "<h5>Header 4</h5>\n",307 "##### Header 5\n",308 "<h6>Header 5</h6>\n",309 "###### Header 6\n",310 "<h6>Header 6</h6>\n",311 "####### Header 7\n",312 "<h6># Header 7</h6>\n",313 },314 }, {315 offset: -1,316 tests: []string{317 "# Header 1\n",318 "<h1>Header 1</h1>\n",319 "## Header 2\n",320 "<h1>Header 2</h1>\n",321 "### Header 3\n",322 "<h2>Header 3</h2>\n",323 "#### Header 4\n",324 "<h3>Header 4</h3>\n",325 "##### Header 5\n",326 "<h4>Header 5</h4>\n",327 "###### Header 6\n",328 "<h5>Header 6</h5>\n",329 "####### Header 7\n",330 "<h5># Header 7</h5>\n",331 },332 }}333 for _, offsetTest := range offsetTests {334 offset := offsetTest.offset335 tests := offsetTest.tests336 doTestsParam(t, tests, TestParams{337 HTMLRendererParameters: HTMLRendererParameters{HeadingLevelOffset: offset},338 })339 }340}341func TestPrefixMultipleHeaderExtensions(t *testing.T) {342 t.Parallel()343 var tests = []string{344 "# Header\n\n# Header {#header}\n\n# Header 1",345 "<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n",346 }347 doTestsBlock(t, tests, AutoHeadingIDs|HeadingIDs)348}349func TestUnderlineHeaders(t *testing.T) {350 t.Parallel()351 var tests = []string{352 "Header 1\n========\n",353 "<h1>Header 1</h1>\n",354 "Header 2\n--------\n",355 "<h2>Header 2</h2>\n",356 "A\n=\n",357 "<h1>A</h1>\n",358 "B\n-\n",359 "<h2>B</h2>\n",360 "Paragraph\nHeader\n=\n",361 "<p>Paragraph</p>\n\n<h1>Header</h1>\n",362 "Header\n===\nParagraph\n",363 "<h1>Header</h1>\n\n<p>Paragraph</p>\n",364 "Header\n===\nAnother header\n---\n",365 "<h1>Header</h1>\n\n<h2>Another header</h2>\n",366 " Header\n======\n",367 "<h1>Header</h1>\n",368 " Code\n========\n",369 "<pre><code>Code\n</code></pre>\n\n<p>========</p>\n",370 "Header with *inline*\n=====\n",371 "<h1>Header with <em>inline</em></h1>\n",372 "* List\n * Sublist\n Not a header\n ------\n",373 "<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header\n------</li>\n</ul></li>\n</ul>\n",374 "Paragraph\n\n\n\n\nHeader\n===\n",375 "<p>Paragraph</p>\n\n<h1>Header</h1>\n",376 "Trailing space \n==== \n\n",377 "<h1>Trailing space</h1>\n",378 "Trailing spaces\n==== \n\n",379 "<h1>Trailing spaces</h1>\n",380 "Double underline\n=====\n=====\n",381 "<h1>Double underline</h1>\n\n<p>=====</p>\n",382 }383 doTestsBlock(t, tests, 0)384}385func TestUnderlineHeadersAutoIDs(t *testing.T) {386 t.Parallel()387 var tests = []string{388 "Header 1\n========\n",389 "<h1 id=\"header-1\">Header 1</h1>\n",390 "Header 2\n--------\n",391 "<h2 id=\"header-2\">Header 2</h2>\n",392 "A\n=\n",393 "<h1 id=\"a\">A</h1>\n",394 "B\n-\n",395 "<h2 id=\"b\">B</h2>\n",396 "Paragraph\nHeader\n=\n",397 "<p>Paragraph</p>\n\n<h1 id=\"header\">Header</h1>\n",398 "Header\n===\nParagraph\n",399 "<h1 id=\"header\">Header</h1>\n\n<p>Paragraph</p>\n",400 "Header\n===\nAnother header\n---\n",401 "<h1 id=\"header\">Header</h1>\n\n<h2 id=\"another-header\">Another header</h2>\n",402 " Header\n======\n",403 "<h1 id=\"header\">Header</h1>\n",404 "Header with *inline*\n=====\n",405 "<h1 id=\"header-with-inline\">Header with <em>inline</em></h1>\n",406 "Paragraph\n\n\n\n\nHeader\n===\n",407 "<p>Paragraph</p>\n\n<h1 id=\"header\">Header</h1>\n",408 "Trailing space \n==== \n\n",409 "<h1 id=\"trailing-space\">Trailing space</h1>\n",410 "Trailing spaces\n==== \n\n",411 "<h1 id=\"trailing-spaces\">Trailing spaces</h1>\n",412 "Double underline\n=====\n=====\n",413 "<h1 id=\"double-underline\">Double underline</h1>\n\n<p>=====</p>\n",414 "Header\n======\n\nHeader\n======\n",415 "<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n",416 "Header 1\n========\n\nHeader 1\n========\n",417 "<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n",418 }419 doTestsBlock(t, tests, AutoHeadingIDs)420}421func TestHorizontalRule(t *testing.T) {422 t.Parallel()423 var tests = []string{424 "-\n",425 "<p>-</p>\n",426 "--\n",427 "<p>--</p>\n",428 "---\n",429 "<hr />\n",430 "----\n",431 "<hr />\n",432 "*\n",433 "<p>*</p>\n",434 "**\n",435 "<p>**</p>\n",436 "***\n",437 "<hr />\n",438 "****\n",439 "<hr />\n",440 "_\n",441 "<p>_</p>\n",442 "__\n",443 "<p>__</p>\n",444 "___\n",445 "<hr />\n",446 "____\n",447 "<hr />\n",448 "-*-\n",449 "<p>-*-</p>\n",450 "- - -\n",451 "<hr />\n",452 "* * *\n",453 "<hr />\n",454 "_ _ _\n",455 "<hr />\n",456 "-----*\n",457 "<p>-----*</p>\n",458 " ------ \n",459 "<hr />\n",460 "Hello\n***\n",461 "<p>Hello</p>\n\n<hr />\n",462 "---\n***\n___\n",463 "<hr />\n\n<hr />\n\n<hr />\n",464 }465 doTestsBlock(t, tests, 0)466}467func TestUnorderedList(t *testing.T) {468 t.Parallel()469 var tests = []string{470 "* Hello\n",471 "<ul>\n<li>Hello</li>\n</ul>\n",472 "* Yin\n* Yang\n",473 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",474 "* Ting\n* Bong\n* Goo\n",475 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",476 "* Yin\n\n* Yang\n",477 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",478 "* Ting\n\n* Bong\n* Goo\n",479 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",480 "+ Hello\n",481 "<ul>\n<li>Hello</li>\n</ul>\n",482 "+ Yin\n+ Yang\n",483 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",484 "+ Ting\n+ Bong\n+ Goo\n",485 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",486 "+ Yin\n\n+ Yang\n",487 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",488 "+ Ting\n\n+ Bong\n+ Goo\n",489 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",490 "- Hello\n",491 "<ul>\n<li>Hello</li>\n</ul>\n",492 "- Yin\n- Yang\n",493 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",494 "- Ting\n- Bong\n- Goo\n",495 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",496 "- Yin\n\n- Yang\n",497 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",498 "- Ting\n\n- Bong\n- Goo\n",499 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",500 "*Hello\n",501 "<p>*Hello</p>\n",502 "* Hello \n",503 "<ul>\n<li>Hello</li>\n</ul>\n",504 "* Hello \n Next line \n",505 "<ul>\n<li>Hello\nNext line</li>\n</ul>\n",506 "Paragraph\n* No linebreak\n",507 "<p>Paragraph\n* No linebreak</p>\n",508 "Paragraph\n\n* Linebreak\n",509 "<p>Paragraph</p>\n\n<ul>\n<li>Linebreak</li>\n</ul>\n",510 "* List\n * Nested list\n",511 "<ul>\n<li>List\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",512 "* List\n\n * Nested list\n",513 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",514 "* List\n Second line\n\n + Nested\n",515 "<ul>\n<li><p>List\nSecond line</p>\n\n<ul>\n<li>Nested</li>\n</ul></li>\n</ul>\n",516 "* List\n + Nested\n\n Continued\n",517 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested</li>\n</ul>\n\n<p>Continued</p></li>\n</ul>\n",518 "* List\n * shallow indent\n",519 "<ul>\n<li>List\n\n<ul>\n<li>shallow indent</li>\n</ul></li>\n</ul>\n",520 "* List\n" +521 " * shallow indent\n" +522 " * part of second list\n" +523 " * still second\n" +524 " * almost there\n" +525 " * third level\n",526 "<ul>\n" +527 "<li>List\n\n" +528 "<ul>\n" +529 "<li>shallow indent</li>\n" +530 "<li>part of second list</li>\n" +531 "<li>still second</li>\n" +532 "<li>almost there\n\n" +533 "<ul>\n" +534 "<li>third level</li>\n" +535 "</ul></li>\n" +536 "</ul></li>\n" +537 "</ul>\n",538 "* List\n extra indent, same paragraph\n",539 "<ul>\n<li>List\n extra indent, same paragraph</li>\n</ul>\n",540 "* List\n\n code block\n",541 "<ul>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ul>\n",542 "* List\n\n code block with spaces\n",543 "<ul>\n<li><p>List</p>\n\n<pre><code> code block with spaces\n</code></pre></li>\n</ul>\n",544 "* List\n\n * sublist\n\n normal text\n\n * another sublist\n",545 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>sublist</li>\n</ul>\n\n<p>normal text</p>\n\n<ul>\n<li>another sublist</li>\n</ul></li>\n</ul>\n",546 }547 doTestsBlock(t, tests, 0)548}549func TestOrderedList(t *testing.T) {550 t.Parallel()551 var tests = []string{552 "1. Hello\n",553 "<ol>\n<li>Hello</li>\n</ol>\n",554 "1. Yin\n2. Yang\n",555 "<ol>\n<li>Yin</li>\n<li>Yang</li>\n</ol>\n",556 "1. Ting\n2. Bong\n3. Goo\n",557 "<ol>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ol>\n",558 "1. Yin\n\n2. Yang\n",559 "<ol>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ol>\n",560 "1. Ting\n\n2. Bong\n3. Goo\n",561 "<ol>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ol>\n",562 "1 Hello\n",563 "<p>1 Hello</p>\n",564 "1.Hello\n",565 "<p>1.Hello</p>\n",566 "1. Hello \n",567 "<ol>\n<li>Hello</li>\n</ol>\n",568 "1. Hello \n Next line \n",569 "<ol>\n<li>Hello\nNext line</li>\n</ol>\n",570 "Paragraph\n1. No linebreak\n",571 "<p>Paragraph\n1. No linebreak</p>\n",572 "Paragraph\n\n1. Linebreak\n",573 "<p>Paragraph</p>\n\n<ol>\n<li>Linebreak</li>\n</ol>\n",574 "1. List\n 1. Nested list\n",575 "<ol>\n<li>List\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",576 "1. List\n\n 1. Nested list\n",577 "<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",578 "1. List\n Second line\n\n 1. Nested\n",579 "<ol>\n<li><p>List\nSecond line</p>\n\n<ol>\n<li>Nested</li>\n</ol></li>\n</ol>\n",580 "1. List\n 1. Nested\n\n Continued\n",581 "<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested</li>\n</ol>\n\n<p>Continued</p></li>\n</ol>\n",582 "1. List\n 1. shallow indent\n",583 "<ol>\n<li>List\n\n<ol>\n<li>shallow indent</li>\n</ol></li>\n</ol>\n",584 "1. List\n" +585 " 1. shallow indent\n" +586 " 2. part of second list\n" +587 " 3. still second\n" +588 " 4. almost there\n" +589 " 1. third level\n",590 "<ol>\n" +591 "<li>List\n\n" +592 "<ol>\n" +593 "<li>shallow indent</li>\n" +594 "<li>part of second list</li>\n" +595 "<li>still second</li>\n" +596 "<li>almost there\n\n" +597 "<ol>\n" +598 "<li>third level</li>\n" +599 "</ol></li>\n" +600 "</ol></li>\n" +601 "</ol>\n",602 "1. List\n extra indent, same paragraph\n",603 "<ol>\n<li>List\n extra indent, same paragraph</li>\n</ol>\n",604 "1. List\n\n code block\n",605 "<ol>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ol>\n",606 "1. List\n\n code block with spaces\n",607 "<ol>\n<li><p>List</p>\n\n<pre><code> code block with spaces\n</code></pre></li>\n</ol>\n",608 "1. List\n * Mixted list\n",609 "<ol>\n<li>List\n\n<ul>\n<li>Mixted list</li>\n</ul></li>\n</ol>\n",610 "1. List\n * Mixed list\n",611 "<ol>\n<li>List\n\n<ul>\n<li>Mixed list</li>\n</ul></li>\n</ol>\n",612 "* Start with unordered\n 1. Ordered\n",613 "<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",614 "* Start with unordered\n 1. Ordered\n",615 "<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",616 "1. numbers\n1. are ignored\n",617 "<ol>\n<li>numbers</li>\n<li>are ignored</li>\n</ol>\n",618 }619 doTestsBlock(t, tests, 0)620}621func TestDefinitionList(t *testing.T) {622 t.Parallel()623 var tests = []string{624 "Term 1\n: Definition a\n",625 "<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n</dl>\n",626 "Term 1\n: Definition a \n",627 "<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n</dl>\n",628 "Term 1\n: Definition a\n: Definition b\n",629 "<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n<dd>Definition b</dd>\n</dl>\n",630 "Term 1\n: Definition a\n\nTerm 2\n: Definition b\n",631 "<dl>\n" +632 "<dt>Term 1</dt>\n" +633 "<dd>Definition a</dd>\n" +634 "<dt>Term 2</dt>\n" +635 "<dd>Definition b</dd>\n" +636 "</dl>\n",637 "Term 1\n: Definition a\n\nTerm 2\n: Definition b\n\nTerm 3\n: Definition c\n",638 "<dl>\n" +639 "<dt>Term 1</dt>\n" +640 "<dd>Definition a</dd>\n" +641 "<dt>Term 2</dt>\n" +642 "<dd>Definition b</dd>\n" +643 "<dt>Term 3</dt>\n" +644 "<dd>Definition c</dd>\n" +645 "</dl>\n",646 "Term 1\n: Definition a\n: Definition b\n\nTerm 2\n: Definition c\n",647 "<dl>\n" +648 "<dt>Term 1</dt>\n" +649 "<dd>Definition a</dd>\n" +650 "<dd>Definition b</dd>\n" +651 "<dt>Term 2</dt>\n" +652 "<dd>Definition c</dd>\n" +653 "</dl>\n",654 "Term 1\n\n: Definition a\n\nTerm 2\n\n: Definition b\n",655 "<dl>\n" +656 "<dt>Term 1</dt>\n" +657 "<dd><p>Definition a</p></dd>\n" +658 "<dt>Term 2</dt>\n" +659 "<dd><p>Definition b</p></dd>\n" +660 "</dl>\n",661 "Term 1\n\n: Definition a\n\n: Definition b\n\nTerm 2\n\n: Definition c\n",662 "<dl>\n" +663 "<dt>Term 1</dt>\n" +664 "<dd><p>Definition a</p></dd>\n" +665 "<dd><p>Definition b</p></dd>\n" +666 "<dt>Term 2</dt>\n" +667 "<dd><p>Definition c</p></dd>\n" +668 "</dl>\n",669 "Term 1\n: Definition a\nNext line\n",670 "<dl>\n<dt>Term 1</dt>\n<dd>Definition a\nNext line</dd>\n</dl>\n",671 "Term 1\n: Definition a\n Next line\n",672 "<dl>\n<dt>Term 1</dt>\n<dd>Definition a\nNext line</dd>\n</dl>\n",673 "Term 1\n: Definition a \n Next line \n",674 "<dl>\n<dt>Term 1</dt>\n<dd>Definition a\nNext line</dd>\n</dl>\n",675 "Term 1\n: Definition a\nNext line\n\nTerm 2\n: Definition b",676 "<dl>\n" +677 "<dt>Term 1</dt>\n" +678 "<dd>Definition a\nNext line</dd>\n" +679 "<dt>Term 2</dt>\n" +680 "<dd>Definition b</dd>\n" +681 "</dl>\n",682 "Term 1\n: Definition a\n",683 "<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n</dl>\n",684 "Term 1\n:Definition a\n",685 "<p>Term 1\n:Definition a</p>\n",686 "Term 1\n\n: Definition a\n\nTerm 2\n\n: Definition b\n\nText 1",687 "<dl>\n" +688 "<dt>Term 1</dt>\n" +689 "<dd><p>Definition a</p></dd>\n" +690 "<dt>Term 2</dt>\n" +691 "<dd><p>Definition b</p></dd>\n" +692 "</dl>\n" +693 "\n<p>Text 1</p>\n",694 "Term 1\n\n: Definition a\n\nText 1\n\nTerm 2\n\n: Definition b\n\nText 2",695 "<dl>\n" +696 "<dt>Term 1</dt>\n" +697 "<dd><p>Definition a</p></dd>\n" +698 "</dl>\n" +699 "\n<p>Text 1</p>\n" +700 "\n<dl>\n" +701 "<dt>Term 2</dt>\n" +702 "<dd><p>Definition b</p></dd>\n" +703 "</dl>\n" +704 "\n<p>Text 2</p>\n",705 }706 doTestsBlock(t, tests, DefinitionLists)707}708func TestConsecutiveLists(t *testing.T) {709 t.Parallel()710 var tests = []string{711 "1. Hello\n\n* Hello\n\nTerm 1\n: Definition a\n",712 "<ol>\n<li>Hello</li>\n</ol>\n\n<ul>\n<li>Hello</li>\n</ul>\n\n<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n</dl>\n",713 "1. Not nested\n2. ordered list\n\n\t1. nested\n\t2. ordered list\n\n\t* nested\n\t* unordered list\n* Not nested\n* unordered list",714 "<ol>\n<li><p>Not nested</p></li>\n\n<li><p>ordered list</p>\n\n<ol>\n<li>nested</li>\n<li>ordered list</li>\n</ol>\n\n<ul>\n<li>nested</li>\n<li>unordered list</li>\n</ul></li>\n</ol>\n\n<ul>\n<li>Not nested</li>\n<li>unordered list</li>\n</ul>\n",715 }716 doTestsBlock(t, tests, DefinitionLists)717}718func TestPreformattedHtml(t *testing.T) {719 t.Parallel()720 var tests = []string{721 "<div></div>\n",722 "<div></div>\n",723 "<div>\n</div>\n",724 "<div>\n</div>\n",725 "<div>\n</div>\nParagraph\n",726 "<p><div>\n</div>\nParagraph</p>\n",727 "<div class=\"foo\">\n</div>\n",728 "<div class=\"foo\">\n</div>\n",729 "<div>\nAnything here\n</div>\n",730 "<div>\nAnything here\n</div>\n",731 "<div>\n Anything here\n</div>\n",732 "<div>\n Anything here\n</div>\n",733 "<div>\nAnything here\n </div>\n",734 "<div>\nAnything here\n </div>\n",735 "<div>\nThis is *not* &proceessed\n</div>\n",736 "<div>\nThis is *not* &proceessed\n</div>\n",737 "<faketag>\n Something\n</faketag>\n",738 "<p><faketag>\n Something\n</faketag></p>\n",739 "<div>\n Something here\n</divv>\n",740 "<p><div>\n Something here\n</divv></p>\n",741 "Paragraph\n<div>\nHere? >&<\n</div>\n",742 "<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div></p>\n",743 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\n",744 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n",745 "Paragraph\n<div>\nHere? >&<\n</div>\nAnd here?\n",746 "<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div>\nAnd here?</p>\n",747 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\nAnd here?\n",748 "<p>Paragraph</p>\n\n<p><div>\nHow about here? &gt;&amp;&lt;\n</div>\nAnd here?</p>\n",749 "Paragraph\n<div>\nHere? >&<\n</div>\n\nAnd here?\n",750 "<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div></p>\n\n<p>And here?</p>\n",751 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\n\nAnd here?\n",752 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",753 }754 doTestsBlock(t, tests, 0)755}756func TestPreformattedHtmlLax(t *testing.T) {757 t.Parallel()758 var tests = []string{759 "Paragraph\n<div>\nHere? >&<\n</div>\n",760 "<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n",761 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\n",762 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n",763 "Paragraph\n<div>\nHere? >&<\n</div>\nAnd here?\n",764 "<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n\n<p>And here?</p>\n",765 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\nAnd here?\n",766 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",767 "Paragraph\n<div>\nHere? >&<\n</div>\n\nAnd here?\n",768 "<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n\n<p>And here?</p>\n",769 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\n\nAnd here?\n",770 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",771 }772 doTestsBlock(t, tests, LaxHTMLBlocks)773}774func TestFencedCodeBlock(t *testing.T) {775 t.Parallel()776 var tests = []string{777 "``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",778 "<pre><code class=\"language-go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",779 "``` go foo bar\nfunc foo() bool {\n\treturn true;\n}\n```\n",780 "<pre><code class=\"language-go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",781 "``` c\n/* special & char < > \" escaping */\n```\n",782 "<pre><code class=\"language-c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",783 "``` c\nno *inline* processing ~~of text~~\n```\n",784 "<pre><code class=\"language-c\">no *inline* processing ~~of text~~\n</code></pre>\n",785 "```\nNo language\n```\n",786 "<pre><code>No language\n</code></pre>\n",787 "``` {ocaml}\nlanguage in braces\n```\n",788 "<pre><code class=\"language-ocaml\">language in braces\n</code></pre>\n",789 "``` {ocaml} \nwith extra whitespace\n```\n",790 "<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",791 "```{ ocaml }\nwith extra whitespace\n```\n",792 "<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",793 "~ ~~ java\nWith whitespace\n~~~\n",794 "<p>~ ~~ java\nWith whitespace\n~~~</p>\n",795 "~~\nonly two\n~~\n",796 "<p>~~\nonly two\n~~</p>\n",797 "```` python\nextra\n````\n",798 "<pre><code class=\"language-python\">extra\n</code></pre>\n",799 "~~~ perl\nthree to start, four to end\n~~~~\n",800 "<p>~~~ perl\nthree to start, four to end\n~~~~</p>\n",801 "~~~~ perl\nfour to start, three to end\n~~~\n",802 "<p>~~~~ perl\nfour to start, three to end\n~~~</p>\n",803 "~~~ bash\ntildes\n~~~\n",804 "<pre><code class=\"language-bash\">tildes\n</code></pre>\n",805 "``` lisp\nno ending\n",806 "<p>``` lisp\nno ending</p>\n",807 "~~~ lisp\nend with language\n~~~ lisp\n",808 "<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",809 "```\nmismatched begin and end\n~~~\n",810 "<p>```\nmismatched begin and end\n~~~</p>\n",811 "~~~\nmismatched begin and end\n```\n",812 "<p>~~~\nmismatched begin and end\n```</p>\n",813 " ``` oz\nleading spaces\n```\n",814 "<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",815 " ``` oz\nleading spaces\n ```\n",816 "<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",817 " ``` oz\nleading spaces\n ```\n",818 "<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",819 "``` oz\nleading spaces\n ```\n",820 "<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",821 " ``` oz\nleading spaces\n ```\n",822 "<pre><code>``` oz\n</code></pre>\n\n<p>leading spaces\n ```</p>\n",823 "Bla bla\n\n``` oz\ncode blocks breakup paragraphs\n```\n\nBla Bla\n",824 "<p>Bla bla</p>\n\n<pre><code class=\"language-oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>Bla Bla</p>\n",825 "Some text before a fenced code block\n``` oz\ncode blocks breakup paragraphs\n```\nAnd some text after a fenced code block",826 "<p>Some text before a fenced code block</p>\n\n<pre><code class=\"language-oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>And some text after a fenced code block</p>\n",827 "`",828 "<p>`</p>\n",829 "Bla bla\n\n``` oz\ncode blocks breakup paragraphs\n```\n\nBla Bla\n\n``` oz\nmultiple code blocks work okay\n```\n\nBla Bla\n",830 "<p>Bla bla</p>\n\n<pre><code class=\"language-oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>Bla Bla</p>\n\n<pre><code class=\"language-oz\">multiple code blocks work okay\n</code></pre>\n\n<p>Bla Bla</p>\n",831 "Some text before a fenced code block\n``` oz\ncode blocks breakup paragraphs\n```\nSome text in between\n``` oz\nmultiple code blocks work okay\n```\nAnd some text after a fenced code block",832 "<p>Some text before a fenced code block</p>\n\n<pre><code class=\"language-oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>Some text in between</p>\n\n<pre><code class=\"language-oz\">multiple code blocks work okay\n</code></pre>\n\n<p>And some text after a fenced code block</p>\n",833 "```\n[]:()\n```\n",834 "<pre><code>[]:()\n</code></pre>\n",835 "```\n[]:()\n[]:)\n[]:(\n[]:x\n[]:testing\n[:testing\n\n[]:\nlinebreak\n[]()\n\n[]:\n[]()\n```",836 "<pre><code>[]:()\n[]:)\n[]:(\n[]:x\n[]:testing\n[:testing\n\n[]:\nlinebreak\n[]()\n\n[]:\n[]()\n</code></pre>\n",837 }838 doTestsBlock(t, tests, FencedCode)839}840func TestFencedCodeInsideBlockquotes(t *testing.T) {841 t.Parallel()842 cat := func(s ...string) string { return strings.Join(s, "\n") }843 var tests = []string{844 cat("> ```go",845 "package moo",846 "",847 "```",848 ""),849 `<blockquote>850<pre><code class="language-go">package moo851</code></pre>852</blockquote>853`,854 // -------------------------------------------855 cat("> foo",856 "> ",857 "> ```go",858 "package moo",859 "```",860 "> ",861 "> goo.",862 ""),863 `<blockquote>864<p>foo</p>865<pre><code class="language-go">package moo866</code></pre>867<p>goo.</p>868</blockquote>869`,870 // -------------------------------------------871 cat("> foo",872 "> ",873 "> quote",874 "continues",875 "```",876 ""),877 `<blockquote>878<p>foo</p>879<p>quote880continues881` + "```" + `</p>882</blockquote>883`,884 // -------------------------------------------885 cat("> foo",886 "> ",887 "> ```go",888 "package moo",889 "```",890 "> ",891 "> goo.",892 "> ",893 "> ```go",894 "package zoo",895 "```",896 "> ",897 "> woo.",898 ""),899 `<blockquote>900<p>foo</p>901<pre><code class="language-go">package moo902</code></pre>903<p>goo.</p>904<pre><code class="language-go">package zoo905</code></pre>906<p>woo.</p>907</blockquote>908`,909 }910 // These 2 alternative forms of blockquoted fenced code blocks should produce same output.911 forms := [2]string{912 cat("> plain quoted text",913 "> ```fenced",914 "code",915 " with leading single space correctly preserved",916 "okay",917 "```",918 "> rest of quoted text"),919 cat("> plain quoted text",920 "> ```fenced",921 "> code",922 "> with leading single space correctly preserved",923 "> okay",924 "> ```",925 "> rest of quoted text"),926 }927 want := `<blockquote>928<p>plain quoted text</p>929<pre><code class="language-fenced">code930 with leading single space correctly preserved931okay932</code></pre>933<p>rest of quoted text</p>934</blockquote>935`936 tests = append(tests, forms[0], want)937 tests = append(tests, forms[1], want)938 doTestsBlock(t, tests, FencedCode)939}940func TestTable(t *testing.T) {941 t.Parallel()942 var tests = []string{943 "a | b\n---|---\nc | d\n",944 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n\n" +945 "<tbody>\n<tr>\n<td>c</td>\n<td>d</td>\n</tr>\n</tbody>\n</table>\n",946 "a | b\n---|--\nc | d\n",947 "<p>a | b\n---|--\nc | d</p>\n",948 "|a|b|c|d|\n|----|----|----|---|\n|e|f|g|h|\n",949 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n<th>d</th>\n</tr>\n</thead>\n\n" +950 "<tbody>\n<tr>\n<td>e</td>\n<td>f</td>\n<td>g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n",951 "*a*|__b__|[c](C)|d\n---|---|---|---\ne|f|g|h\n",952 "<table>\n<thead>\n<tr>\n<th><em>a</em></th>\n<th><strong>b</strong></th>\n<th><a href=\"C\">c</a></th>\n<th>d</th>\n</tr>\n</thead>\n\n" +953 "<tbody>\n<tr>\n<td>e</td>\n<td>f</td>\n<td>g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n",954 "a|b|c\n---|---|---\nd|e|f\ng|h\ni|j|k|l|m\nn|o|p\n",955 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" +956 "<tbody>\n<tr>\n<td>d</td>\n<td>e</td>\n<td>f</td>\n</tr>\n\n" +957 "<tr>\n<td>g</td>\n<td>h</td>\n<td></td>\n</tr>\n\n" +958 "<tr>\n<td>i</td>\n<td>j</td>\n<td>k</td>\n</tr>\n\n" +959 "<tr>\n<td>n</td>\n<td>o</td>\n<td>p</td>\n</tr>\n</tbody>\n</table>\n",960 "a|b|c\n---|---|---\n*d*|__e__|f\n",961 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" +962 "<tbody>\n<tr>\n<td><em>d</em></td>\n<td><strong>e</strong></td>\n<td>f</td>\n</tr>\n</tbody>\n</table>\n",963 "a|b|c|d\n:--|--:|:-:|---\ne|f|g|h\n",964 "<table>\n<thead>\n<tr>\n<th align=\"left\">a</th>\n<th align=\"right\">b</th>\n" +965 "<th align=\"center\">c</th>\n<th>d</th>\n</tr>\n</thead>\n\n" +966 "<tbody>\n<tr>\n<td align=\"left\">e</td>\n<td align=\"right\">f</td>\n" +967 "<td align=\"center\">g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n",968 "a|b|c\n---|---|---\n",969 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n<tbody>\n</tbody>\n</table>\n",970 "a| b|c | d | e\n---|---|---|---|---\nf| g|h | i |j\n",971 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n<th>d</th>\n<th>e</th>\n</tr>\n</thead>\n\n" +972 "<tbody>\n<tr>\n<td>f</td>\n<td>g</td>\n<td>h</td>\n<td>i</td>\n<td>j</td>\n</tr>\n</tbody>\n</table>\n",973 "a|b\\|c|d\n---|---|---\nf|g\\|h|i\n",974 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b|c</th>\n<th>d</th>\n</tr>\n</thead>\n\n<tbody>\n<tr>\n<td>f</td>\n<td>g|h</td>\n<td>i</td>\n</tr>\n</tbody>\n</table>\n",975 }976 doTestsBlock(t, tests, Tables)977}978func TestUnorderedListWith_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {979 t.Parallel()980 var tests = []string{981 "* Hello\n",982 "<ul>\n<li>Hello</li>\n</ul>\n",983 "* Yin\n* Yang\n",984 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",985 "* Ting\n* Bong\n* Goo\n",986 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",987 "* Yin\n\n* Yang\n",988 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",989 "* Ting\n\n* Bong\n* Goo\n",990 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",991 "+ Hello\n",992 "<ul>\n<li>Hello</li>\n</ul>\n",993 "+ Yin\n+ Yang\n",994 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",995 "+ Ting\n+ Bong\n+ Goo\n",996 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",997 "+ Yin\n\n+ Yang\n",998 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",999 "+ Ting\n\n+ Bong\n+ Goo\n",1000 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",1001 "- Hello\n",1002 "<ul>\n<li>Hello</li>\n</ul>\n",1003 "- Yin\n- Yang\n",1004 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",1005 "- Ting\n- Bong\n- Goo\n",1006 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",1007 "- Yin\n\n- Yang\n",1008 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",1009 "- Ting\n\n- Bong\n- Goo\n",1010 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",1011 "*Hello\n",1012 "<p>*Hello</p>\n",1013 "* Hello \n",1014 "<ul>\n<li>Hello</li>\n</ul>\n",1015 "* Hello \n Next line \n",1016 "<ul>\n<li>Hello\nNext line</li>\n</ul>\n",1017 "Paragraph\n* No linebreak\n",1018 "<p>Paragraph</p>\n\n<ul>\n<li>No linebreak</li>\n</ul>\n",1019 "Paragraph\n\n* Linebreak\n",1020 "<p>Paragraph</p>\n\n<ul>\n<li>Linebreak</li>\n</ul>\n",1021 "* List\n * Nested list\n",1022 "<ul>\n<li>List\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",1023 "* List\n\n * Nested list\n",1024 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",1025 "* List\n Second line\n\n + Nested\n",1026 "<ul>\n<li><p>List\nSecond line</p>\n\n<ul>\n<li>Nested</li>\n</ul></li>\n</ul>\n",1027 "* List\n + Nested\n\n Continued\n",1028 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested</li>\n</ul>\n\n<p>Continued</p></li>\n</ul>\n",1029 "* List\n * shallow indent\n",1030 "<ul>\n<li>List\n\n<ul>\n<li>shallow indent</li>\n</ul></li>\n</ul>\n",1031 "* List\n" +1032 " * shallow indent\n" +1033 " * part of second list\n" +1034 " * still second\n" +1035 " * almost there\n" +1036 " * third level\n",1037 "<ul>\n" +1038 "<li>List\n\n" +1039 "<ul>\n" +1040 "<li>shallow indent</li>\n" +1041 "<li>part of second list</li>\n" +1042 "<li>still second</li>\n" +1043 "<li>almost there\n\n" +1044 "<ul>\n" +1045 "<li>third level</li>\n" +1046 "</ul></li>\n" +1047 "</ul></li>\n" +1048 "</ul>\n",1049 "* List\n extra indent, same paragraph\n",1050 "<ul>\n<li>List\n extra indent, same paragraph</li>\n</ul>\n",1051 "* List\n\n code block\n",1052 "<ul>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ul>\n",1053 "* List\n\n code block with spaces\n",1054 "<ul>\n<li><p>List</p>\n\n<pre><code> code block with spaces\n</code></pre></li>\n</ul>\n",1055 "* List\n\n * sublist\n\n normal text\n\n * another sublist\n",1056 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>sublist</li>\n</ul>\n\n<p>normal text</p>\n\n<ul>\n<li>another sublist</li>\n</ul></li>\n</ul>\n",1057 }1058 doTestsBlock(t, tests, NoEmptyLineBeforeBlock)1059}1060func TestOrderedList_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {1061 t.Parallel()1062 var tests = []string{1063 "1. Hello\n",1064 "<ol>\n<li>Hello</li>\n</ol>\n",1065 "1. Yin\n2. Yang\n",1066 "<ol>\n<li>Yin</li>\n<li>Yang</li>\n</ol>\n",1067 "1. Ting\n2. Bong\n3. Goo\n",1068 "<ol>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ol>\n",1069 "1. Yin\n\n2. Yang\n",1070 "<ol>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ol>\n",1071 "1. Ting\n\n2. Bong\n3. Goo\n",1072 "<ol>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ol>\n",1073 "1 Hello\n",1074 "<p>1 Hello</p>\n",1075 "1.Hello\n",1076 "<p>1.Hello</p>\n",1077 "1. Hello \n",1078 "<ol>\n<li>Hello</li>\n</ol>\n",1079 "1. Hello \n Next line \n",1080 "<ol>\n<li>Hello\nNext line</li>\n</ol>\n",1081 "Paragraph\n1. No linebreak\n",1082 "<p>Paragraph</p>\n\n<ol>\n<li>No linebreak</li>\n</ol>\n",1083 "Paragraph\n\n1. Linebreak\n",1084 "<p>Paragraph</p>\n\n<ol>\n<li>Linebreak</li>\n</ol>\n",1085 "1. List\n 1. Nested list\n",1086 "<ol>\n<li>List\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",1087 "1. List\n\n 1. Nested list\n",1088 "<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",1089 "1. List\n Second line\n\n 1. Nested\n",1090 "<ol>\n<li><p>List\nSecond line</p>\n\n<ol>\n<li>Nested</li>\n</ol></li>\n</ol>\n",1091 "1. List\n 1. Nested\n\n Continued\n",1092 "<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested</li>\n</ol>\n\n<p>Continued</p></li>\n</ol>\n",1093 "1. List\n 1. shallow indent\n",1094 "<ol>\n<li>List\n\n<ol>\n<li>shallow indent</li>\n</ol></li>\n</ol>\n",1095 "1. List\n" +1096 " 1. shallow indent\n" +1097 " 2. part of second list\n" +1098 " 3. still second\n" +1099 " 4. almost there\n" +1100 " 1. third level\n",1101 "<ol>\n" +1102 "<li>List\n\n" +1103 "<ol>\n" +1104 "<li>shallow indent</li>\n" +1105 "<li>part of second list</li>\n" +1106 "<li>still second</li>\n" +1107 "<li>almost there\n\n" +1108 "<ol>\n" +1109 "<li>third level</li>\n" +1110 "</ol></li>\n" +1111 "</ol></li>\n" +1112 "</ol>\n",1113 "1. List\n extra indent, same paragraph\n",1114 "<ol>\n<li>List\n extra indent, same paragraph</li>\n</ol>\n",1115 "1. List\n\n code block\n",1116 "<ol>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ol>\n",1117 "1. List\n\n code block with spaces\n",1118 "<ol>\n<li><p>List</p>\n\n<pre><code> code block with spaces\n</code></pre></li>\n</ol>\n",1119 "1. List\n * Mixted list\n",1120 "<ol>\n<li>List\n\n<ul>\n<li>Mixted list</li>\n</ul></li>\n</ol>\n",1121 "1. List\n * Mixed list\n",1122 "<ol>\n<li>List\n\n<ul>\n<li>Mixed list</li>\n</ul></li>\n</ol>\n",1123 "* Start with unordered\n 1. Ordered\n",1124 "<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",1125 "* Start with unordered\n 1. Ordered\n",1126 "<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",1127 "1. numbers\n1. are ignored\n",1128 "<ol>\n<li>numbers</li>\n<li>are ignored</li>\n</ol>\n",1129 }1130 doTestsBlock(t, tests, NoEmptyLineBeforeBlock)1131}1132func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {1133 t.Parallel()1134 var tests = []string{1135 "``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",1136 "<pre><code class=\"language-go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",1137 "``` go foo bar\nfunc foo() bool {\n\treturn true;\n}\n```\n",1138 "<pre><code class=\"language-go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",1139 "``` c\n/* special & char < > \" escaping */\n```\n",1140 "<pre><code class=\"language-c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",1141 "``` c\nno *inline* processing ~~of text~~\n```\n",1142 "<pre><code class=\"language-c\">no *inline* processing ~~of text~~\n</code></pre>\n",1143 "```\nNo language\n```\n",1144 "<pre><code>No language\n</code></pre>\n",1145 "``` {ocaml}\nlanguage in braces\n```\n",1146 "<pre><code class=\"language-ocaml\">language in braces\n</code></pre>\n",1147 "``` {ocaml} \nwith extra whitespace\n```\n",1148 "<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",1149 "```{ ocaml }\nwith extra whitespace\n```\n",1150 "<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",1151 "~ ~~ java\nWith whitespace\n~~~\n",1152 "<p>~ ~~ java\nWith whitespace\n~~~</p>\n",1153 "~~\nonly two\n~~\n",1154 "<p>~~\nonly two\n~~</p>\n",1155 "```` python\nextra\n````\n",1156 "<pre><code class=\"language-python\">extra\n</code></pre>\n",1157 "~~~ perl\nthree to start, four to end\n~~~~\n",1158 "<p>~~~ perl\nthree to start, four to end\n~~~~</p>\n",1159 "~~~~ perl\nfour to start, three to end\n~~~\n",1160 "<p>~~~~ perl\nfour to start, three to end\n~~~</p>\n",1161 "~~~ bash\ntildes\n~~~\n",1162 "<pre><code class=\"language-bash\">tildes\n</code></pre>\n",1163 "``` lisp\nno ending\n",1164 "<p>``` lisp\nno ending</p>\n",1165 "~~~ lisp\nend with language\n~~~ lisp\n",1166 "<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",1167 "```\nmismatched begin and end\n~~~\n",1168 "<p>```\nmismatched begin and end\n~~~</p>\n",1169 "~~~\nmismatched begin and end\n```\n",1170 "<p>~~~\nmismatched begin and end\n```</p>\n",1171 " ``` oz\nleading spaces\n```\n",1172 "<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",1173 " ``` oz\nleading spaces\n ```\n",1174 "<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",1175 " ``` oz\nleading spaces\n ```\n",1176 "<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",1177 "``` oz\nleading spaces\n ```\n",1178 "<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",1179 " ``` oz\nleading spaces\n ```\n",1180 "<pre><code>``` oz\n</code></pre>\n\n<p>leading spaces</p>\n\n<pre><code>```\n</code></pre>\n",1181 }1182 doTestsBlock(t, tests, FencedCode|NoEmptyLineBeforeBlock)1183}1184func TestListWithFencedCodeBlock(t *testing.T) {1185 t.Parallel()1186 var tests = []string{1187 "1. one\n\n ```\n code\n ```\n\n2. two\n",1188 "<ol>\n<li><p>one</p>\n\n<pre><code>code\n</code></pre></li>\n\n<li><p>two</p></li>\n</ol>\n",1189 // https://github.com/russross/blackfriday/issues/2391190 "1. one\n\n ```\n - code\n ```\n\n2. two\n",1191 "<ol>\n<li><p>one</p>\n\n<pre><code>- code\n</code></pre></li>\n\n<li><p>two</p></li>\n</ol>\n",1192 }1193 doTestsBlock(t, tests, FencedCode)1194}1195func TestListWithMalformedFencedCodeBlock(t *testing.T) {1196 t.Parallel()1197 // Ensure that in the case of an unclosed fenced code block in a list,1198 // no source gets ommitted (even if it is malformed).1199 // See russross/blackfriday#372 for context.1200 var tests = []string{1201 "1. one\n\n ```\n code\n\n2. two\n",1202 "<ol>\n<li>one\n```\ncode\n2. two</li>\n</ol>\n",1203 "1. one\n\n ```\n - code\n\n2. two\n",1204 "<ol>\n<li>one\n```\n- code\n2. two</li>\n</ol>\n",1205 }1206 doTestsBlock(t, tests, FencedCode)1207}1208func TestListWithFencedCodeBlockNoExtensions(t *testing.T) {1209 t.Parallel()1210 // If there is a fenced code block in a list, and FencedCode is not set,1211 // lists should be processed normally.1212 var tests = []string{1213 "1. one\n\n ```\n code\n ```\n\n2. two\n",1214 "<ol>\n<li><p>one</p>\n\n<p><code>\ncode\n</code></p></li>\n\n<li><p>two</p></li>\n</ol>\n",1215 "1. one\n\n ```\n - code\n ```\n\n2. two\n",1216 "<ol>\n<li><p>one</p>\n\n<p>```</p>\n\n<ul>\n<li>code\n```</li>\n</ul></li>\n\n<li><p>two</p></li>\n</ol>\n",1217 }1218 doTestsBlock(t, tests, 0)1219}1220func TestTitleBlock_EXTENSION_TITLEBLOCK(t *testing.T) {1221 t.Parallel()1222 var tests = []string{1223 "% Some title\n" +1224 "% Another title line\n" +1225 "% Yep, more here too\n",1226 "<h1 class=\"title\">" +1227 "Some title\n" +1228 "Another title line\n" +1229 "Yep, more here too" +1230 "</h1>\n",1231 }1232 doTestsBlock(t, tests, Titleblock)1233}1234func TestBlockComments(t *testing.T) {1235 t.Parallel()1236 var tests = []string{1237 "Some text\n\n<!-- comment -->\n",1238 "<p>Some text</p>\n\n<!-- comment -->\n",1239 "Some text\n\n<!--\n\nmultiline\ncomment\n-->\n",1240 "<p>Some text</p>\n\n<!--\n\nmultiline\ncomment\n-->\n",1241 "Some text\n\n<!--\n\n<div><p>Commented</p>\n<span>html</span></div>\n-->\n",1242 "<p>Some text</p>\n\n<!--\n\n<div><p>Commented</p>\n<span>html</span></div>\n-->\n",1243 }1244 doTestsBlock(t, tests, 0)1245}1246func TestTOC(t *testing.T) {1247 t.Parallel()1248 var tests = []string{1249 "# Title\n\n##Subtitle1\n\n##Subtitle2",1250 //"<nav>\n<ul>\n<li><a href=\"#toc_0\">Title</a>\n<ul>\n<li><a href=\"#toc_1\">Subtitle1</a></li>\n<li><a href=\"#toc_2\">Subtitle2</a></li>\n</ul></li>\n</ul>\n</nav>\n\n<h1 id=\"toc_0\">Title</h1>\n\n<h2 id=\"toc_1\">Subtitle1</h2>\n\n<h2 id=\"toc_2\">Subtitle2</h2>\n",1251 `<nav>1252<ul>1253<li><a href="#toc_0">Title</a>1254<ul>1255<li><a href="#toc_1">Subtitle1</a></li>1256<li><a href="#toc_2">Subtitle2</a></li>1257</ul></li>1258</ul>1259</nav>1260<h1 id="toc_0">Title</h1>1261<h2 id="toc_1">Subtitle1</h2>1262<h2 id="toc_2">Subtitle2</h2>1263`,1264 "# Title\n\n##Subtitle\n\n#Title2",1265 //"<nav>\n<ul>\n<li><a href=\"#toc_0\">Title</a>\n<ul>\n<li><a href=\"#toc_1\">Subtitle</a></li>\n</ul></li>\n<li><a href=\"#toc_2\">Title2</a></li>\n</ul>\n</nav>\n\n<h1 id=\"toc_0\">Title</h1>\n\n<h2 id=\"toc_1\">Subtitle</h2>\n\n<h1 id=\"toc_2\">Title2</h1>\n",1266 `<nav>1267<ul>1268<li><a href="#toc_0">Title</a>1269<ul>1270<li><a href="#toc_1">Subtitle</a></li>1271</ul></li>1272<li><a href="#toc_2">Title2</a></li>1273</ul>1274</nav>1275<h1 id="toc_0">Title</h1>1276<h2 id="toc_1">Subtitle</h2>1277<h1 id="toc_2">Title2</h1>1278`,1279 "## Subtitle\n\n# Title",1280 `<nav>1281<ul>1282<li>1283<ul>1284<li><a href="#toc_0">Subtitle</a></li>1285</ul></li>1286<li><a href="#toc_1">Title</a></li>1287</ul>1288</nav>1289<h2 id="toc_0">Subtitle</h2>1290<h1 id="toc_1">Title</h1>1291`,1292 "# Title 1\n\n## Subtitle 1\n\n### Subsubtitle 1\n\n# Title 2\n\n### Subsubtitle 2",1293 `<nav>1294<ul>1295<li><a href="#toc_0">Title 1</a>1296<ul>1297<li><a href="#toc_1">Subtitle 1</a>1298<ul>1299<li><a href="#toc_2">Subsubtitle 1</a></li>1300</ul></li>1301</ul></li>1302<li><a href="#toc_3">Title 2</a>1303<ul>1304<li>1305<ul>1306<li><a href="#toc_4">Subsubtitle 2</a></li>1307</ul></li>1308</ul></li>1309</ul>1310</nav>1311<h1 id="toc_0">Title 1</h1>1312<h2 id="toc_1">Subtitle 1</h2>1313<h3 id="toc_2">Subsubtitle 1</h3>1314<h1 id="toc_3">Title 2</h1>1315<h3 id="toc_4">Subsubtitle 2</h3>1316`,1317 "# Title with `code`",1318 `<nav>1319<ul>1320<li><a href="#toc_0">Title with <code>code</code></a></li>1321</ul>1322</nav>1323<h1 id="toc_0">Title with <code>code</code></h1>1324`,1325 // Trigger empty TOC1326 "#",1327 "",1328 }1329 doTestsParam(t, tests, TestParams{1330 HTMLFlags: UseXHTML | TOC,1331 })1332}1333func TestCompletePage(t *testing.T) {1334 t.Parallel()1335 var tests = []string{1336 "*foo*",1337 `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">1338<html xmlns="http://www.w3.org/1999/xhtml">1339<head>1340 <title></title>1341 <meta name="GENERATOR" content="Blackfriday Markdown Processor v2.0" />1342 <meta charset="utf-8" />1343</head>1344<body>1345<p><em>foo</em></p>1346</body>1347</html>1348`,1349 }1350 doTestsParam(t, tests, TestParams{HTMLFlags: UseXHTML | CompletePage})1351}1352func TestIsFenceLine(t *testing.T) {1353 t.Parallel()1354 tests := []struct {1355 data []byte1356 infoRequested bool1357 wantEnd int1358 wantMarker string1359 wantInfo string1360 }{1361 {1362 data: []byte("```"),1363 wantEnd: 3,1364 wantMarker: "```",1365 },1366 {1367 data: []byte("```\nstuff here\n"),1368 wantEnd: 4,1369 wantMarker: "```",1370 },1371 {1372 data: []byte("```\nstuff here\n"),1373 infoRequested: true,1374 wantEnd: 4,1375 wantMarker: "```",1376 },1377 {1378 data: []byte("stuff here\n```\n"),1379 wantEnd: 0,1380 },1381 {1382 data: []byte("```"),1383 infoRequested: true,1384 wantEnd: 3,1385 wantMarker: "```",1386 },1387 {1388 data: []byte("``` go"),1389 infoRequested: true,1390 wantEnd: 6,1391 wantMarker: "```",1392 wantInfo: "go",1393 },1394 {1395 data: []byte("``` go foo bar"),1396 infoRequested: true,1397 wantEnd: 14,1398 wantMarker: "```",1399 wantInfo: "go foo bar",1400 },1401 {1402 data: []byte("``` go foo bar "),1403 infoRequested: true,1404 wantEnd: 16,1405 wantMarker: "```",1406 wantInfo: "go foo bar",1407 },1408 }1409 for _, test := range tests {1410 var info *string1411 if test.infoRequested {1412 info = new(string)1413 }1414 end, marker := isFenceLine(test.data, info, "```")1415 if got, want := end, test.wantEnd; got != want {1416 t.Errorf("got end %v, want %v", got, want)1417 }1418 if got, want := marker, test.wantMarker; got != want {1419 t.Errorf("got marker %q, want %q", got, want)1420 }1421 if test.infoRequested {1422 if got, want := *info, test.wantInfo; got != want {1423 t.Errorf("got info string %q, want %q", got, want)1424 }1425 }1426 }1427}...

Full Screen

Full Screen

combinator_test.go

Source:combinator_test.go Github

copy

Full Screen

1package combinator2import (3 "testing"4)5func TestCombinator(t *testing.T) {6 type Data struct {7 Color string8 Number int9 Enabled bool10 // DataTests ignore this field11 Untouched bool12 }13 type DataTests struct {14 Color []string15 Number []int16 Enabled []bool17 // DataTests ignore this field18 Untouched []bool19 }20 td := DataTests{21 Color: []string{"red", "green", "blue"},22 Number: []int{0, 1},23 Enabled: []bool{false, true},24 // DataTests ignore this field25 Untouched: []bool{},26 }27 tdl := len(td.Color) * len(td.Number) * len(td.Enabled)28 // initialize check matrix29 matrix := map[string]map[int]map[bool]bool{}30 for ci := 0; ci < len(td.Color); ci++ {31 matrix[td.Color[ci]] = map[int]map[bool]bool{}32 for ni := 0; ni < len(td.Number); ni++ {33 matrix[td.Color[ci]][td.Number[ni]] = map[bool]bool{}34 for bi := 0; bi < len(td.Enabled); bi++ {35 matrix[td.Color[ci]][td.Number[ni]][td.Enabled[bi]] = false36 }37 }38 }39 var data []Data40 err := Generate(&data, td)41 if err != nil {42 t.Fatalf("unexpected error: %v", err)43 }44 if len(data) != tdl {45 t.Errorf("expected %d permutations, got %d", tdl, len(data))46 }47 for _, v := range data {48 // fmt.Println(i, v)49 cmatrix, ok := matrix[v.Color]50 if !ok {51 t.Errorf("unexpected value %s", v.Color)52 continue53 }54 nmatrix, ok := cmatrix[v.Number]55 if !ok {56 t.Errorf("unexpected value %s %d", v.Color, v.Number)57 continue58 }59 _, ok = nmatrix[v.Enabled]60 if !ok {61 t.Errorf("unexpected value %s %d %v", v.Color, v.Number, v.Enabled)62 continue63 }64 // flag combination as found65 matrix[v.Color][v.Number][v.Enabled] = true66 }67 // check all combinations have been found68 for ck, cv := range matrix {69 for nk, nv := range cv {70 for bk, bv := range nv {71 if !bv {72 t.Errorf("combination not found: %s %d %v", ck, nk, bk)73 }74 }75 }76 }77}78func TestConstValue(t *testing.T) {79 type Data struct {80 Number int81 Enabled bool82 }83 type DataTests struct {84 Number []int85 Enabled bool86 }87 td := DataTests{88 Number: []int{0, 1},89 Enabled: true,90 }91 var data []Data92 err := Generate(&data, td)93 if err != nil {94 t.Fatalf("unexpected error: %v", err)95 }96 for _, v := range data {97 if !v.Enabled {98 t.Fatalf("expected enabled to be set to true")99 }100 }101}102func TestUnmatchedField(t *testing.T) {103 type Data struct {104 Number int105 }106 type DataTests struct {107 Number []int108 // Data does not actually contain this field109 Unmatched []bool110 }111 td := DataTests{112 Number: []int{0, 1},113 // Data does not actually contain this field114 Unmatched: []bool{false},115 }116 var data []Data117 err := Generate(&data, td)118 if err == nil {119 t.Errorf("expected error for unmatched fields in data, got nil")120 }121}122func TestInvalidType(t *testing.T) {123 td := struct {124 Number []int125 }{}126 var s string127 err := Generate(s, td)128 if err == nil {129 t.Errorf("expected error for non-pointer type, got nil")130 }131 err = Generate(&s, td)132 if err == nil {133 t.Errorf("expected error for invalid type, got nil")134 }135 err = Generate(&[]string{}, "")136 if err == nil {137 t.Errorf("expected error for invalid type, got nil")138 }139}...

Full Screen

Full Screen

speedtest.go

Source:speedtest.go Github

copy

Full Screen

1package main2import (3 "fmt"4 "html/template"5 "log"6 "math"7 "os"8 "runtime/debug"9 "sync"10 "time"11)12type SpeedTest struct {13 TestFunc func()14 ItemsDefinition string15 OperationDefinition string16 DurationsNs []int6417}18//MeasureDurations runs function f, returns time.Duration of execution or error19func (test *SpeedTest) MeasureDurations(times int) (err error) {20 defer func() {21 if err := recover(); err != nil {22 log.Printf("Error: %v\n %v\n", err, debug.Stack())23 }24 }()25 var wg sync.WaitGroup26 for i := 0; i < times; i++ {27 wg.Add(1)28 startT := time.Now()29 go func() {30 defer wg.Done()31 test.TestFunc()32 }()33 wg.Wait()34 stopT := time.Now()35 test.DurationsNs = append(test.DurationsNs, stopT.Sub(startT).Nanoseconds())36 }37 return38}39func (test SpeedTest) MinNs() (minNs int64) {40 for _, durNs := range test.DurationsNs {41 if durNs < minNs {42 minNs = durNs43 }44 }45 return46}47func (test SpeedTest) MaxNs() (maxNs int64) {48 for _, durNs := range test.DurationsNs {49 if durNs > maxNs {50 maxNs = durNs51 }52 }53 return54}55func (test SpeedTest) SumNs() (sumNs int64) {56 for _, durNs := range test.DurationsNs {57 sumNs += durNs58 }59 return60}61func (test SpeedTest) OpCostNs() (ns float64) {62 if lenDur := len(test.DurationsNs); lenDur > 0 {63 ns = math.Floor(float64(test.SumNs())/float64(TestQty*lenDur)*100) / 10064 }65 return66}67func (test SpeedTest) String() string {68 return fmt.Sprintf(`Structure: %v . Operation: %v69Durations = %v70Sum duration = %v. 71Operation cost: ns/op = %v72`, test.ItemsDefinition, test.OperationDefinition,73 test.DurationsNs, test.SumNs(), test.OpCostNs())74}75type SpeedTests []SpeedTest76func (tests SpeedTests) Len() int { return len(tests) }77func (tests SpeedTests) Swap(i, j int) { tests[i], tests[j] = tests[j], tests[i] }78func (tests SpeedTests) Less(i, j int) bool { return tests[i].SumNs() < tests[j].SumNs() }79const htmlTmplt = `<table>80<tr><th>Structure</th><th>Operation</th><th>Summary Duration(Ns)</th><th><th>Op Cost(ns)</th></tr>81{{with .Tests}}{{range .}}<tr>82 <td><pre>{{.ItemsDefinition}}</pre></td><td><pre>{{.OperationDefinition}}</pre></td><td>{{.SumNs}}</td>83 <td>{{.OpCostNs}}ns</td>84 </tr>{{end}}{{end}}85</table>86`87func (tests SpeedTests) HTML() {88 t := template.New("HtmlReport")89 if t, err := t.Parse(htmlTmplt); err != nil {90 log.Printf("Error %v", err)91 } else {92 if err := t.Execute(os.Stdout, struct{ Tests SpeedTests }{Tests: tests}); err != nil {93 log.Printf("Error %v", err)94 }95 }96 return97}...

Full Screen

Full Screen

TestS

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 t.TestS()4}5import "fmt"6func main() {7 t.TestT()8}9import "fmt"10func main() {11 t.TestU()12}13import "fmt"14func main() {15 t.TestV()16}17import "fmt"18func main() {19 t.TestW()20}21import "fmt"22func main() {23 t.TestX()24}25import "fmt"26func main() {27 t.TestY()28}29import "fmt"30func main() {31 t.TestZ()32}33import "fmt"34func main() {35 t.TestAA()36}37import "fmt"38func main() {39 t.TestAB()40}41import "fmt"42func main() {43 t.TestAC()44}45import "fmt"46func main() {47 t.TestAD()48}49import "fmt"50func main() {

Full Screen

Full Screen

TestS

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 t.TestS()4}5import "fmt"6func main() {7 t.Test()8}9import "fmt"10func main() {11 t.Test()12}13import "fmt"14func main() {15 t.TestS()16}17import "fmt"18func main() {19 t.Test()20}21import "fmt"22func main() {23 t.TestS()24}25import "fmt"26func main() {27 t.Test()28}29import "fmt"30func main() {31 t.TestS()32}33import "fmt"34func main() {35 t.Test()36}37import "fmt"38func main() {39 t.TestS()40}41import "fmt"42func main() {43 t.Test()44}45import "fmt"46func main() {47 t.TestS()48}49import "fmt"50func main() {51 t.Test()52}

Full Screen

Full Screen

TestS

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 t := testpkg.NewTD()4 t.TestS()5}6In this tutorial, we have learned how to create and use packages in Go. We have also seen how to import packages in Go. We have also seen how to use a package in a file without importing it in that file. Go package is a very important concept in Go. It is very easy to creat

Full Screen

Full Screen

TestS

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 t := td.TD{}4 t.TestS()5 fmt.Println("Hello World")6}7import (8func main() {9 t := td.TD{}10 t.TestM()11 fmt.Println("Hello World")12}13import (14func main() {15 t := td.TD{}16 t.TestL()17 fmt.Println("Hello World")18}19import _ "github.com/abc

Full Screen

Full Screen

TestS

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 t := test.Td{}4 t.TestS()5}6import (7func main() {8 t := test.Td{}9 t.TestS()10}11import (12func main() {13 t := test.Td{}14 t.TestS()15}16import (17func main() {18 t := test.Td{}19 t.TestS()20}21import (

Full Screen

Full Screen

TestS

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td.TestS()4 fmt.Println("Hello, playground")5}6import (7type Test struct {8}9func (t Test) TestS() {10 fmt.Println("TestS")11}

Full Screen

Full Screen

TestS

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/GoLangTutorials/2/2.go"3func main() {4 t.TestS()5 fmt.Println("Hello World!")6}7import "fmt"8import "github.com/GoLangTutorials/2/2.go"9func main() {10 t.TestS()11 fmt.Println("Hello World!")12}13import "fmt"14import "github.com/GoLangTutorials/2/2.go"15func main() {16 t.TestS()17 fmt.Println("Hello World!")18}19import "fmt"20import "github.com/GoLangTutorials/2/2.go"21func main() {22 t.TestS()23 fmt.Println("Hello World!")24}25import "fmt"26import "github.com/GoLangTutorials/2/2.go"27func main() {28 t.TestS()29 fmt.Println("Hello World!")30}31import "fmt"32import "github.com/GoLangTutorials/2/2.go"33func main() {34 t.TestS()35 fmt.Println("Hello World!")36}37import "fmt"38import "github.com/GoLangTutorials/2/2.go"39func main() {40 t.TestS()41 fmt.Println("Hello World!")42}43import "fmt"44import "github.com/GoLangTutorials/2/2.go"45func main() {46 t.TestS()47 fmt.Println("Hello World!")48}

Full Screen

Full Screen

TestS

Using AI Code Generation

copy

Full Screen

1import (2func main() {3t.TestS()4fmt.Println(t.a)5}6import "fmt"7type Employee struct {8}9func main() {10 fmt.Println(e1)11 fmt.Println(e1)12 e2 := Employee{"Sourav", 35, 6000}13 fmt.Println(e2)14}15{ 0 0}16{Sachin 34 5000}17{Sourav 35 6000}18import (19func main() {20 rand.Seed(time.Now().UnixNano())21 randNum := rand.Intn(10) + 122 fmt.Println("Guess a number between 1 and 10")23 fmt.Scan(&guess)24 if guess == randNum {25 fmt.Println("You guessed it!")26 } else {27 fmt.Println("Sorry, you guessed wrong. The number was", randNum)28 }29}

Full Screen

Full Screen

TestS

Using AI Code Generation

copy

Full Screen

1import "TD"2func main() {3 td := td.TD{}4 td.TestS()5}6The import statement can be used to import multiple packages. The following is the syntax of the import statement:7import "package_name"8The import statement can also be used to import multiple packages in a single line. The following is the syntax of the import statement:9import ("package_name1" "package_name2")10The following program imports multiple packages in a single line:11import ("fmt" "TD")12func main() {13 td := td.TD{}14 td.TestS()15 fmt.Println("Hello World")16}17The import statement can also be used to import multiple packages with different names. The following is the syntax of the import statement:18import (19The following program imports multiple packages with different names in a single line:20import (21func main() {22 td := td.TD{}23 td.TestS()24 fmt.Println(time.Now())25 fmt.Println(strings.ToLower("Hello World"))26}27The import statement can also be used to import a package with a different name. The following is the syntax of the import statement:28import "package_name" "package_name" as "new_package_name"29The following program imports a package with a different name in a single line:

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Go-testdeep automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful