@@ -5,141 +5,87 @@ import (
55 "testing"
66)
77
8+ type (
9+ Pg = BookmarkPage
10+ Blk = BookmarkBlock
11+ Col = BookmarkColumn
12+ Cat = BookmarkCategory
13+ Ent = BookmarkEntry
14+ )
15+
16+ func e (u , n string ) * Ent { return & Ent {Url : u , Name : n } }
17+ func cat (name string , es ... * Ent ) * Cat { return & Cat {Name : name , Entries : es } }
18+ func col (cs ... * Cat ) * Col { return & Col {Categories : cs } }
19+ func colsBlock (cs ... * Col ) * Blk { return & Blk {Columns : cs } }
20+ func hrBlock () * Blk { return & Blk {HR : true } }
21+ func page (bs ... * Blk ) * Pg { return & Pg {Blocks : bs } }
22+
823func Test_preprocessBookmarks (t * testing.T ) {
924 tests := []struct {
10- name string
11- bookmarks string
12- want []* BookmarkPage
25+ name string
26+ input string
27+ want []* Pg
1328 }{
1429 {
15- name : "basic" ,
16- bookmarks : "Category: Search\n http://www.google.com.au Google\n Category: Wikies\n http://en.wikipedia.org/wiki/Main_Page Wikipedia\n http://mathworld.wolfram.com/ Math World\n http://gentoo-wiki.com/Main_Page Gentoo-wiki\n " ,
17- want : []* BookmarkPage {{
18- Columns : []* BookmarkColumn {{
19- Categories : []* BookmarkCategory {
20- {
21- Name : "Search" ,
22- Entries : []* BookmarkEntry {{Url : "http://www.google.com.au" , Name : "Google" }},
23- },
24- {
25- Name : "Wikies" ,
26- Entries : []* BookmarkEntry {
27- {Url : "http://en.wikipedia.org/wiki/Main_Page" , Name : "Wikipedia" },
28- {Url : "http://mathworld.wolfram.com/" , Name : "Math World" },
29- {Url : "http://gentoo-wiki.com/Main_Page" , Name : "Gentoo-wiki" },
30- },
31- },
32- },
33- }},
34- }},
30+ name : "basic" ,
31+ input : "Category: Search\n http://g.com G\n Category: Wikies\n http://w.com W\n " ,
32+ want : []* Pg {
33+ page (colsBlock (
34+ col (cat ("Search" , e ("http://g.com" , "G" )),
35+ cat ("Wikies" , e ("http://w.com" , "W" ))),
36+ )),
37+ },
3538 },
3639 {
37- name : "columns" ,
38- bookmarks : "Category: Search\n http://www.google.com.au Google\n Column\n Category: Wikies\n http://en.wikipedia.org/wiki/Main_Page Wikipedia\n " ,
39- want : []* BookmarkPage {{
40- Columns : []* BookmarkColumn {
41- {
42- Categories : []* BookmarkCategory {
43- {
44- Name : "Search" ,
45- Entries : []* BookmarkEntry {{Url : "http://www.google.com.au" , Name : "Google" }},
46- },
47- },
48- },
49- {
50- Categories : []* BookmarkCategory {
51- {
52- Name : "Wikies" ,
53- Entries : []* BookmarkEntry {{Url : "http://en.wikipedia.org/wiki/Main_Page" , Name : "Wikipedia" }},
54- },
55- },
56- },
57- },
58- }},
40+ name : "columns" ,
41+ input : "Category: Search\n http://g.com G\n Column\n Category: Wikies\n http://w.com W\n " ,
42+ want : []* Pg {
43+ page (colsBlock (
44+ col (cat ("Search" , e ("http://g.com" , "G" ))),
45+ col (cat ("Wikies" , e ("http://w.com" , "W" ))),
46+ )),
47+ },
5948 },
6049 {
61- name : "pages" ,
62- bookmarks : "Category: First\n http://example.com A\n Page\n Category: Second\n http://example.org B\n " ,
63- want : []* BookmarkPage {
64- {
65- Columns : []* BookmarkColumn {{
66- Categories : []* BookmarkCategory {
67- {
68- Name : "First" ,
69- Entries : []* BookmarkEntry {{Url : "http://example.com" , Name : "A" }},
70- },
71- },
72- }},
73- },
74- {
75- Columns : []* BookmarkColumn {{
76- Categories : []* BookmarkCategory {
77- {
78- Name : "Second" ,
79- Entries : []* BookmarkEntry {{Url : "http://example.org" , Name : "B" }},
80- },
81- },
82- }},
83- },
50+ name : "pages" ,
51+ input : "Category: A\n http://a.com a\n Page\n Category: B\n http://b.com b\n " ,
52+ want : []* Pg {
53+ page (colsBlock (col (cat ("A" , e ("http://a.com" , "a" ))))),
54+ page (colsBlock (col (cat ("B" , e ("http://b.com" , "b" ))))),
8455 },
8556 },
8657 {
87- name : "pages and columns" ,
88- bookmarks : "Category: A\n http://a.com\n Column\n Category: B\n http://b.com\n Page\n Category: C\n http://c.com\n Column\n Category: D\n http://d.com\n " ,
89- want : []* BookmarkPage {
90- {
91- Columns : []* BookmarkColumn {
92- {
93- Categories : []* BookmarkCategory {
94- {Name : "A" , Entries : []* BookmarkEntry {{Url : "http://a.com" , Name : "http://a.com" }}},
95- },
96- },
97- {
98- Categories : []* BookmarkCategory {
99- {Name : "B" , Entries : []* BookmarkEntry {{Url : "http://b.com" , Name : "http://b.com" }}},
100- },
101- },
102- },
103- },
104- {
105- Columns : []* BookmarkColumn {
106- {
107- Categories : []* BookmarkCategory {
108- {Name : "C" , Entries : []* BookmarkEntry {{Url : "http://c.com" , Name : "http://c.com" }}},
109- },
110- },
111- {
112- Categories : []* BookmarkCategory {
113- {Name : "D" , Entries : []* BookmarkEntry {{Url : "http://d.com" , Name : "http://d.com" }}},
114- },
115- },
116- },
117- },
58+ name : "pages and columns" ,
59+ input : "Category: A\n http://a.com\n Column\n Category: B\n http://b.com\n Page\n Category: C\n http://c.com\n Column\n Category: D\n http://d.com\n " ,
60+ want : []* Pg {
61+ page (colsBlock (
62+ col (cat ("A" , e ("http://a.com" , "http://a.com" ))),
63+ col (cat ("B" , e ("http://b.com" , "http://b.com" ))),
64+ )),
65+ page (colsBlock (
66+ col (cat ("C" , e ("http://c.com" , "http://c.com" ))),
67+ col (cat ("D" , e ("http://d.com" , "http://d.com" ))),
68+ )),
11869 },
11970 },
12071 {
121- name : "double dash compat" ,
122- bookmarks : "Category: One\n http://one.com\n --\n Category: Two\n http://two.com\n " ,
123- want : []* BookmarkPage {
124- {
125- Columns : []* BookmarkColumn {{
126- Categories : []* BookmarkCategory {{Name : "One" , Entries : []* BookmarkEntry {{Url : "http://one.com" , Name : "http://one.com" }}}},
127- }},
128- },
129- {
130- Columns : []* BookmarkColumn {{
131- Categories : []* BookmarkCategory {{Name : "Two" , Entries : []* BookmarkEntry {{Url : "http://two.com" , Name : "http://two.com" }}}},
132- }},
133- },
72+ name : "horizontal rule" ,
73+ input : "Category: One\n http://one.com\n --\n Category: Two\n http://two.com\n " ,
74+ want : []* Pg {
75+ page (
76+ colsBlock (col (cat ("One" , e ("http://one.com" , "http://one.com" )))),
77+ hrBlock (),
78+ colsBlock (col (cat ("Two" , e ("http://two.com" , "http://two.com" )))),
79+ ),
13480 },
13581 },
13682 }
13783
13884 for _ , tt := range tests {
13985 t .Run (tt .name , func (t * testing.T ) {
140- got := PreprocessBookmarks (tt .bookmarks )
141- if diff := cmp .Diff (got , tt .want ); diff != "" {
142- t .Errorf ("PreprocessBookmarks() = diff\n %s" , diff )
86+ got := PreprocessBookmarks (tt .input )
87+ if diff := cmp .Diff (tt .want , got ); diff != "" {
88+ t .Errorf ("diff: \n %s" , diff )
14389 }
14490 })
14591 }
0 commit comments