2022-05-01 13:30:55 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2022-08-18 13:18:23 +03:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2022-05-01 13:30:55 +03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_repairQuery(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
args []string
|
|
|
|
output string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
[]string{""},
|
|
|
|
"",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]string{"foo"},
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]string{"foo", "bar"},
|
|
|
|
"foo bar",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]string{"foo bar", "baz"},
|
|
|
|
"\"foo bar\" baz",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]string{"foo:bar", "baz"},
|
|
|
|
"foo:bar baz",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]string{"foo:bar boo", "baz"},
|
|
|
|
"foo:\"bar boo\" baz",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
require.Equal(t, tc.output, repairQuery(tc.args))
|
|
|
|
}
|
|
|
|
}
|
2022-08-18 13:18:23 +03:00
|
|
|
|
|
|
|
func TestLs_Format(t *testing.T) {
|
|
|
|
const expOrgMode = `^#+TODO: OPEN | CLOSED
|
|
|
|
[*] OPEN [0-9a-f]{7} \[\d\d\d\d-\d\d-\d\d [[:alpha:]]{3} \d\d:\d\d\] John Doe: this is a bug title ::
|
|
|
|
[*]{2} Last Edited: \[\d\d\d\d-\d\d-\d\d [[:alpha:]]{3} \d\d:\d\d\]
|
|
|
|
[*]{2} Actors:
|
|
|
|
: [0-9a-f]{7} John Doe
|
|
|
|
[*]{2} Participants:
|
|
|
|
: [0-9a-f]{7} John Doe
|
|
|
|
$`
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
format string
|
|
|
|
exp string
|
|
|
|
}{
|
|
|
|
{"default", "^[0-9a-f]{7}\topen\tthis is a bug title \tJohn Doe \t\n$"},
|
|
|
|
{"plain", "^[0-9a-f]{7} \\[open\\] this is a bug title\n$"},
|
|
|
|
{"compact", "^[0-9a-f]{7} open this is a bug title John Doe\n$"},
|
|
|
|
{"org-mode", expOrgMode},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testcase := range cases {
|
|
|
|
opts := lsOptions{
|
|
|
|
sortDirection: "asc",
|
|
|
|
sortBy: "creation",
|
|
|
|
outputFormat: testcase.format,
|
|
|
|
}
|
|
|
|
|
|
|
|
name := fmt.Sprintf("with %s format", testcase.format)
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2022-08-18 13:29:51 +03:00
|
|
|
env, _ := newTestEnvAndBug(t)
|
2022-08-18 13:18:23 +03:00
|
|
|
|
|
|
|
require.NoError(t, runLs(env.env, opts, []string{}))
|
|
|
|
t.Log(env.out.String())
|
|
|
|
require.Regexp(t, testcase.exp, env.out.String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("with JSON format", func(t *testing.T) {
|
|
|
|
opts := lsOptions{
|
|
|
|
sortDirection: "asc",
|
|
|
|
sortBy: "creation",
|
|
|
|
outputFormat: "json",
|
|
|
|
}
|
|
|
|
|
2022-08-18 13:29:51 +03:00
|
|
|
env, _ := newTestEnvAndBug(t)
|
2022-08-18 13:18:23 +03:00
|
|
|
|
|
|
|
require.NoError(t, runLs(env.env, opts, []string{}))
|
|
|
|
|
|
|
|
bugs := []JSONBugExcerpt{}
|
|
|
|
require.NoError(t, json.Unmarshal(env.out.Bytes(), &bugs))
|
|
|
|
|
|
|
|
require.Len(t, bugs, 1)
|
|
|
|
})
|
|
|
|
}
|