diff options
author | Michael Muré <batolettre@gmail.com> | 2022-09-10 11:09:19 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2022-11-20 17:18:09 +0100 |
commit | acc9a6f3a6df2961c3ae44352216d915cb9b5315 (patch) | |
tree | e159372673104ade1f15ddc1a84aa9da93e93552 /commands/bug/bug_test.go | |
parent | a3fa445a9c76631c4cd16f93e1c1c68a954adef7 (diff) | |
download | git-bug-acc9a6f3a6df2961c3ae44352216d915cb9b5315.tar.gz |
commands: reorg into different packages
Diffstat (limited to 'commands/bug/bug_test.go')
-rw-r--r-- | commands/bug/bug_test.go | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/commands/bug/bug_test.go b/commands/bug/bug_test.go new file mode 100644 index 00000000..aef0346d --- /dev/null +++ b/commands/bug/bug_test.go @@ -0,0 +1,103 @@ +package bugcmd + +import ( + "encoding/json" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/MichaelMure/git-bug/commands/bug/testenv" +) + +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)) + } +} + +func TestBug_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$"}, + {"id", "^[0-9a-f]{64}\n$"}, + {"org-mode", expOrgMode}, + } + + for _, testcase := range cases { + opts := bugOptions{ + sortDirection: "asc", + sortBy: "creation", + outputFormat: testcase.format, + } + + name := fmt.Sprintf("with %s format", testcase.format) + + t.Run(name, func(t *testing.T) { + env, _ := testenv.NewTestEnvAndBug(t) + + require.NoError(t, runBug(env, opts, []string{})) + require.Regexp(t, testcase.exp, env.Out.String()) + }) + } + + t.Run("with JSON format", func(t *testing.T) { + opts := bugOptions{ + sortDirection: "asc", + sortBy: "creation", + outputFormat: "json", + } + + env, _ := testenv.NewTestEnvAndBug(t) + + require.NoError(t, runBug(env, opts, []string{})) + + var bugs []JSONBugExcerpt + require.NoError(t, json.Unmarshal(env.Out.Bytes(), &bugs)) + + require.Len(t, bugs, 1) + }) +} |