本文整理匯總了Golang中github.com/minodisk/qiitactl/model.Post.Decode方法的典型用法代碼示例。如果您正苦於以下問題:Golang Post.Decode方法的具體用法?Golang Post.Decode怎麽用?Golang Post.Decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/minodisk/qiitactl/model.Post
的用法示例。
在下文中一共展示了Post.Decode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestPostDecodeWithWrongTitle
func TestPostDecodeWithWrongTitle(t *testing.T) {
testutil.CleanUp()
defer testutil.CleanUp()
var post model.Post
err := post.Decode([]byte(`<!--
id: abcdefghijklmnopqrst
url: http://example.com/mypost
created_at: 2013-12-10T12:29:14+09:00
updated_at: 2015-02-25T09:26:30+09:00
private: true
coediting: false
tags:
- TypeScript
- Docker:
- 1.9
- Go:
- 1.4.3
- 1.5.3
team: null
-->
## Sub title
# Main title
Paragraph
`))
if err == nil {
t.Errorf("should return error with non-object element in tags")
}
}
示例2: TestPostDecodeWithMultiComment
func TestPostDecodeWithMultiComment(t *testing.T) {
testutil.CleanUp()
defer testutil.CleanUp()
var post model.Post
err := post.Decode([]byte(`<!--
id: ""
url: ""
created_at: 2016-02-17T13:08:30+09:00
updated_at: 2016-02-17T13:08:30+09:00
private: false
coediting: false
tags:
- Qiita
- Go
team: null
-->
# Example Title
<!--
This is not meta
-->
# This is not title of this post
`))
if err != nil {
t.Fatal(err)
}
}
示例3: TestPostDecodeWithCorrectMarkdown
func TestPostDecodeWithCorrectMarkdown(t *testing.T) {
testutil.CleanUp()
defer testutil.CleanUp()
var post model.Post
err := post.Decode([]byte(`<!--
id: abcdefghijklmnopqrst
url: http://example.com/mypost
created_at: 2013-12-10T12:29:14+09:00
updated_at: 2015-02-25T09:26:30+09:00
private: true
coediting: false
tags:
- TypeScript
- Docker:
- 1.9
- Go:
- 1.4.3
- 1.5.3
team: null
-->
# Main title
## Sub title
Paragraph
`))
if err != nil {
t.Fatal(err)
}
if post.Meta.ID != "abcdefghijklmnopqrst" {
t.Errorf("wrong Id")
}
if post.Meta.URL != "http://example.com/mypost" {
t.Errorf("wrong Url")
}
if !post.Meta.CreatedAt.Equal(time.Date(2013, 12, 10, 3, 29, 14, 0, time.UTC)) {
t.Errorf("wrong CreatedAt")
}
if !post.Meta.UpdatedAt.Equal(time.Date(2015, 02, 25, 0, 26, 30, 0, time.UTC)) {
t.Errorf("wrong UpdatedAt")
}
if post.Meta.Private != true {
t.Errorf("wrong Private")
}
if post.Meta.Coediting != false {
t.Errorf("wrong Coediting")
}
if len(post.Meta.Tags) != 3 {
t.Errorf("wrong Tags length: %d", len(post.Meta.Tags))
} else {
for _, tag := range post.Meta.Tags {
switch tag.Name {
case "TypeScript":
if len(tag.Versions) != 0 {
t.Errorf("wrong Tag with no version: %+v", tag)
}
case "Docker":
if len(tag.Versions) != 1 || tag.Versions[0] != "1.9" {
t.Errorf("wrong Tag with single version: %+v", tag)
}
case "Go":
if len(tag.Versions) != 2 || tag.Versions[0] != "1.4.3" || tag.Versions[1] != "1.5.3" {
t.Errorf("wrong Tag with multi versions: %+v", tag)
}
}
}
}
if post.Title != "Main title" {
t.Errorf("wrong Title")
}
if post.Body != "## Sub title\nParagraph" {
t.Errorf("wrong Body: %s", post.Body)
}
}