github.com/phsym/gomarkdoc@v0.5.4/format/formatcore/base_test.go (about) 1 package formatcore 2 3 import ( 4 "testing" 5 6 "github.com/matryer/is" 7 ) 8 9 func TestPlainText(t *testing.T) { 10 tests := []struct { 11 in, out string 12 }{ 13 { 14 in: "plain text", 15 out: "plain text", 16 }, 17 { 18 in: "[linked](https://foo.bar)", 19 out: "linked", 20 }, 21 { 22 in: "[linked 2](<https://foo.bar>)", 23 out: "linked 2", 24 }, 25 { 26 in: "type [foo](<https://foo.bar>)", 27 out: "type foo", 28 }, 29 { 30 in: "**bold** text", 31 out: "bold text", 32 }, 33 { 34 in: "*italicized* text", 35 out: "italicized text", 36 }, 37 { 38 in: "~~strikethrough~~ text", 39 out: "strikethrough text", 40 }, 41 { 42 in: "paragraph 1\n\nparagraph 2", 43 out: "paragraph 1 paragraph 2", 44 }, 45 { 46 in: "# header\n\nparagraph", 47 out: "header paragraph", 48 }, 49 } 50 51 for _, test := range tests { 52 t.Run(test.in, func(t *testing.T) { 53 is := is.New(t) 54 is.Equal(PlainText(test.in), test.out) // Wrong output for plainText() 55 }) 56 } 57 } 58 59 func TestEscape(t *testing.T) { 60 tests := []struct { 61 in, out string 62 }{ 63 { 64 in: "plain, text.", 65 out: `plain, text.`, 66 }, 67 { 68 in: "**bold** text", 69 out: `\*\*bold\*\* text`, 70 }, 71 { 72 in: "*italicized* text", 73 out: `\*italicized\* text`, 74 }, 75 { 76 in: "~~strikethrough~~ text", 77 out: `\~\~strikethrough\~\~ text`, 78 }, 79 { 80 in: "# header", 81 out: `\# header`, 82 }, 83 { 84 in: "markdown [link](https://foo.bar)", 85 out: `markdown \[link\]\(https://foo.bar\)`, 86 }, 87 { 88 in: "# header then complex URL: http://abc.def/sdfklj/sdf?key=value&special=%323%20sd " + 89 "with http://simple.url and **bold** after", 90 out: `\# header then complex URL: http://abc.def/sdfklj/sdf?key=value&special=%323%20sd ` + 91 `with http://simple.url and \*\*bold\*\* after`, 92 }, 93 } 94 95 for _, test := range tests { 96 t.Run(test.in, func(t *testing.T) { 97 is := is.New(t) 98 is.Equal(Escape(test.in), test.out) // Wrong output for escape() 99 }) 100 } 101 }