-
Notifications
You must be signed in to change notification settings - Fork 0
/
marshal_test.go
156 lines (143 loc) · 3.82 KB
/
marshal_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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package netscape
import (
"testing"
"time"
)
func TestMarshal(t *testing.T) {
folderCreatedAt := time.Date(2021, time.June, 1, 17, 11, 13, 0, time.UTC)
folderUpdatedAt := time.Date(2021, time.August, 1, 22, 9, 46, 0, time.UTC)
bookmarkCreatedAt := time.Date(2022, time.January, 1, 17, 11, 13, 0, time.UTC)
bookmarkUpdatedAt := time.Date(2022, time.March, 1, 22, 9, 46, 0, time.UTC)
cases := []struct {
tname string
document Document
want string
}{
{
tname: "empty document",
want: `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<TITLE></TITLE>
<H1></H1>
<DL><p>
</DL><p>
`,
},
{
tname: "document with bookmarks",
document: Document{
Title: "Bookmarks",
Root: Folder{
Name: "Bookmarks",
Bookmarks: []Bookmark{
{
URL: "https://domain.tld",
Title: "Test Domain",
},
{
Description: "Second test",
URL: "https://test.domain.tld",
Title: "Test Domain II",
},
{
Description: `
> The format of here-documents is:
` + "```shell" + `
[n]<<[-]word
here-document
delimiter
` + "```" + `
> If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded.`,
URL: "https://markdown.xml",
Title: "Markdown Description",
},
},
},
},
want: `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><A HREF="https://domain.tld" PRIVATE="0">Test Domain</A>
<DT><A HREF="https://test.domain.tld" PRIVATE="0">Test Domain II</A>
<DD>Second test
<DT><A HREF="https://markdown.xml" PRIVATE="0">Markdown Description</A>
<DD>
> The format of here-documents is:
` + "```shell" + `
[n]<<[-]word
here-document
delimiter
` + "```" + `
> If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded.
</DL><p>
`,
},
{
tname: "document with private bookmarks and dates",
document: Document{
Title: "Bookmarks",
Root: Folder{
Name: "Bookmarks",
Subfolders: []Folder{
{
Name: "Favorites",
Description: "Add bookmarks here",
CreatedAt: folderCreatedAt,
UpdatedAt: folderUpdatedAt,
Bookmarks: []Bookmark{
{
CreatedAt: bookmarkCreatedAt,
URL: "https://domain.tld",
Title: "Test Domain",
Private: true,
},
{
CreatedAt: bookmarkCreatedAt,
UpdatedAt: bookmarkUpdatedAt,
Description: "Second test",
URL: "https://test.domain.tld",
Title: "Test Domain II",
Private: true,
},
},
},
},
},
},
want: `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
<DT><H3 ADD_DATE="1622567473" LAST_MODIFIED="1627855786">Favorites</H3>
<DD>Add bookmarks here
<DL><p>
<DT><A HREF="https://domain.tld" ADD_DATE="1641057073" PRIVATE="1">Test Domain</A>
<DT><A HREF="https://test.domain.tld" ADD_DATE="1641057073" LAST_MODIFIED="1646172586" PRIVATE="1">Test Domain II</A>
<DD>Second test
</DL><p>
</DL><p>
`,
},
}
for _, tc := range cases {
t.Run(tc.tname, func(t *testing.T) {
m, err := Marshal(&tc.document)
if err != nil {
t.Fatalf("expected no error, got %q", err)
}
got := string(m)
if got != tc.want {
t.Errorf("\nwant:\n%s\n\ngot:\n%s", tc.want, got)
}
})
}
}