|
|
|
@ -14,22 +14,24 @@ import (
|
|
|
|
|
func TestEnterToContinue(t *testing.T) {
|
|
|
|
|
r, w, err := os.Pipe()
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
ow := os.Stdout
|
|
|
|
|
os.Stdout = w
|
|
|
|
|
or := os.Stdin
|
|
|
|
|
os.Stdin = r
|
|
|
|
|
defer func() {
|
|
|
|
|
os.Stdin = or
|
|
|
|
|
os.Stdout = ow
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
wg.Add(2)
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
ow := os.Stdout
|
|
|
|
|
os.Stdout = w
|
|
|
|
|
fmt.Println()
|
|
|
|
|
os.Stdout = ow
|
|
|
|
|
}()
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
or := os.Stdin
|
|
|
|
|
os.Stdin = r
|
|
|
|
|
EnterToContinue()
|
|
|
|
|
os.Stdin = or
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
wait := make(chan lang.PlaceholderType)
|
|
|
|
@ -48,24 +50,26 @@ func TestEnterToContinue(t *testing.T) {
|
|
|
|
|
func TestReadLine(t *testing.T) {
|
|
|
|
|
r, w, err := os.Pipe()
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
ow := os.Stdout
|
|
|
|
|
os.Stdout = w
|
|
|
|
|
or := os.Stdin
|
|
|
|
|
os.Stdin = r
|
|
|
|
|
defer func() {
|
|
|
|
|
os.Stdin = or
|
|
|
|
|
os.Stdout = ow
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
const message = "hello"
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
wg.Add(2)
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
ow := os.Stdout
|
|
|
|
|
os.Stdout = w
|
|
|
|
|
fmt.Println(message)
|
|
|
|
|
os.Stdout = ow
|
|
|
|
|
}()
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
or := os.Stdin
|
|
|
|
|
os.Stdin = r
|
|
|
|
|
input := ReadLine("")
|
|
|
|
|
assert.Equal(t, message, input)
|
|
|
|
|
os.Stdin = or
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
wait := make(chan lang.PlaceholderType)
|
|
|
|
|