-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalize_test.go
More file actions
111 lines (108 loc) · 3.33 KB
/
normalize_test.go
File metadata and controls
111 lines (108 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import "testing"
func TestNormalizeMD(t *testing.T) {
tests := []struct {
name string
in string
want string
}{
{
name: "bold header followed by description",
in: "**Profound** ($58.5M raised) — profound.ai\nMarket leader in AI visibility.",
want: "**Profound** ($58.5M raised) — profound.ai\n\nMarket leader in AI visibility.",
},
{
name: "bold header already has blank line",
in: "**Profound** — profound.ai\n\nMarket leader.",
want: "**Profound** — profound.ai\n\nMarket leader.",
},
{
name: "multiple bold headers with descriptions",
in: "**Profound** — profound.ai\nFirst company.\n\n**Lemrock** — lemrock.com\nSecond company.",
want: "**Profound** — profound.ai\n\nFirst company.\n\n**Lemrock** — lemrock.com\n\nSecond company.",
},
{
name: "bold header followed by list",
in: "**Features:**\n- Item one\n- Item two",
want: "**Features:**\n\n- Item one\n- Item two",
},
{
name: "bold header followed by heading",
in: "**Summary**\n## Next Section",
want: "**Summary**\n\n## Next Section",
},
{
name: "inline bold not at start of line",
in: "This has **bold** in the middle.\nNext line.",
want: "This has **bold** in the middle.\nNext line.",
},
{
name: "list after paragraph (existing rule)",
in: "Some text.\n- Item one\n- Item two",
want: "Some text.\n\n- Item one\n- Item two",
},
{
name: "heading after paragraph (existing rule)",
in: "Some text.\n## Heading",
want: "Some text.\n\n## Heading",
},
{
name: "numbered list after paragraph",
in: "Some text.\n1. First\n2. Second",
want: "Some text.\n\n1. First\n2. Second",
},
{
name: "already correct spacing preserved",
in: "## Heading\n\nSome text.\n\n- Item one\n- Item two",
want: "## Heading\n\nSome text.\n\n- Item one\n- Item two",
},
{
name: "bold line followed by blank then text",
in: "**Header**\n\nDescription.",
want: "**Header**\n\nDescription.",
},
{
name: "consecutive bold lines not separated",
in: "**Line one**\n**Line two**",
want: "**Line one**\n**Line two**",
},
{
name: "bold with parens and dash followed by text",
in: "**ReFiBuy** (ChannelAdvisor founder) — refibuy.com\nCommerce Intelligence Engine.",
want: "**ReFiBuy** (ChannelAdvisor founder) — refibuy.com\n\nCommerce Intelligence Engine.",
},
{
name: "real world tier section",
in: "## Tier 1\n\n**Profound** — profound.ai\nMarket leader.\n\n**Lemrock** — lemrock.com\nMiddleware.",
want: "## Tier 1\n\n**Profound** — profound.ai\n\nMarket leader.\n\n**Lemrock** — lemrock.com\n\nMiddleware.",
},
{
name: "empty input",
in: "",
want: "",
},
{
name: "single line",
in: "Just text.",
want: "Just text.",
},
{
name: "table rows not affected",
in: "| **Company** | Funding |\n| Profound | $58M |",
want: "| **Company** | Funding |\n| Profound | $58M |",
},
{
name: "bold key-value not broken",
in: "**Key gap:** monitoring only.\n**Our edge:** self-serve.",
want: "**Key gap:** monitoring only.\n**Our edge:** self-serve.",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := normalizeMD(tt.in)
if got != tt.want {
t.Errorf("normalizeMD():\n input: %q\n got: %q\n want: %q", tt.in, got, tt.want)
}
})
}
}