2016-05-11 15:39:46 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/github/hub/github"
|
|
|
|
)
|
|
|
|
|
|
|
|
type formatIssueTest struct {
|
|
|
|
name string
|
|
|
|
issue github.Issue
|
|
|
|
format string
|
|
|
|
colorize bool
|
|
|
|
expect string
|
|
|
|
}
|
|
|
|
|
|
|
|
func testFormatIssue(t *testing.T, tests []formatIssueTest) {
|
|
|
|
for _, test := range tests {
|
|
|
|
if got := formatIssue(test.issue, test.format, test.colorize); got != test.expect {
|
|
|
|
t.Errorf("%s: formatIssue(..., %q, %t) = %q, want %q", test.name, test.format, test.colorize, got, test.expect)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFormatIssue(t *testing.T) {
|
2016-08-15 17:52:44 +03:00
|
|
|
format := "%sC%>(8)%i%Creset %t% l%n"
|
2016-05-11 15:39:46 +03:00
|
|
|
testFormatIssue(t, []formatIssueTest{
|
|
|
|
{
|
|
|
|
name: "standard usage",
|
|
|
|
issue: github.Issue{
|
2016-08-15 17:52:44 +03:00
|
|
|
Number: 42,
|
|
|
|
Title: "Just an Issue",
|
|
|
|
State: "open",
|
|
|
|
User: &github.User{Login: "pcorpet"},
|
|
|
|
Body: "Body of the\nissue",
|
|
|
|
Assignees: []github.User{{Login: "mislav"}},
|
2016-05-11 15:39:46 +03:00
|
|
|
},
|
|
|
|
format: format,
|
|
|
|
colorize: true,
|
|
|
|
expect: "\033[32m #42\033[m Just an Issue\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "closed issue colored differently",
|
|
|
|
issue: github.Issue{
|
|
|
|
Number: 42,
|
|
|
|
Title: "Just an Issue",
|
|
|
|
State: "closed",
|
2016-08-15 17:52:44 +03:00
|
|
|
User: &github.User{Login: "octocat"},
|
2016-05-11 15:39:46 +03:00
|
|
|
},
|
|
|
|
format: format,
|
|
|
|
colorize: true,
|
|
|
|
expect: "\033[31m #42\033[m Just an Issue\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "labels",
|
|
|
|
issue: github.Issue{
|
|
|
|
Number: 42,
|
|
|
|
Title: "An issue with labels",
|
|
|
|
State: "open",
|
2016-08-15 17:52:44 +03:00
|
|
|
User: &github.User{Login: "octocat"},
|
2016-05-11 15:39:46 +03:00
|
|
|
Labels: []github.IssueLabel{
|
|
|
|
{Name: "bug", Color: "800000"},
|
|
|
|
{Name: "reproduced", Color: "55ff55"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
format: format,
|
|
|
|
colorize: true,
|
|
|
|
expect: "\033[32m #42\033[m An issue with labels \033[38;5;15;48;2;128;0;0m bug \033[m \033[38;5;16;48;2;85;255;85m reproduced \033[m\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not colorized",
|
|
|
|
issue: github.Issue{
|
|
|
|
Number: 42,
|
|
|
|
Title: "Just an Issue",
|
|
|
|
State: "open",
|
2016-08-15 17:52:44 +03:00
|
|
|
User: &github.User{Login: "octocat"},
|
2016-05-11 15:39:46 +03:00
|
|
|
},
|
|
|
|
format: format,
|
|
|
|
colorize: false,
|
|
|
|
expect: " #42 Just an Issue\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "labels not colorized",
|
|
|
|
issue: github.Issue{
|
|
|
|
Number: 42,
|
|
|
|
Title: "An issue with labels",
|
|
|
|
State: "open",
|
2016-08-15 17:52:44 +03:00
|
|
|
User: &github.User{Login: "octocat"},
|
2016-05-11 15:39:46 +03:00
|
|
|
Labels: []github.IssueLabel{
|
|
|
|
{Name: "bug", Color: "880000"},
|
|
|
|
{Name: "reproduced", Color: "55ff55"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
format: format,
|
|
|
|
colorize: false,
|
|
|
|
expect: " #42 An issue with labels bug reproduced \n",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFormatIssue_customFormatString(t *testing.T) {
|
|
|
|
issue := github.Issue{
|
2016-08-15 17:52:44 +03:00
|
|
|
Number: 42,
|
|
|
|
Title: "Just an Issue",
|
|
|
|
State: "open",
|
|
|
|
User: &github.User{Login: "pcorpet"},
|
|
|
|
Body: "Body of the\nissue",
|
|
|
|
Assignees: []github.User{
|
|
|
|
{Login: "mislav"},
|
|
|
|
{Login: "josh"},
|
|
|
|
},
|
2016-05-11 15:39:46 +03:00
|
|
|
Labels: []github.IssueLabel{
|
|
|
|
{Name: "bug", Color: "880000"},
|
2016-08-15 17:52:44 +03:00
|
|
|
{Name: "feature", Color: "008800"},
|
|
|
|
},
|
|
|
|
HtmlUrl: "the://url",
|
|
|
|
Comments: 12,
|
|
|
|
Milestone: &github.Milestone{
|
|
|
|
Number: 31,
|
|
|
|
Title: "2.2-stable",
|
2016-05-11 15:39:46 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
testFormatIssue(t, []formatIssueTest{
|
|
|
|
{
|
|
|
|
name: "number",
|
|
|
|
issue: issue,
|
2016-08-15 17:52:44 +03:00
|
|
|
format: "%I",
|
2016-05-11 15:39:46 +03:00
|
|
|
colorize: true,
|
|
|
|
expect: "42",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "hashed number",
|
|
|
|
issue: issue,
|
2016-08-15 17:52:44 +03:00
|
|
|
format: "%i",
|
2016-05-11 15:39:46 +03:00
|
|
|
colorize: true,
|
|
|
|
expect: "#42",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "state as text",
|
|
|
|
issue: issue,
|
2016-08-15 17:52:44 +03:00
|
|
|
format: "%S",
|
2016-05-11 15:39:46 +03:00
|
|
|
colorize: true,
|
|
|
|
expect: "open",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "state as color switch",
|
|
|
|
issue: issue,
|
|
|
|
format: "%sC",
|
|
|
|
colorize: true,
|
|
|
|
expect: "\033[32m",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "state as color switch non colorized",
|
|
|
|
issue: issue,
|
|
|
|
format: "%sC",
|
|
|
|
colorize: false,
|
|
|
|
expect: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "title",
|
|
|
|
issue: issue,
|
|
|
|
format: "%t",
|
|
|
|
colorize: true,
|
|
|
|
expect: "Just an Issue",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "label colorized",
|
|
|
|
issue: issue,
|
|
|
|
format: "%l",
|
|
|
|
colorize: true,
|
2016-08-15 17:52:44 +03:00
|
|
|
expect: "\033[38;5;15;48;2;136;0;0m bug \033[m \033[38;5;15;48;2;0;136;0m feature \033[m",
|
2016-05-11 15:39:46 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "label not colorized",
|
|
|
|
issue: issue,
|
|
|
|
format: "%l",
|
|
|
|
colorize: false,
|
2016-08-15 17:52:44 +03:00
|
|
|
expect: " bug feature ",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "raw labels",
|
|
|
|
issue: issue,
|
|
|
|
format: "%L",
|
|
|
|
colorize: true,
|
|
|
|
expect: "bug, feature",
|
2016-05-11 15:39:46 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "body",
|
|
|
|
issue: issue,
|
|
|
|
format: "%b",
|
|
|
|
colorize: true,
|
|
|
|
expect: "Body of the\nissue",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "user login",
|
|
|
|
issue: issue,
|
2016-08-15 17:52:44 +03:00
|
|
|
format: "%au",
|
2016-05-11 15:39:46 +03:00
|
|
|
colorize: true,
|
|
|
|
expect: "pcorpet",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "assignee login",
|
|
|
|
issue: issue,
|
2016-08-15 17:52:44 +03:00
|
|
|
format: "%as",
|
2016-05-11 15:39:46 +03:00
|
|
|
colorize: true,
|
2016-08-15 17:52:44 +03:00
|
|
|
expect: "mislav, josh",
|
2016-05-11 15:39:46 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "assignee login but not assigned",
|
|
|
|
issue: github.Issue{
|
|
|
|
State: "open",
|
|
|
|
User: &github.User{Login: "pcorpet"},
|
|
|
|
},
|
2016-08-15 17:52:44 +03:00
|
|
|
format: "%as",
|
2016-05-11 15:39:46 +03:00
|
|
|
colorize: true,
|
|
|
|
expect: "",
|
|
|
|
},
|
2016-08-15 17:52:44 +03:00
|
|
|
{
|
|
|
|
name: "milestone number",
|
|
|
|
issue: issue,
|
|
|
|
format: "%Mn",
|
|
|
|
colorize: true,
|
|
|
|
expect: "31",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "milestone title",
|
|
|
|
issue: issue,
|
|
|
|
format: "%Mt",
|
|
|
|
colorize: true,
|
|
|
|
expect: "2.2-stable",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "comments number",
|
|
|
|
issue: issue,
|
|
|
|
format: "%Nc",
|
|
|
|
colorize: true,
|
|
|
|
expect: "(12)",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "raw comments number",
|
|
|
|
issue: issue,
|
|
|
|
format: "%NC",
|
|
|
|
colorize: true,
|
|
|
|
expect: "12",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "issue URL",
|
|
|
|
issue: issue,
|
|
|
|
format: "%U",
|
|
|
|
colorize: true,
|
|
|
|
expect: "the://url",
|
|
|
|
},
|
2016-05-11 15:39:46 +03:00
|
|
|
})
|
|
|
|
}
|