How to use Shallow method of td Package

Best Go-testdeep code snippet using td.Shallow

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 "testing"15)16func runMarkdownBlock(input string, extensions int) string {17 htmlFlags := 018 htmlFlags |= HTML_USE_XHTML19 renderer := HtmlRenderer(htmlFlags, "", "")20 return string(Markdown([]byte(input), renderer, extensions))21}22func doTestsBlock(t *testing.T, tests []string, extensions int) {23 // catch and report panics24 var candidate string25 defer func() {26 if err := recover(); err != nil {27 t.Errorf("\npanic while processing [%#v]\n", candidate)28 }29 }()30 for i := 0; i+1 < len(tests); i += 2 {31 input := tests[i]32 candidate = input33 expected := tests[i+1]34 actual := runMarkdownBlock(candidate, extensions)35 if actual != expected {36 t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]",37 candidate, expected, actual)38 }39 // now test every substring to stress test bounds checking40 if !testing.Short() {41 for start := 0; start < len(input); start++ {42 for end := start + 1; end <= len(input); end++ {43 candidate = input[start:end]44 _ = runMarkdownBlock(candidate, extensions)45 }46 }47 }48 }49}50func TestPrefixHeaderNoExtensions(t *testing.T) {51 var tests = []string{52 "# Header 1\n",53 "<h1>Header 1</h1>\n",54 "## Header 2\n",55 "<h2>Header 2</h2>\n",56 "### Header 3\n",57 "<h3>Header 3</h3>\n",58 "#### Header 4\n",59 "<h4>Header 4</h4>\n",60 "##### Header 5\n",61 "<h5>Header 5</h5>\n",62 "###### Header 6\n",63 "<h6>Header 6</h6>\n",64 "####### Header 7\n",65 "<h6># Header 7</h6>\n",66 "#Header 1\n",67 "<h1>Header 1</h1>\n",68 "##Header 2\n",69 "<h2>Header 2</h2>\n",70 "###Header 3\n",71 "<h3>Header 3</h3>\n",72 "####Header 4\n",73 "<h4>Header 4</h4>\n",74 "#####Header 5\n",75 "<h5>Header 5</h5>\n",76 "######Header 6\n",77 "<h6>Header 6</h6>\n",78 "#######Header 7\n",79 "<h6>#Header 7</h6>\n",80 "Hello\n# Header 1\nGoodbye\n",81 "<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",82 "* List\n# Header\n* List\n",83 "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",84 "* List\n#Header\n* List\n",85 "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",86 "* List\n * Nested list\n # Nested header\n",87 "<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +88 "<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",89 }90 doTestsBlock(t, tests, 0)91}92func TestPrefixHeaderSpaceExtension(t *testing.T) {93 var tests = []string{94 "# Header 1\n",95 "<h1>Header 1</h1>\n",96 "## Header 2\n",97 "<h2>Header 2</h2>\n",98 "### Header 3\n",99 "<h3>Header 3</h3>\n",100 "#### Header 4\n",101 "<h4>Header 4</h4>\n",102 "##### Header 5\n",103 "<h5>Header 5</h5>\n",104 "###### Header 6\n",105 "<h6>Header 6</h6>\n",106 "####### Header 7\n",107 "<p>####### Header 7</p>\n",108 "#Header 1\n",109 "<p>#Header 1</p>\n",110 "##Header 2\n",111 "<p>##Header 2</p>\n",112 "###Header 3\n",113 "<p>###Header 3</p>\n",114 "####Header 4\n",115 "<p>####Header 4</p>\n",116 "#####Header 5\n",117 "<p>#####Header 5</p>\n",118 "######Header 6\n",119 "<p>######Header 6</p>\n",120 "#######Header 7\n",121 "<p>#######Header 7</p>\n",122 "Hello\n# Header 1\nGoodbye\n",123 "<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",124 "* List\n# Header\n* List\n",125 "<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",126 "* List\n#Header\n* List\n",127 "<ul>\n<li>List\n#Header</li>\n<li>List</li>\n</ul>\n",128 "* List\n * Nested list\n # Nested header\n",129 "<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +130 "<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",131 }132 doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS)133}134func TestUnderlineHeaders(t *testing.T) {135 var tests = []string{136 "Header 1\n========\n",137 "<h1>Header 1</h1>\n",138 "Header 2\n--------\n",139 "<h2>Header 2</h2>\n",140 "A\n=\n",141 "<h1>A</h1>\n",142 "B\n-\n",143 "<h2>B</h2>\n",144 "Paragraph\nHeader\n=\n",145 "<p>Paragraph</p>\n\n<h1>Header</h1>\n",146 "Header\n===\nParagraph\n",147 "<h1>Header</h1>\n\n<p>Paragraph</p>\n",148 "Header\n===\nAnother header\n---\n",149 "<h1>Header</h1>\n\n<h2>Another header</h2>\n",150 " Header\n======\n",151 "<h1>Header</h1>\n",152 " Code\n========\n",153 "<pre><code>Code\n</code></pre>\n\n<p>========</p>\n",154 "Header with *inline*\n=====\n",155 "<h1>Header with <em>inline</em></h1>\n",156 "* List\n * Sublist\n Not a header\n ------\n",157 "<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header\n------</li>\n</ul></li>\n</ul>\n",158 "Paragraph\n\n\n\n\nHeader\n===\n",159 "<p>Paragraph</p>\n\n<h1>Header</h1>\n",160 "Trailing space \n==== \n\n",161 "<h1>Trailing space</h1>\n",162 "Trailing spaces\n==== \n\n",163 "<h1>Trailing spaces</h1>\n",164 "Double underline\n=====\n=====\n",165 "<h1>Double underline</h1>\n\n<p>=====</p>\n",166 }167 doTestsBlock(t, tests, 0)168}169func TestHorizontalRule(t *testing.T) {170 var tests = []string{171 "-\n",172 "<p>-</p>\n",173 "--\n",174 "<p>--</p>\n",175 "---\n",176 "<hr />\n",177 "----\n",178 "<hr />\n",179 "*\n",180 "<p>*</p>\n",181 "**\n",182 "<p>**</p>\n",183 "***\n",184 "<hr />\n",185 "****\n",186 "<hr />\n",187 "_\n",188 "<p>_</p>\n",189 "__\n",190 "<p>__</p>\n",191 "___\n",192 "<hr />\n",193 "____\n",194 "<hr />\n",195 "-*-\n",196 "<p>-*-</p>\n",197 "- - -\n",198 "<hr />\n",199 "* * *\n",200 "<hr />\n",201 "_ _ _\n",202 "<hr />\n",203 "-----*\n",204 "<p>-----*</p>\n",205 " ------ \n",206 "<hr />\n",207 "Hello\n***\n",208 "<p>Hello</p>\n\n<hr />\n",209 "---\n***\n___\n",210 "<hr />\n\n<hr />\n\n<hr />\n",211 }212 doTestsBlock(t, tests, 0)213}214func TestUnorderedList(t *testing.T) {215 var tests = []string{216 "* Hello\n",217 "<ul>\n<li>Hello</li>\n</ul>\n",218 "* Yin\n* Yang\n",219 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",220 "* Ting\n* Bong\n* Goo\n",221 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",222 "* Yin\n\n* Yang\n",223 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",224 "* Ting\n\n* Bong\n* Goo\n",225 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",226 "+ Hello\n",227 "<ul>\n<li>Hello</li>\n</ul>\n",228 "+ Yin\n+ Yang\n",229 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",230 "+ Ting\n+ Bong\n+ Goo\n",231 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",232 "+ Yin\n\n+ Yang\n",233 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",234 "+ Ting\n\n+ Bong\n+ Goo\n",235 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",236 "- Hello\n",237 "<ul>\n<li>Hello</li>\n</ul>\n",238 "- Yin\n- Yang\n",239 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",240 "- Ting\n- Bong\n- Goo\n",241 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",242 "- Yin\n\n- Yang\n",243 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",244 "- Ting\n\n- Bong\n- Goo\n",245 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",246 "*Hello\n",247 "<p>*Hello</p>\n",248 "* Hello \n",249 "<ul>\n<li>Hello</li>\n</ul>\n",250 "* Hello \n Next line \n",251 "<ul>\n<li>Hello\nNext line</li>\n</ul>\n",252 "Paragraph\n* No linebreak\n",253 "<p>Paragraph\n* No linebreak</p>\n",254 "Paragraph\n\n* Linebreak\n",255 "<p>Paragraph</p>\n\n<ul>\n<li>Linebreak</li>\n</ul>\n",256 "* List\n * Nested list\n",257 "<ul>\n<li>List\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",258 "* List\n\n * Nested list\n",259 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",260 "* List\n Second line\n\n + Nested\n",261 "<ul>\n<li><p>List\nSecond line</p>\n\n<ul>\n<li>Nested</li>\n</ul></li>\n</ul>\n",262 "* List\n + Nested\n\n Continued\n",263 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested</li>\n</ul>\n\n<p>Continued</p></li>\n</ul>\n",264 "* List\n * shallow indent\n",265 "<ul>\n<li>List\n\n<ul>\n<li>shallow indent</li>\n</ul></li>\n</ul>\n",266 "* List\n" +267 " * shallow indent\n" +268 " * part of second list\n" +269 " * still second\n" +270 " * almost there\n" +271 " * third level\n",272 "<ul>\n" +273 "<li>List\n\n" +274 "<ul>\n" +275 "<li>shallow indent</li>\n" +276 "<li>part of second list</li>\n" +277 "<li>still second</li>\n" +278 "<li>almost there\n\n" +279 "<ul>\n" +280 "<li>third level</li>\n" +281 "</ul></li>\n" +282 "</ul></li>\n" +283 "</ul>\n",284 "* List\n extra indent, same paragraph\n",285 "<ul>\n<li>List\n extra indent, same paragraph</li>\n</ul>\n",286 "* List\n\n code block\n",287 "<ul>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ul>\n",288 "* List\n\n code block with spaces\n",289 "<ul>\n<li><p>List</p>\n\n<pre><code> code block with spaces\n</code></pre></li>\n</ul>\n",290 "* List\n\n * sublist\n\n normal text\n\n * another sublist\n",291 "<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",292 }293 doTestsBlock(t, tests, 0)294}295func TestOrderedList(t *testing.T) {296 var tests = []string{297 "1. Hello\n",298 "<ol>\n<li>Hello</li>\n</ol>\n",299 "1. Yin\n2. Yang\n",300 "<ol>\n<li>Yin</li>\n<li>Yang</li>\n</ol>\n",301 "1. Ting\n2. Bong\n3. Goo\n",302 "<ol>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ol>\n",303 "1. Yin\n\n2. Yang\n",304 "<ol>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ol>\n",305 "1. Ting\n\n2. Bong\n3. Goo\n",306 "<ol>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ol>\n",307 "1 Hello\n",308 "<p>1 Hello</p>\n",309 "1.Hello\n",310 "<p>1.Hello</p>\n",311 "1. Hello \n",312 "<ol>\n<li>Hello</li>\n</ol>\n",313 "1. Hello \n Next line \n",314 "<ol>\n<li>Hello\nNext line</li>\n</ol>\n",315 "Paragraph\n1. No linebreak\n",316 "<p>Paragraph\n1. No linebreak</p>\n",317 "Paragraph\n\n1. Linebreak\n",318 "<p>Paragraph</p>\n\n<ol>\n<li>Linebreak</li>\n</ol>\n",319 "1. List\n 1. Nested list\n",320 "<ol>\n<li>List\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",321 "1. List\n\n 1. Nested list\n",322 "<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",323 "1. List\n Second line\n\n 1. Nested\n",324 "<ol>\n<li><p>List\nSecond line</p>\n\n<ol>\n<li>Nested</li>\n</ol></li>\n</ol>\n",325 "1. List\n 1. Nested\n\n Continued\n",326 "<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested</li>\n</ol>\n\n<p>Continued</p></li>\n</ol>\n",327 "1. List\n 1. shallow indent\n",328 "<ol>\n<li>List\n\n<ol>\n<li>shallow indent</li>\n</ol></li>\n</ol>\n",329 "1. List\n" +330 " 1. shallow indent\n" +331 " 2. part of second list\n" +332 " 3. still second\n" +333 " 4. almost there\n" +334 " 1. third level\n",335 "<ol>\n" +336 "<li>List\n\n" +337 "<ol>\n" +338 "<li>shallow indent</li>\n" +339 "<li>part of second list</li>\n" +340 "<li>still second</li>\n" +341 "<li>almost there\n\n" +342 "<ol>\n" +343 "<li>third level</li>\n" +344 "</ol></li>\n" +345 "</ol></li>\n" +346 "</ol>\n",347 "1. List\n extra indent, same paragraph\n",348 "<ol>\n<li>List\n extra indent, same paragraph</li>\n</ol>\n",349 "1. List\n\n code block\n",350 "<ol>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ol>\n",351 "1. List\n\n code block with spaces\n",352 "<ol>\n<li><p>List</p>\n\n<pre><code> code block with spaces\n</code></pre></li>\n</ol>\n",353 "1. List\n * Mixted list\n",354 "<ol>\n<li>List\n\n<ul>\n<li>Mixted list</li>\n</ul></li>\n</ol>\n",355 "1. List\n * Mixed list\n",356 "<ol>\n<li>List\n\n<ul>\n<li>Mixed list</li>\n</ul></li>\n</ol>\n",357 "* Start with unordered\n 1. Ordered\n",358 "<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",359 "* Start with unordered\n 1. Ordered\n",360 "<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",361 "1. numbers\n1. are ignored\n",362 "<ol>\n<li>numbers</li>\n<li>are ignored</li>\n</ol>\n",363 }364 doTestsBlock(t, tests, 0)365}366func TestPreformattedHtml(t *testing.T) {367 var tests = []string{368 "<div></div>\n",369 "<div></div>\n",370 "<div>\n</div>\n",371 "<div>\n</div>\n",372 "<div>\n</div>\nParagraph\n",373 "<p><div>\n</div>\nParagraph</p>\n",374 "<div class=\"foo\">\n</div>\n",375 "<div class=\"foo\">\n</div>\n",376 "<div>\nAnything here\n</div>\n",377 "<div>\nAnything here\n</div>\n",378 "<div>\n Anything here\n</div>\n",379 "<div>\n Anything here\n</div>\n",380 "<div>\nAnything here\n </div>\n",381 "<div>\nAnything here\n </div>\n",382 "<div>\nThis is *not* &proceessed\n</div>\n",383 "<div>\nThis is *not* &proceessed\n</div>\n",384 "<faketag>\n Something\n</faketag>\n",385 "<p><faketag>\n Something\n</faketag></p>\n",386 "<div>\n Something here\n</divv>\n",387 "<p><div>\n Something here\n</divv></p>\n",388 "Paragraph\n<div>\nHere? >&<\n</div>\n",389 "<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div></p>\n",390 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\n",391 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n",392 "Paragraph\n<div>\nHere? >&<\n</div>\nAnd here?\n",393 "<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div>\nAnd here?</p>\n",394 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\nAnd here?\n",395 "<p>Paragraph</p>\n\n<p><div>\nHow about here? &gt;&amp;&lt;\n</div>\nAnd here?</p>\n",396 "Paragraph\n<div>\nHere? >&<\n</div>\n\nAnd here?\n",397 "<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div></p>\n\n<p>And here?</p>\n",398 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\n\nAnd here?\n",399 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",400 }401 doTestsBlock(t, tests, 0)402}403func TestPreformattedHtmlLax(t *testing.T) {404 var tests = []string{405 "Paragraph\n<div>\nHere? >&<\n</div>\n",406 "<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n",407 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\n",408 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n",409 "Paragraph\n<div>\nHere? >&<\n</div>\nAnd here?\n",410 "<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n\n<p>And here?</p>\n",411 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\nAnd here?\n",412 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",413 "Paragraph\n<div>\nHere? >&<\n</div>\n\nAnd here?\n",414 "<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n\n<p>And here?</p>\n",415 "Paragraph\n\n<div>\nHow about here? >&<\n</div>\n\nAnd here?\n",416 "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",417 }418 doTestsBlock(t, tests, EXTENSION_LAX_HTML_BLOCKS)419}420func TestFencedCodeBlock(t *testing.T) {421 var tests = []string{422 "``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",423 "<pre><code class=\"go\">func foo() bool {\n return true;\n}\n</code></pre>\n",424 "``` c\n/* special & char < > \" escaping */\n```\n",425 "<pre><code class=\"c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",426 "``` c\nno *inline* processing ~~of text~~\n```\n",427 "<pre><code class=\"c\">no *inline* processing ~~of text~~\n</code></pre>\n",428 "```\nNo language\n```\n",429 "<pre><code>No language\n</code></pre>\n",430 "``` {ocaml}\nlanguage in braces\n```\n",431 "<pre><code class=\"ocaml\">language in braces\n</code></pre>\n",432 "``` {ocaml} \nwith extra whitespace\n```\n",433 "<pre><code class=\"ocaml\">with extra whitespace\n</code></pre>\n",434 "```{ ocaml }\nwith extra whitespace\n```\n",435 "<pre><code class=\"ocaml\">with extra whitespace\n</code></pre>\n",436 "~ ~~ java\nWith whitespace\n~~~\n",437 "<p>~ ~~ java\nWith whitespace\n~~~</p>\n",438 "~~\nonly two\n~~\n",439 "<p>~~\nonly two\n~~</p>\n",440 "```` python\nextra\n````\n",441 "<pre><code class=\"python\">extra\n</code></pre>\n",442 "~~~ perl\nthree to start, four to end\n~~~~\n",443 "<p>~~~ perl\nthree to start, four to end\n~~~~</p>\n",444 "~~~~ perl\nfour to start, three to end\n~~~\n",445 "<p>~~~~ perl\nfour to start, three to end\n~~~</p>\n",446 "~~~ bash\ntildes\n~~~\n",447 "<pre><code class=\"bash\">tildes\n</code></pre>\n",448 "``` lisp\nno ending\n",449 "<p>``` lisp\nno ending</p>\n",450 "~~~ lisp\nend with language\n~~~ lisp\n",451 "<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",452 "```\nmismatched begin and end\n~~~\n",453 "<p>```\nmismatched begin and end\n~~~</p>\n",454 "~~~\nmismatched begin and end\n```\n",455 "<p>~~~\nmismatched begin and end\n```</p>\n",456 " ``` oz\nleading spaces\n```\n",457 "<pre><code class=\"oz\">leading spaces\n</code></pre>\n",458 " ``` oz\nleading spaces\n ```\n",459 "<pre><code class=\"oz\">leading spaces\n</code></pre>\n",460 " ``` oz\nleading spaces\n ```\n",461 "<pre><code class=\"oz\">leading spaces\n</code></pre>\n",462 "``` oz\nleading spaces\n ```\n",463 "<pre><code class=\"oz\">leading spaces\n</code></pre>\n",464 " ``` oz\nleading spaces\n ```\n",465 "<pre><code>``` oz\n</code></pre>\n\n<p>leading spaces\n ```</p>\n",466 }467 doTestsBlock(t, tests, EXTENSION_FENCED_CODE)468}469func TestTable(t *testing.T) {470 var tests = []string{471 "a | b\n---|---\nc | d\n",472 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n\n" +473 "<tbody>\n<tr>\n<td>c</td>\n<td>d</td>\n</tr>\n</tbody>\n</table>\n",474 "a | b\n---|--\nc | d\n",475 "<p>a | b\n---|--\nc | d</p>\n",476 "|a|b|c|d|\n|----|----|----|---|\n|e|f|g|h|\n",477 "<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" +478 "<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",479 "*a*|__b__|[c](C)|d\n---|---|---|---\ne|f|g|h\n",480 "<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" +481 "<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",482 "a|b|c\n---|---|---\nd|e|f\ng|h\ni|j|k|l|m\nn|o|p\n",483 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" +484 "<tbody>\n<tr>\n<td>d</td>\n<td>e</td>\n<td>f</td>\n</tr>\n\n" +485 "<tr>\n<td>g</td>\n<td>h</td>\n<td></td>\n</tr>\n\n" +486 "<tr>\n<td>i</td>\n<td>j</td>\n<td>k</td>\n</tr>\n\n" +487 "<tr>\n<td>n</td>\n<td>o</td>\n<td>p</td>\n</tr>\n</tbody>\n</table>\n",488 "a|b|c\n---|---|---\n*d*|__e__|f\n",489 "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" +490 "<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",491 "a|b|c|d\n:--|--:|:-:|---\ne|f|g|h\n",492 "<table>\n<thead>\n<tr>\n<th align=\"left\">a</th>\n<th align=\"right\">b</th>\n" +493 "<th align=\"center\">c</th>\n<th>d</th>\n</tr>\n</thead>\n\n" +494 "<tbody>\n<tr>\n<td align=\"left\">e</td>\n<td align=\"right\">f</td>\n" +495 "<td align=\"center\">g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n",496 "a|b|c\n---|---|---\n",497 "<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",498 "a| b|c | d | e\n---|---|---|---|---\nf| g|h | i |j\n",499 "<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" +500 "<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",501 "a|b\\|c|d\n---|---|---\nf|g\\|h|i\n",502 "<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",503 }504 doTestsBlock(t, tests, EXTENSION_TABLES)505}506func TestUnorderedListWith_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {507 var tests = []string{508 "* Hello\n",509 "<ul>\n<li>Hello</li>\n</ul>\n",510 "* Yin\n* Yang\n",511 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",512 "* Ting\n* Bong\n* Goo\n",513 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",514 "* Yin\n\n* Yang\n",515 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",516 "* Ting\n\n* Bong\n* Goo\n",517 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",518 "+ Hello\n",519 "<ul>\n<li>Hello</li>\n</ul>\n",520 "+ Yin\n+ Yang\n",521 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",522 "+ Ting\n+ Bong\n+ Goo\n",523 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",524 "+ Yin\n\n+ Yang\n",525 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",526 "+ Ting\n\n+ Bong\n+ Goo\n",527 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",528 "- Hello\n",529 "<ul>\n<li>Hello</li>\n</ul>\n",530 "- Yin\n- Yang\n",531 "<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",532 "- Ting\n- Bong\n- Goo\n",533 "<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",534 "- Yin\n\n- Yang\n",535 "<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",536 "- Ting\n\n- Bong\n- Goo\n",537 "<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",538 "*Hello\n",539 "<p>*Hello</p>\n",540 "* Hello \n",541 "<ul>\n<li>Hello</li>\n</ul>\n",542 "* Hello \n Next line \n",543 "<ul>\n<li>Hello\nNext line</li>\n</ul>\n",544 "Paragraph\n* No linebreak\n",545 "<p>Paragraph</p>\n\n<ul>\n<li>No linebreak</li>\n</ul>\n",546 "Paragraph\n\n* Linebreak\n",547 "<p>Paragraph</p>\n\n<ul>\n<li>Linebreak</li>\n</ul>\n",548 "* List\n * Nested list\n",549 "<ul>\n<li>List\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",550 "* List\n\n * Nested list\n",551 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",552 "* List\n Second line\n\n + Nested\n",553 "<ul>\n<li><p>List\nSecond line</p>\n\n<ul>\n<li>Nested</li>\n</ul></li>\n</ul>\n",554 "* List\n + Nested\n\n Continued\n",555 "<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested</li>\n</ul>\n\n<p>Continued</p></li>\n</ul>\n",556 "* List\n * shallow indent\n",557 "<ul>\n<li>List\n\n<ul>\n<li>shallow indent</li>\n</ul></li>\n</ul>\n",558 "* List\n" +559 " * shallow indent\n" +560 " * part of second list\n" +561 " * still second\n" +562 " * almost there\n" +563 " * third level\n",564 "<ul>\n" +565 "<li>List\n\n" +566 "<ul>\n" +567 "<li>shallow indent</li>\n" +568 "<li>part of second list</li>\n" +569 "<li>still second</li>\n" +570 "<li>almost there\n\n" +571 "<ul>\n" +572 "<li>third level</li>\n" +573 "</ul></li>\n" +574 "</ul></li>\n" +575 "</ul>\n",576 "* List\n extra indent, same paragraph\n",577 "<ul>\n<li>List\n extra indent, same paragraph</li>\n</ul>\n",578 "* List\n\n code block\n",579 "<ul>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ul>\n",580 "* List\n\n code block with spaces\n",581 "<ul>\n<li><p>List</p>\n\n<pre><code> code block with spaces\n</code></pre></li>\n</ul>\n",582 "* List\n\n * sublist\n\n normal text\n\n * another sublist\n",583 "<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",584 }585 doTestsBlock(t, tests, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)586}587func TestOrderedList_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {588 var tests = []string{589 "1. Hello\n",590 "<ol>\n<li>Hello</li>\n</ol>\n",591 "1. Yin\n2. Yang\n",592 "<ol>\n<li>Yin</li>\n<li>Yang</li>\n</ol>\n",593 "1. Ting\n2. Bong\n3. Goo\n",594 "<ol>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ol>\n",595 "1. Yin\n\n2. Yang\n",596 "<ol>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ol>\n",597 "1. Ting\n\n2. Bong\n3. Goo\n",598 "<ol>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ol>\n",599 "1 Hello\n",600 "<p>1 Hello</p>\n",601 "1.Hello\n",602 "<p>1.Hello</p>\n",603 "1. Hello \n",604 "<ol>\n<li>Hello</li>\n</ol>\n",605 "1. Hello \n Next line \n",606 "<ol>\n<li>Hello\nNext line</li>\n</ol>\n",607 "Paragraph\n1. No linebreak\n",608 "<p>Paragraph</p>\n\n<ol>\n<li>No linebreak</li>\n</ol>\n",609 "Paragraph\n\n1. Linebreak\n",610 "<p>Paragraph</p>\n\n<ol>\n<li>Linebreak</li>\n</ol>\n",611 "1. List\n 1. Nested list\n",612 "<ol>\n<li>List\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",613 "1. List\n\n 1. Nested list\n",614 "<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",615 "1. List\n Second line\n\n 1. Nested\n",616 "<ol>\n<li><p>List\nSecond line</p>\n\n<ol>\n<li>Nested</li>\n</ol></li>\n</ol>\n",617 "1. List\n 1. Nested\n\n Continued\n",618 "<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested</li>\n</ol>\n\n<p>Continued</p></li>\n</ol>\n",619 "1. List\n 1. shallow indent\n",620 "<ol>\n<li>List\n\n<ol>\n<li>shallow indent</li>\n</ol></li>\n</ol>\n",621 "1. List\n" +622 " 1. shallow indent\n" +623 " 2. part of second list\n" +624 " 3. still second\n" +625 " 4. almost there\n" +626 " 1. third level\n",627 "<ol>\n" +628 "<li>List\n\n" +629 "<ol>\n" +630 "<li>shallow indent</li>\n" +631 "<li>part of second list</li>\n" +632 "<li>still second</li>\n" +633 "<li>almost there\n\n" +634 "<ol>\n" +635 "<li>third level</li>\n" +636 "</ol></li>\n" +637 "</ol></li>\n" +638 "</ol>\n",639 "1. List\n extra indent, same paragraph\n",640 "<ol>\n<li>List\n extra indent, same paragraph</li>\n</ol>\n",641 "1. List\n\n code block\n",642 "<ol>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ol>\n",643 "1. List\n\n code block with spaces\n",644 "<ol>\n<li><p>List</p>\n\n<pre><code> code block with spaces\n</code></pre></li>\n</ol>\n",645 "1. List\n * Mixted list\n",646 "<ol>\n<li>List\n\n<ul>\n<li>Mixted list</li>\n</ul></li>\n</ol>\n",647 "1. List\n * Mixed list\n",648 "<ol>\n<li>List\n\n<ul>\n<li>Mixed list</li>\n</ul></li>\n</ol>\n",649 "* Start with unordered\n 1. Ordered\n",650 "<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",651 "* Start with unordered\n 1. Ordered\n",652 "<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",653 "1. numbers\n1. are ignored\n",654 "<ol>\n<li>numbers</li>\n<li>are ignored</li>\n</ol>\n",655 }656 doTestsBlock(t, tests, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)657}658func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {659 var tests = []string{660 "``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",661 "<pre><code class=\"go\">func foo() bool {\n return true;\n}\n</code></pre>\n",662 "``` c\n/* special & char < > \" escaping */\n```\n",663 "<pre><code class=\"c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",664 "``` c\nno *inline* processing ~~of text~~\n```\n",665 "<pre><code class=\"c\">no *inline* processing ~~of text~~\n</code></pre>\n",666 "```\nNo language\n```\n",667 "<pre><code>No language\n</code></pre>\n",668 "``` {ocaml}\nlanguage in braces\n```\n",669 "<pre><code class=\"ocaml\">language in braces\n</code></pre>\n",670 "``` {ocaml} \nwith extra whitespace\n```\n",671 "<pre><code class=\"ocaml\">with extra whitespace\n</code></pre>\n",672 "```{ ocaml }\nwith extra whitespace\n```\n",673 "<pre><code class=\"ocaml\">with extra whitespace\n</code></pre>\n",674 "~ ~~ java\nWith whitespace\n~~~\n",675 "<p>~ ~~ java\nWith whitespace\n~~~</p>\n",676 "~~\nonly two\n~~\n",677 "<p>~~\nonly two\n~~</p>\n",678 "```` python\nextra\n````\n",679 "<pre><code class=\"python\">extra\n</code></pre>\n",680 "~~~ perl\nthree to start, four to end\n~~~~\n",681 "<p>~~~ perl\nthree to start, four to end\n~~~~</p>\n",682 "~~~~ perl\nfour to start, three to end\n~~~\n",683 "<p>~~~~ perl\nfour to start, three to end\n~~~</p>\n",684 "~~~ bash\ntildes\n~~~\n",685 "<pre><code class=\"bash\">tildes\n</code></pre>\n",686 "``` lisp\nno ending\n",687 "<p>``` lisp\nno ending</p>\n",688 "~~~ lisp\nend with language\n~~~ lisp\n",689 "<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",690 "```\nmismatched begin and end\n~~~\n",691 "<p>```\nmismatched begin and end\n~~~</p>\n",692 "~~~\nmismatched begin and end\n```\n",693 "<p>~~~\nmismatched begin and end\n```</p>\n",694 " ``` oz\nleading spaces\n```\n",695 "<pre><code class=\"oz\">leading spaces\n</code></pre>\n",696 " ``` oz\nleading spaces\n ```\n",697 "<pre><code class=\"oz\">leading spaces\n</code></pre>\n",698 " ``` oz\nleading spaces\n ```\n",699 "<pre><code class=\"oz\">leading spaces\n</code></pre>\n",700 "``` oz\nleading spaces\n ```\n",701 "<pre><code class=\"oz\">leading spaces\n</code></pre>\n",702 " ``` oz\nleading spaces\n ```\n",703 "<pre><code>``` oz\n</code></pre>\n\n<p>leading spaces</p>\n\n<pre><code>```\n</code></pre>\n",704 }705 doTestsBlock(t, tests, EXTENSION_FENCED_CODE|EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)706}...

Full Screen

Full Screen

td_shallow_test.go

Source:td_shallow_test.go Github

copy

Full Screen

...9 "testing"10 "github.com/maxatome/go-testdeep/internal/test"11 "github.com/maxatome/go-testdeep/td"12)13func TestShallow(t *testing.T) {14 checkOK(t, nil, nil)15 //16 // Slice17 back := [...]int{1, 2, 3, 1, 2, 3}18 as := back[:3]19 bs := back[3:]20 checkError(t, bs, td.Shallow(back[:]),21 expectedError{22 Message: mustBe("slice pointer mismatch"),23 Path: mustBe("DATA"),24 Got: mustContain("0x"),25 Expected: mustContain("0x"),26 })27 checkOK(t, as, td.Shallow(back[:]))28 checkOK(t, ([]byte)(nil), ([]byte)(nil))29 //30 // Map31 gotMap := map[string]bool{"a": true, "b": false}32 expectedMap := map[string]bool{"a": true, "b": false}33 checkError(t, gotMap, td.Shallow(expectedMap),34 expectedError{35 Message: mustBe("map pointer mismatch"),36 Path: mustBe("DATA"),37 Got: mustContain("0x"),38 Expected: mustContain("0x"),39 })40 expectedMap = gotMap41 checkOK(t, gotMap, td.Shallow(expectedMap))42 checkOK(t, (map[string]bool)(nil), (map[string]bool)(nil))43 //44 // Ptr45 type MyStruct struct {46 val int47 }48 gotPtr := &MyStruct{val: 12}49 expectedPtr := &MyStruct{val: 12}50 checkError(t, gotPtr, td.Shallow(expectedPtr),51 expectedError{52 Message: mustBe("ptr pointer mismatch"),53 Path: mustBe("DATA"),54 Got: mustContain("0x"),55 Expected: mustContain("0x"),56 })57 expectedPtr = gotPtr58 checkOK(t, gotPtr, td.Shallow(expectedPtr))59 checkOK(t, (*MyStruct)(nil), (*MyStruct)(nil))60 //61 // Func62 gotFunc := func(a int) int { return a * 2 }63 expectedFunc := func(a int) int { return a * 2 }64 checkError(t, gotFunc, td.Shallow(expectedFunc),65 expectedError{66 Message: mustBe("func pointer mismatch"),67 Path: mustBe("DATA"),68 Got: mustContain("0x"),69 Expected: mustContain("0x"),70 })71 expectedFunc = gotFunc72 checkOK(t, gotFunc, td.Shallow(expectedFunc))73 checkOK(t, (func(a int) int)(nil), (func(a int) int)(nil))74 //75 // Chan76 gotChan := make(chan int)77 expectedChan := make(chan int)78 checkError(t, gotChan, td.Shallow(expectedChan),79 expectedError{80 Message: mustBe("chan pointer mismatch"),81 Path: mustBe("DATA"),82 Got: mustContain("0x"),83 Expected: mustContain("0x"),84 })85 expectedChan = gotChan86 checkOK(t, gotChan, td.Shallow(expectedChan))87 checkOK(t, (chan int)(nil), (chan int)(nil))88 //89 // String90 backStr := "foobarfoobar!"91 a := backStr[:6]92 b := backStr[6:12]93 checkOK(t, a, td.Shallow(backStr))94 checkOK(t, backStr, td.Shallow(a))95 checkOK(t, b, td.Shallow(backStr[6:7]))96 checkError(t, backStr, td.Shallow(b),97 expectedError{98 Message: mustBe("string pointer mismatch"),99 Path: mustBe("DATA"),100 Got: mustContain("0x"),101 Expected: mustContain("0x"),102 })103 checkError(t, b, td.Shallow(backStr),104 expectedError{105 Message: mustBe("string pointer mismatch"),106 Path: mustBe("DATA"),107 Got: mustContain("0x"),108 Expected: mustContain("0x"),109 })110 //111 // Erroneous mix112 checkError(t, gotMap, td.Shallow(expectedChan),113 expectedError{114 Message: mustBe("bad kind"),115 Path: mustBe("DATA"),116 Got: mustContain("map"),117 Expected: mustContain("chan"),118 })119 //120 // Bad usage121 checkError(t, "never tested",122 td.Shallow(42),123 expectedError{124 Message: mustBe("bad usage of Shallow operator"),125 Path: mustBe("DATA"),126 Summary: mustBe("usage: Shallow(CHANNEL|FUNC|MAP|PTR|SLICE|UNSAFE_PTR|STRING), but received int as 1st parameter"),127 })128 //129 //130 reg := regexp.MustCompile(`^\(map\) 0x[a-f0-9]+\z`)131 if !reg.MatchString(td.Shallow(expectedMap).String()) {132 t.Errorf("Shallow().String() failed\n got: %s\nexpected: %s",133 td.Shallow(expectedMap).String(), reg)134 }135 // Erroneous op136 test.EqualStr(t, td.Shallow(42).String(), "Shallow(<ERROR>)")137}138func TestShallowTypeBehind(t *testing.T) {139 equalTypes(t, td.Shallow(t), nil)140 // Erroneous op141 equalTypes(t, td.Shallow(42), nil)142}...

Full Screen

Full Screen

td_shallow.go

Source:td_shallow.go Github

copy

Full Screen

...10 "unsafe"11 "github.com/maxatome/go-testdeep/internal/ctxerr"12 "github.com/maxatome/go-testdeep/internal/types"13)14type tdShallow struct {15 base16 expectedKind reflect.Kind17 expectedPointer uintptr18 expectedStr string // in reflect.String case, to avoid contents GC19}20var _ TestDeep = &tdShallow{}21func stringPointer(s string) uintptr {22 return (*reflect.StringHeader)(unsafe.Pointer(&s)).Data23}24// summary(Shallow): compares pointers only, not their contents25// input(Shallow): nil,str,slice,map,ptr,chan,func26// Shallow operator compares pointers only, not their contents. It27// applies on channels, functions (with some restrictions), maps,28// pointers, slices and strings.29//30// During a match, the compared data must be the same as expectedPtr31// to succeed.32//33// a, b := 123, 12334// td.Cmp(t, &a, td.Shallow(&a)) // succeeds35// td.Cmp(t, &a, td.Shallow(&b)) // fails even if a == b as &a != &b36//37// back := "foobarfoobar"38// a, b := back[:6], back[6:]39// // a == b but...40// td.Cmp(t, &a, td.Shallow(&b)) // fails41//42// Be careful for slices and strings! Shallow can succeed but the43// slices/strings not be identical because of their different44// lengths. For example:45//46// a := "foobar yes!"47// b := a[:1] // aka "f"48// td.Cmp(t, &a, td.Shallow(&b)) // succeeds as both strings point to the same area, even if len() differ49//50// The same behavior occurs for slices:51//52// a := []int{1, 2, 3, 4, 5, 6}53// b := a[:2] // aka []int{1, 2}54// td.Cmp(t, &a, td.Shallow(&b)) // succeeds as both slices point to the same area, even if len() differ55//56// See also [Ptr].57func Shallow(expectedPtr any) TestDeep {58 vptr := reflect.ValueOf(expectedPtr)59 shallow := tdShallow{60 base: newBase(3),61 expectedKind: vptr.Kind(),62 }63 // Note from reflect documentation:64 // If v's Kind is Func, the returned pointer is an underlying code65 // pointer, but not necessarily enough to identify a single function66 // uniquely. The only guarantee is that the result is zero if and67 // only if v is a nil func Value.68 switch shallow.expectedKind {69 case reflect.Chan,70 reflect.Func,71 reflect.Map,72 reflect.Ptr,73 reflect.Slice,74 reflect.UnsafePointer:75 shallow.expectedPointer = vptr.Pointer()76 case reflect.String:77 shallow.expectedStr = vptr.String()78 shallow.expectedPointer = stringPointer(shallow.expectedStr)79 default:80 shallow.err = ctxerr.OpBadUsage(81 "Shallow", "(CHANNEL|FUNC|MAP|PTR|SLICE|UNSAFE_PTR|STRING)",82 expectedPtr, 1, true)83 }84 return &shallow85}86func (s *tdShallow) Match(ctx ctxerr.Context, got reflect.Value) *ctxerr.Error {87 if s.err != nil {88 return ctx.CollectError(s.err)89 }90 if got.Kind() != s.expectedKind {91 if ctx.BooleanError {92 return ctxerr.BooleanError93 }94 return ctx.CollectError(&ctxerr.Error{95 Message: "bad kind",96 Got: types.RawString(got.Kind().String()),97 Expected: types.RawString(s.expectedKind.String()),98 })99 }100 var ptr uintptr101 // Special case for strings102 if s.expectedKind == reflect.String {103 ptr = stringPointer(got.String())104 } else {105 ptr = got.Pointer()106 }107 if ptr != s.expectedPointer {108 if ctx.BooleanError {109 return ctxerr.BooleanError110 }111 return ctx.CollectError(&ctxerr.Error{112 Message: fmt.Sprintf("%s pointer mismatch", s.expectedKind),113 Got: types.RawString(fmt.Sprintf("0x%x", ptr)),114 Expected: types.RawString(fmt.Sprintf("0x%x", s.expectedPointer)),115 })116 }117 return nil118}119func (s *tdShallow) String() string {120 if s.err != nil {121 return s.stringError()122 }123 return fmt.Sprintf("(%s) 0x%x", s.expectedKind, s.expectedPointer)124}...

Full Screen

Full Screen

Shallow

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := [][]string{4 []string{"1", "2", "3"},5 []string{"4", "5", "6"},6 []string{"7", "8", "9"},7 }8 table := tablewriter.NewWriter(os.Stdout)9 table.SetHeader([]string{"A", "B", "C"})10 table.Render()11}12import (13func main() {14 data := [][]string{15 []string{"1", "2", "3"},16 []string{"4", "5", "6"},17 []string{"7", "8", "9"},18 }19 table := tablewriter.NewWriter(os.Stdout)20 table.SetHeader([]string{"A", "B", "C"})21 table.SetAutoWrapText(false)22 table.Render()23}24import (25func main() {26 data := [][]string{27 []string{"1", "2", "3"},28 []string{"4", "5", "6"},29 []string{"7", "8", "9"},30 }31 table := tablewriter.NewWriter(os.Stdout)32 table.SetHeader([]string{"A", "B", "C"})33 table.SetAutoFormatHeaders(false)34 table.Render()35}

Full Screen

Full Screen

Shallow

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := [][]string{4 []string{"1", "2", "3", "4", "5"},5 []string{"6", "7", "8", "9", "10"},6 []string{"11", "12", "13", "14", "15"},7 []string{"16", "17", "18", "19", "20"},8 []string{"21", "22", "23", "24", "25"},9 }10 table := tablewriter.NewWriter(os.Stdout)11 table.SetHeader([]string{"1", "2", "3", "4", "5"})12 table.SetAlignment(tablewriter.ALIGN_LEFT)13 table.Render()14}15import (16func main() {17 data := [][]string{18 []string{"1", "2", "3", "4", "5"},19 []string{"6", "7", "8", "9", "10"},20 []string{"11", "12", "13", "14", "15"},21 []string{"16", "17", "18", "19", "20"},22 []string{"21", "22", "23", "24", "25"},23 }24 table := tablewriter.NewWriter(os.Stdout)25 table.SetHeader([]string{"1", "2", "3", "4", "

Full Screen

Full Screen

Shallow

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := colly.NewCollector()4 c.OnHTML("td", func(e *colly.HTMLElement) {5 fmt.Println(e.Text)6 })7}

Full Screen

Full Screen

Shallow

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 json := []byte(`{"name":{"first":"Janet","last":"Prichard"},"age":47}`)4 value, dataType, offset, err := jsonparser.Get(json, "name")5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println(string(value), dataType, offset)9}10import (11func main() {12 json := []byte(`{"name":{"first":"Janet","last":"Prichard"},"age":47}`)13 value, dataType, offset, err := jsonparser.Get(json, "age")14 if err != nil {15 fmt.Println(err)16 }17 fmt.Println(string(value), dataType, offset)18}19import (20func main() {21 json := []byte(`{"name":{"first":"Janet","last":"Prichard"},"age":47}`)22 value, dataType, offset, err := jsonparser.Get(json, "name", "first")23 if err != nil {24 fmt.Println(err)25 }26 fmt.Println(string(value), dataType, offset)27}28import (29func main() {30 json := []byte(`{"name":{"first":"Janet","last":"Prichard"},"age":47}`)31 value, dataType, offset, err := jsonparser.Get(json, "name", "last")32 if err != nil {33 fmt.Println(err)34 }35 fmt.Println(string(value), dataType, offset)36}37import (38func main() {39 json := []byte(`{"name":{"first":"Janet","last":"Prichard"},"age":47}`)40 value, dataType, offset, err := jsonparser.Get(json, "name", "first", "last")41 if err != nil {42 fmt.Println(err)43 }44 fmt.Println(string(value), dataType, offset)

Full Screen

Full Screen

Shallow

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := [][]string{4 []string{"1", "2", "3", "4"},5 []string{"5", "6", "7", "8"},6 []string{"9", "10", "11", "12"},7 []string{"13", "14", "15", "16"},8 }9 table := tablewriter.NewWriter(os.Stdout)10 table.SetHeader([]string{"A", "B", "C", "D"})11 table.AppendBulk(data)12 table.Render()13 table.SetRowLine(true)14 table.Render()15 table.SetColumnSeparator("|")16 table.Render()17 table.SetCenterSeparator("*")18 table.Render()19 table.SetBorder(false)20 table.Render()21 table.SetRowSeparator("-")22 table.Render()23 table.SetAutoWrapText(false)24 table.Render()25 table.SetAutoFormatHeaders(false)26 table.Render()27 table.SetHeaderAlignment(tablewriter.ALIGN_RIGHT)28 table.Render()29 table.SetAlignment(tablewriter.ALIGN_RIGHT)30 table.Render()31 table.SetHeaderLine(true)32 table.Render()33 table.SetColumnAlignment([]int{34 })35 table.Render()36 table.SetHeaderLine(false)37 table.SetBorder(true)38 table.SetCenterSeparator("|")39 table.SetColumnSeparator(" ")40 table.SetRowSeparator("-")41 table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)42 table.SetAlignment(tablewriter.ALIGN_LEFT)43 table.SetHeaderLine(true)44 table.SetColumnAlignment([]int{45 })46 table.SetAutoFormatHeaders(true)47 table.SetAutoWrapText(true)48 table.SetAutoFormatHeaders(true)49 table.SetHeader([]string{"A", "B", "C"})50 table.Append([]string{"a", "b", "c"})51 table.Append([]string{"d", "e", "f"})52 table.Append([]string{"g", "h", "i"})53 table.Append([]string{"j", "k", "l"})54 table.Append([]string{"m", "n", "o"})55 table.Append([]string{"p", "q", "

Full Screen

Full Screen

Shallow

Using AI Code Generation

copy

Full Screen

1import (2type td struct {3}4func (t *td) Shallow() interface{} {5 return reflect.New(reflect.TypeOf(t).Elem()).Interface()6}7func main() {8 t1 := &td{1, 2}9 t2 := t1.Shallow().(*td)10 fmt.Println("t1:", t1, *t1)11 fmt.Println("t2:", t2, *t2)12}13t1: &{1 2} {1 2}14t2: &{0 0} {0 0}

Full Screen

Full Screen

Shallow

Using AI Code Generation

copy

Full Screen

1import (2type td struct {3}4func (t td) Shallow() {5 fmt.Println("Shallow")6}7func main() {8 t := td{1}9 pretty.Println(t)10}11import (12type td struct {13}14func (t td) Deep() {15 fmt.Println("Deep")16}17func main() {18 t := td{1}19 pretty.Println(t)20}21import (22type td struct {23}24func (t td) Shallow() {25 fmt.Println("Shallow")26}27func main() {28 t := td{1}29 pretty.Println(t)30}31import (32type td struct {33}34func (t td) Shallow() {35 fmt.Println("Shallow")36}37func main() {38 t := td{1}39 pretty.Println(t)40}41import (42type td struct {43}44func (t td) Shallow() {45 fmt.Println("Shallow")46}47func main() {48 t := td{1}49 pretty.Println(t)50}51import (52type td struct {53}54func (t td) Shallow() {55 fmt.Println("Shallow")56}57func main() {58 t := td{1}59 pretty.Println(t)60}61import (62type td struct {63}64func (t td) Shallow() {65 fmt.Println("Shallow")66}67func main() {68 t := td{1}

Full Screen

Full Screen

Shallow

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Shallow Copy")4 t := time.Now()5 t = t.Add(time.Hour)6 fmt.Println("t:", t)7 fmt.Println("u:", u)8}9import (10func main() {11 fmt.Println("Deep Copy")12 t := time.Now()13 t = t.Add(time.Hour)14 fmt.Println("t:", t)15 fmt.Println("u:", u)16}

Full Screen

Full Screen

Shallow

Using AI Code Generation

copy

Full Screen

1import td "github.com/tdlib/td/telegram"2import "github.com/tdlib/td/tg"3import "github.com/tdlib/td/telegram/query"4func (t *Client) Shallow() {5 t.client.Shallow()6}7import td "github.com/tdlib/td/telegram"8import "github.com/tdlib/td/tg"9import "github.com/tdlib/td/telegram/query"10func (t *Client) GetActiveSessions() {11 t.client.GetActiveSessions()12}13import td "github.com/tdlib/td/telegram"14import "github.com/tdlib/td/tg"15import "github.com/tdlib/td/telegram/query"16func (t *Client) GetConnectedWebsites() {17 t.client.GetConnectedWebsites()18}19import td "github.com/tdlib/td/telegram"20import "github.com/tdlib/td/tg"21import "github.com/tdlib/td/telegram/query"22func (t *Client) DisconnectWebsite() {23 t.client.DisconnectWebsite()24}25import td "github.com/tdlib/td/telegram"26import "github.com/tdlib/td/tg"27import "github.com/tdlib/td/telegram/query"28func (t *Client) DisconnectAllWebsites() {29 t.client.DisconnectAllWebsites()30}

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