-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgonsole_test.go
More file actions
37 lines (31 loc) · 860 Bytes
/
gonsole_test.go
File metadata and controls
37 lines (31 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package gonsole_test
import (
"github.com/walltearer/gonsole"
"io"
"io/ioutil"
"os"
"reflect"
"testing"
)
func TestNew(t *testing.T) {
gon := gonsole.New()
if reflect.TypeOf(gon).String() != "*gonsole.Gonsole" {
t.Error("Failed to create new gonsole instance")
}
}
func ExampleGonsole_ReadInt() {
// using fake input source to simulate user's input
fakeInput, _ := ioutil.TempFile("", "")
defer fakeInput.Close()
io.WriteString(fakeInput, "wrongone\n")
io.WriteString(fakeInput, "wrong2\n")
io.WriteString(fakeInput, "123\n")
fakeInput.Seek(0, os.SEEK_SET)
gon := gonsole.New()
gon.SetSource(fakeInput)
gon.ReadInt("Prompt msg: ")
// Output:
// Prompt msg: Converting Error: strconv.ParseInt: parsing "wrongone": invalid syntax
// Prompt msg: Converting Error: strconv.ParseInt: parsing "wrong2": invalid syntax
// Prompt msg:
}