-func TestEventText(t *testing.T) {
- testCases := []struct {
- name string
- event Event
- text string
- }{
- {
- name: "reply as it is",
- event: Event{Kind: "reply", Text: "Done."},
- text: "Done.",
- },
- {
- name: "own user message not shown",
- event: Event{Kind: "user", Text: "typed", Source: terminalSource},
- text: "",
- },
- {
- name: "user message of another source marked",
- event: Event{Kind: "user", Text: "from the phone", Source: "telegram"},
- text: "[telegram] from the phone",
- },
- {
- name: "long result cut",
- event: Event{Kind: "echo", Text: strings.Repeat("line\n", 12)},
- text: "[result] " + strings.Repeat("line\n", 9) + "line\n[2 more lines]",
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- require.Equal(t, tc.text, eventText(tc.event))
- })
- }
-}
-
-// testClient is a terminal client of a test daemon, with a pipe as its input.
-type testClient struct {
- input *io.PipeWriter
- done chan error
- out *syncBuffer
-}
-
-// Type writes one line to the input of the client.
-func (c *testClient) Type(line string) {
- _, err := io.WriteString(c.input, line+"\n")
- if err != nil {
- panic(err)
- }
-}
-
-// Output returns what the client showed.
-func (c *testClient) Output() string {
- return c.out.String()
-}
-
-// WaitFor waits until the client showed text.
-func (c *testClient) WaitFor(t *testing.T, text string) {