Skip to content

Commit 09e844b

Browse files
committed
Remove Regexp/RegexpPattern
1 parent 0e8d4b6 commit 09e844b

File tree

2 files changed

+0
-159
lines changed

2 files changed

+0
-159
lines changed

expect/expect_opt.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -225,36 +225,6 @@ func String(strs ...string) Opt {
225225
}
226226
}
227227

228-
// Regexp adds an Expect condition to exit if the content read from Console's
229-
// tty matches the given Regexp.
230-
func Regexp(res ...*regexp.Regexp) Opt {
231-
return func(opts *Opts) error {
232-
for _, re := range res {
233-
opts.Matchers = append(opts.Matchers, &regexpMatcher{
234-
re: re,
235-
})
236-
}
237-
return nil
238-
}
239-
}
240-
241-
// RegexpPattern adds an Expect condition to exit if the content read from
242-
// Console's tty matches the given Regexp patterns. Expect returns an error if
243-
// the patterns were unsuccessful in compiling the Regexp.
244-
func RegexpPattern(ps ...string) Opt {
245-
return func(opts *Opts) error {
246-
var res []*regexp.Regexp
247-
for _, p := range ps {
248-
re, err := regexp.Compile(p)
249-
if err != nil {
250-
return err
251-
}
252-
res = append(res, re)
253-
}
254-
return Regexp(res...)(opts)
255-
}
256-
}
257-
258228
// Error adds an Expect condition to exit if reading from Console's tty returns
259229
// one of the provided errors.
260230
func Error(errs ...error) Opt {

expect/expect_opt_test.go

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package expect_test
1717
import (
1818
"bytes"
1919
"io"
20-
"regexp"
2120
"testing"
2221

2322
"github.com/stretchr/testify/require"
@@ -83,122 +82,6 @@ func TestExpectOptString(t *testing.T) {
8382
}
8483
}
8584

86-
func TestExpectOptRegexp(t *testing.T) {
87-
t.Parallel()
88-
89-
tests := []struct {
90-
title string
91-
opt Opt
92-
data string
93-
expected bool
94-
}{
95-
{
96-
"No args",
97-
Regexp(),
98-
"Hello world",
99-
false,
100-
},
101-
{
102-
"Single arg",
103-
Regexp(regexp.MustCompile(`^Hello`)),
104-
"Hello world",
105-
true,
106-
},
107-
{
108-
"Multiple arg",
109-
Regexp(regexp.MustCompile(`^Hello$`), regexp.MustCompile(`world$`)),
110-
"Hello world",
111-
true,
112-
},
113-
{
114-
"No matches",
115-
Regexp(regexp.MustCompile(`^Hello$`)),
116-
"Hello world",
117-
false,
118-
},
119-
}
120-
121-
for _, test := range tests {
122-
test := test
123-
t.Run(test.title, func(t *testing.T) {
124-
t.Parallel()
125-
126-
var options Opts
127-
err := test.opt(&options)
128-
require.Nil(t, err)
129-
130-
buf := new(bytes.Buffer)
131-
_, err = buf.WriteString(test.data)
132-
require.Nil(t, err)
133-
134-
matcher := options.Match(buf)
135-
if test.expected {
136-
require.NotNil(t, matcher)
137-
} else {
138-
require.Nil(t, matcher)
139-
}
140-
})
141-
}
142-
}
143-
144-
func TestExpectOptRegexpPattern(t *testing.T) {
145-
t.Parallel()
146-
147-
tests := []struct {
148-
title string
149-
opt Opt
150-
data string
151-
expected bool
152-
}{
153-
{
154-
"No args",
155-
RegexpPattern(),
156-
"Hello world",
157-
false,
158-
},
159-
{
160-
"Single arg",
161-
RegexpPattern(`^Hello`),
162-
"Hello world",
163-
true,
164-
},
165-
{
166-
"Multiple arg",
167-
RegexpPattern(`^Hello$`, `world$`),
168-
"Hello world",
169-
true,
170-
},
171-
{
172-
"No matches",
173-
RegexpPattern(`^Hello$`),
174-
"Hello world",
175-
false,
176-
},
177-
}
178-
179-
for _, test := range tests {
180-
test := test
181-
t.Run(test.title, func(t *testing.T) {
182-
t.Parallel()
183-
184-
var options Opts
185-
err := test.opt(&options)
186-
require.Nil(t, err)
187-
188-
buf := new(bytes.Buffer)
189-
_, err = buf.WriteString(test.data)
190-
require.Nil(t, err)
191-
192-
matcher := options.Match(buf)
193-
if test.expected {
194-
require.NotNil(t, matcher)
195-
} else {
196-
require.Nil(t, matcher)
197-
}
198-
})
199-
}
200-
}
201-
20285
func TestExpectOptError(t *testing.T) {
20386
t.Parallel()
20487

@@ -310,18 +193,6 @@ func TestExpectOptAll(t *testing.T) {
310193
"Hello world",
311194
true,
312195
},
313-
{
314-
"Mixed opts match",
315-
All(String("Hello"), RegexpPattern(`wo[a-z]{1}ld`)),
316-
"Hello woxld",
317-
true,
318-
},
319-
{
320-
"Mixed opts no match",
321-
All(String("Hello"), RegexpPattern(`wo[a-z]{1}ld`)),
322-
"Hello wo4ld",
323-
false,
324-
},
325196
}
326197

327198
for _, test := range tests {

0 commit comments

Comments
 (0)