@@ -2,7 +2,6 @@ package cliui_test
2
2
3
3
import (
4
4
"context"
5
- "runtime"
6
5
"testing"
7
6
8
7
"github.com/spf13/cobra"
@@ -47,7 +46,7 @@ func TestPrompt(t *testing.T) {
47
46
require .Equal (t , "yes" , <- doneChan )
48
47
})
49
48
50
- t .Run ("Multiline " , func (t * testing.T ) {
49
+ t .Run ("JSON " , func (t * testing.T ) {
51
50
t .Parallel ()
52
51
ptty := ptytest .New (t )
53
52
doneChan := make (chan string )
@@ -59,13 +58,44 @@ func TestPrompt(t *testing.T) {
59
58
doneChan <- resp
60
59
}()
61
60
ptty .ExpectMatch ("Example" )
62
- ptty .WriteLine ("'this is a" )
63
- ptty .WriteLine ("test'" )
64
- newline := "\n "
65
- if runtime .GOOS == "windows" {
66
- newline = "\r \n "
67
- }
68
- require .Equal (t , "this is a" + newline + "test" , <- doneChan )
61
+ ptty .WriteLine ("{}" )
62
+ require .Equal (t , "{}" , <- doneChan )
63
+ })
64
+
65
+ t .Run ("BadJSON" , func (t * testing.T ) {
66
+ t .Parallel ()
67
+ ptty := ptytest .New (t )
68
+ doneChan := make (chan string )
69
+ go func () {
70
+ resp , err := newPrompt (ptty , cliui.PromptOptions {
71
+ Text : "Example" ,
72
+ })
73
+ require .NoError (t , err )
74
+ doneChan <- resp
75
+ }()
76
+ ptty .ExpectMatch ("Example" )
77
+ ptty .WriteLine ("{a" )
78
+ require .Equal (t , "{a" , <- doneChan )
79
+ })
80
+
81
+ t .Run ("MultilineJSON" , func (t * testing.T ) {
82
+ t .Parallel ()
83
+ ptty := ptytest .New (t )
84
+ doneChan := make (chan string )
85
+ go func () {
86
+ resp , err := newPrompt (ptty , cliui.PromptOptions {
87
+ Text : "Example" ,
88
+ })
89
+ require .NoError (t , err )
90
+ doneChan <- resp
91
+ }()
92
+ ptty .ExpectMatch ("Example" )
93
+ ptty .WriteLine (`{
94
+ "test": "wow"
95
+ }` )
96
+ require .Equal (t , `{
97
+ "test": "wow"
98
+ }` , <- doneChan )
69
99
})
70
100
}
71
101
0 commit comments