-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
70 lines (62 loc) · 1.94 KB
/
main_test.go
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
package main
import (
"reflect"
"testing"
gofeed "github.com/mmcdole/gofeed"
)
func TestEscapeMarkdown(t *testing.T) {
// Test case 1: No special characters
input := "Hello, world!"
expected := "Hello, world!"
output := escapeMarkdown(input)
if output != expected {
t.Errorf("Expected %q, but got %q", expected, output)
}
// Test case 2: One special character
input = "Hello, _world_!"
expected = "Hello, \\_world\\_!"
output = escapeMarkdown(input)
if output != expected {
t.Errorf("Expected %q, but got %q", expected, output)
}
// Test case 3: Multiple special characters
input = "Hello, *world*! [Link](https://example.com)"
expected = "Hello, \\*world\\*! \\[Link\\]\\(https://example.com\\)"
output = escapeMarkdown(input)
if output != expected {
t.Errorf("Expected %q, but got %q", expected, output)
}
// Test case 4: Empty string
input = ""
expected = ""
output = escapeMarkdown(input)
if output != expected {
t.Errorf("Expected %q, but got %q", expected, output)
}
}
func TestGetFieldValues(t *testing.T) {
// Test case 1: Single field
item := &gofeed.Item{Title: "Test post"}
fields := []string{"Title"}
expected := []interface{}{"Test post"}
output := getFieldValues(item, fields)
if !reflect.DeepEqual(output, expected) {
t.Errorf("Expected %v, but got %v", expected, output)
}
// Test case 2: Multiple fields
item = &gofeed.Item{Title: "Test post", Link: "https://example.com/post"}
fields = []string{"Title", "Link"}
expected = []interface{}{"Test post", "https://example.com/post"}
output = getFieldValues(item, fields)
if !reflect.DeepEqual(output, expected) {
t.Errorf("Expected %v, but got %v", expected, output)
}
// Test case 3: Empty fields
item = &gofeed.Item{Title: "Test post", Link: "https://example.com/post"}
fields = []string{}
expected = []interface{}{}
output = getFieldValues(item, fields)
if !reflect.DeepEqual(output, expected) {
t.Errorf("Expected %v, but got %v", expected, output)
}
}