Skip to content

Commit 7104a1d

Browse files
Copilotstreed
andcommitted
Add tests and finalize website import feature
Co-authored-by: streed <805140+streed@users.noreply.github.com>
1 parent 629fcb1 commit 7104a1d

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

cmd/import_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
"net/url"
6+
)
7+
8+
func TestValidateURL(t *testing.T) {
9+
tests := []struct {
10+
name string
11+
input string
12+
wantErr bool
13+
}{
14+
{
15+
name: "valid http url",
16+
input: "https://example.com",
17+
wantErr: false,
18+
},
19+
{
20+
name: "valid https url",
21+
input: "http://example.com",
22+
wantErr: false,
23+
},
24+
{
25+
name: "valid file url",
26+
input: "file:///tmp/test.html",
27+
wantErr: false,
28+
},
29+
{
30+
name: "relative path (invalid for our use case)",
31+
input: "not-a-url",
32+
wantErr: false, // url.Parse accepts this but we'd expect Chrome to handle it
33+
},
34+
{
35+
name: "empty url",
36+
input: "",
37+
wantErr: false, // url.Parse accepts empty string
38+
},
39+
}
40+
41+
for _, tt := range tests {
42+
t.Run(tt.name, func(t *testing.T) {
43+
_, err := url.Parse(tt.input)
44+
hasErr := err != nil
45+
if hasErr != tt.wantErr {
46+
t.Errorf("url.Parse() error = %v, wantErr %v", err, tt.wantErr)
47+
}
48+
})
49+
}
50+
}
51+
52+
func TestCleanMarkdownContent(t *testing.T) {
53+
tests := []struct {
54+
name string
55+
input string
56+
expected string
57+
}{
58+
{
59+
name: "remove multiple empty lines",
60+
input: "Line 1\n\n\n\nLine 2",
61+
expected: "Line 1\n\nLine 2",
62+
},
63+
{
64+
name: "remove leading empty lines",
65+
input: "\n\nLine 1\nLine 2",
66+
expected: "Line 1\nLine 2",
67+
},
68+
{
69+
name: "remove trailing empty lines",
70+
input: "Line 1\nLine 2\n\n\n",
71+
expected: "Line 1\nLine 2",
72+
},
73+
{
74+
name: "trim whitespace",
75+
input: " Line 1 \n Line 2 ",
76+
expected: "Line 1\nLine 2",
77+
},
78+
{
79+
name: "single line",
80+
input: "Single line",
81+
expected: "Single line",
82+
},
83+
{
84+
name: "empty content",
85+
input: "",
86+
expected: "",
87+
},
88+
}
89+
90+
for _, tt := range tests {
91+
t.Run(tt.name, func(t *testing.T) {
92+
result := cleanMarkdownContent(tt.input)
93+
if result != tt.expected {
94+
t.Errorf("cleanMarkdownContent() = %q, want %q", result, tt.expected)
95+
}
96+
})
97+
}
98+
}

0 commit comments

Comments
 (0)