MCPcopy Create free account
hub / github.com/cloudspannerecosystem/spanner-cli / TestReadInteractiveInput

Function TestReadInteractiveInput

cli_test.go:120–189  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestReadInteractiveInput(t *testing.T) {
121 for _, tt := range []struct {
122 desc string
123 input string
124 want *inputStatement
125 wantError bool
126 }{
127 {
128 desc: "single line",
129 input: "SELECT 1;\n",
130 want: &inputStatement{
131 statement: "SELECT 1",
132 statementWithoutComments: "SELECT 1",
133 delim: delimiterHorizontal,
134 },
135 },
136 {
137 desc: "multi lines",
138 input: "SELECT\n* FROM\n t1\n;\n",
139 want: &inputStatement{
140 statement: "SELECT\n* FROM\n t1",
141 statementWithoutComments: "SELECT\n* FROM\n t1",
142 delim: delimiterHorizontal,
143 },
144 },
145 {
146 desc: "multi lines with vertical delimiter",
147 input: "SELECT\n* FROM\n t1\\G\n",
148 want: &inputStatement{
149 statement: "SELECT\n* FROM\n t1",
150 statementWithoutComments: "SELECT\n* FROM\n t1",
151 delim: delimiterVertical,
152 },
153 },
154 {
155 desc: "multi lines with multiple comments",
156 input: "SELECT\n/* comment */1,\n# comment\n2;\n",
157 want: &inputStatement{
158 statement: "SELECT\n/* comment */1,\n# comment\n2",
159 statementWithoutComments: "SELECT\n 1,\n 2",
160 delim: delimiterHorizontal,
161 },
162 },
163 {
164 desc: "multiple statements",
165 input: "SELECT 1; SELECT 2;",
166 want: nil,
167 wantError: true,
168 },
169 } {
170 t.Run(tt.desc, func(t *testing.T) {
171 rl, err := readline.NewEx(&readline.Config{
172 Stdin: io.NopCloser(strings.NewReader(tt.input)),
173 Stdout: io.Discard,
174 Stderr: io.Discard,
175 })
176 if err != nil {
177 t.Fatalf("unexpected readline.NewEx() error: %v", err)

Callers

nothing calls this directly

Calls 1

readInteractiveInputFunction · 0.85

Tested by

no test coverage detected