1
16
17 package templates
18
19 import (
20 "testing"
21 )
22
23 func TestLongDescMarkdown(t *testing.T) {
24 tests := []struct {
25 desc string
26 in string
27 out string
28 }{
29 {
30 desc: "Empty input produces empty output",
31 in: "",
32 out: "",
33 },
34 {
35 desc: "Single line text is preserved as is",
36 in: "Some text",
37 out: "Some text",
38 },
39 {
40 desc: "Consecutive new lines are combined into a single paragraph",
41 in: "Line1\nLine2",
42 out: "Line1 Line2",
43 },
44 {
45 desc: "Two paragraphs",
46 in: "Line1\n\nLine2",
47 out: "Line1\n\n Line2",
48 },
49 {
50 desc: "Leading and trailing spaces are stripped (single line)",
51 in: "\t \nThe text line \n \t",
52 out: "The text line",
53 },
54 {
55 desc: "Leading and trailing spaces are stripped (multi line)",
56 in: "\t \nLine1\nLine2 \n \t",
57 out: "Line1 Line2",
58 },
59 {
60 desc: "List Items with order",
61 in: "Title\n\n1. First item\n2. Second item\n\nSome text",
62 out: "Title\n\n 1. First item\n 2. Second item\n\n Some text",
63 },
64 {
65 desc: "Multi lines without order",
66 in: "\t\t\t\t\tDescriptions.\n\n * Item.\n * Item2.",
67 out: "Descriptions.\n \n * Item.\n * Item2.",
68 },
69 {
70 desc: "With code block",
71 in: "Line1\n\n\t<type>.<fieldName>[.<fieldName>]\n\nLine2",
72 out: "Line1\n\n <type>.<fieldName>[.<fieldName>]\n \n Line2",
73 },
74 }
75
76 for _, test := range tests {
77 t.Run(test.desc, func(t *testing.T) {
78 got := LongDesc(test.in)
79 if got != test.out {
80 t.Errorf("expected(%d):\n%s\n=====\ngot(%d):\n%s\n", len(test.out), test.out, len(got), got)
81 }
82 })
83 }
84 }
85
86 func TestMultiLongDescInvocation(t *testing.T) {
87 tests := []struct {
88 desc string
89 in string
90 out string
91 }{
92 {
93 desc: "Empty input produces empty output",
94 in: "",
95 out: "",
96 },
97 {
98 desc: "Single line text is preserved as is",
99 in: "Some text",
100 out: "Some text",
101 },
102 {
103 desc: "Consecutive new lines are combined into a single paragraph",
104 in: "Line1\nLine2",
105 out: "Line1 Line2",
106 },
107 {
108 desc: "Two paragraphs",
109 in: "Line1\n\nLine2",
110 out: "Line1\n\n Line2",
111 },
112 {
113 desc: "Leading and trailing spaces are stripped (single line)",
114 in: "\t \nThe text line \n \t",
115 out: "The text line",
116 },
117 {
118 desc: "With code block",
119 in: "Line1\n\n\t<type>.<fieldName>[.<fieldName>]\n\nLine2",
120 out: "Line1\n\n <type>.<fieldName>[.<fieldName>]\n \n Line2",
121 },
122 }
123
124 for _, test := range tests {
125 t.Run(test.desc, func(t *testing.T) {
126 got := LongDesc(LongDesc(test.in))
127 if got != test.out {
128 t.Errorf("expected(%d):\n%s\n=====\ngot(%d):\n%s\n", len(test.out), test.out, len(got), got)
129 }
130 })
131 }
132 }
133
View as plain text