forked from NollGo/Noll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
166 lines (142 loc) · 4.24 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
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
157
158
159
160
161
162
163
164
165
166
package main
import (
"fmt"
"os"
"strings"
"testing"
"time"
"github.com/gosimple/slug"
)
func TestURLSlug(t *testing.T) {
text := slug.Make("Hellö Wörld хелло ворлд")
fmt.Println(text) // Will print: "hello-world-khello-vorld"
text2 := slug.Make("o(* ̄▽ ̄*)ブ")
fmt.Println(text2) // Will print: "o-v-bu"
text3 := slug.Make("💡 (_ _)。゜zzZ")
fmt.Println(text3) // Will print: "zzz"
text4 := slug.Make("( ´・・)ノ(._.`)")
fmt.Println(text4) // Will print: "no"
text5 := slug.Make("ヾ(⌐■_■)ノ♪")
fmt.Println(text5) // Will print: "no"
someText := slug.Make("影師")
fmt.Println(someText) // Will print: "ying-shi"
enText := slug.MakeLang("This & that", "en")
fmt.Println(enText) // Will print: "this-and-that"
deText := slug.MakeLang("Diese & Dass", "de")
fmt.Println(deText) // Will print: "diese-und-dass"
slug.Lowercase = false // Keep uppercase characters
deUppercaseText := slug.MakeLang("Diese & Dass", "fa")
fmt.Println(deUppercaseText) // Will print: "Diese-und-Dass"
slug.CustomSub = map[string]string{
"water": "sand",
}
textSub := slug.Make("water is hot")
fmt.Println(textSub) // Will print: "sand-is-hot"
}
func TestStringContains(t *testing.T) {
if strings.Contains(`{
repository(owner: "excing", name: "find-roots-of-word") {
discussionCategories(first: 10) {
nodes {
id
name
emoji
description
}
totalCount
}
}
viewer {
login
}
}`, `first: 11`) {
t.Log()
} else {
t.Fail()
}
}
func TestTimeConvert(t *testing.T) {
timeStr := ""
time, err := time.Parse("2006-01-02 15:04:05", timeStr)
if err != nil {
// Result: failed
t.Fatal(err)
}
t.Log(time.String())
}
func TestQueryf(t *testing.T) {
query := queryf(`{
repository(owner: "excing", name: "find-roots-of-word") {
discussionCategories(first: 10) {
nodes {
id
name
emoji
description
}
totalCount
}
}
viewer {
login
}
}`)
fmt.Println(query)
// {"query": "query { repository(owner: \"excing\", name: \"find-roots-of-word\") { discussionCategories(first: 10) { nodes { id name emoji description } totalCount } } viewer { login } }" }
}
func TestRender(t *testing.T) {
err := render(
&RenderSite{"/", ""},
testRepository(),
"assets/theme",
true,
func(s string, b []byte) error {
fmt.Println(s)
_, err := os.Stdout.Write(b)
return err
},
)
if err != nil {
t.Fatal(err)
}
}
func TestOsStat(t *testing.T) {
if _, err := os.Stat(""); os.IsNotExist(err) {
t.Fatal(err)
} else {
t.Log("PASS")
}
}
func TestGetEmoji4GEmoji(t *testing.T) {
gemojiFormat := `<div></div>`
gemoji := `<g-emoji class="g-emoji" alias="mega" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4e3.png">📣</g-emoji>`
t.Log(getGemoji(fmt.Sprintf(gemojiFormat, gemoji)) == gemoji)
}
func TestPref(t *testing.T) {
str := "example.txt"
suffix := "txt"
t.Log(strings.HasSuffix(str, suffix))
}
func TestNewSite(t *testing.T) {
fmt.Println(newSite("./test"))
}
func testRepository() *GithubData {
labels := &LabelPage{}
labels.Nodes = append(labels.Nodes, &Label{Name: "bug", Discussions: &DiscussionPage{}})
labels.TotalCount = len(labels.Nodes)
categories := &CategoryPage{}
categories.Nodes = append(categories.Nodes, &Category{Name: "Announcements", Discussions: &DiscussionPage{}})
categories.Nodes = append(categories.Nodes, &Category{Name: "General", Discussions: &DiscussionPage{}})
categories.Nodes = append(categories.Nodes, &Category{Name: "Ideas", Discussions: &DiscussionPage{}})
categories.Nodes = append(categories.Nodes, &Category{Name: "Polls", Discussions: &DiscussionPage{}})
categories.Nodes = append(categories.Nodes, &Category{Name: "Q&A", Discussions: &DiscussionPage{}})
categories.TotalCount = len(categories.Nodes)
discussions := &DiscussionPage{}
discussions.Nodes = append(discussions.Nodes, &Discussion{Title: "关于模板版本的一些思考", GitHubURL: "https://github.com/ThreeTenth/GitHub-Discussions-to-Blog/discussions/8", Category: &Category{Name: "Ideas"}, Comments: &CommentPage{}})
discussions.TotalCount = len(discussions.Nodes)
return &GithubData{
&Repository{Labels: labels, Categories: categories, Discussions: discussions},
&User{Login: "excing"},
&Organization{},
}
}