-
Notifications
You must be signed in to change notification settings - Fork 15
/
exam_test.go
71 lines (62 loc) · 1.49 KB
/
exam_test.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package prompter_test
import (
"fmt"
"github.com/Songmu/prompter"
)
func ExamplePrompter() {
input := (&prompter.Prompter{
Choices: []string{"aa", "bb", "cc"},
Default: "aa",
Message: "please select",
IgnoreCase: true,
}).Prompt()
fmt.Println("aa")
fmt.Printf("your input is %s.", input)
// Output:
// please select (aa/bb/cc) [aa]: aa
// your input is aa.
}
func ExampleChoose() {
lang := prompter.Choose("Which language do you like the most?", []string{"Perl", "Golang", "Scala", "Ruby"}, "Perl")
fmt.Println("Perl")
fmt.Printf("Great! You like %s!", lang)
// Output:
// Which language do you like the most? (Perl/Golang/Scala/Ruby) [Perl]: Perl
// Great! You like Perl!
}
func ExamplePrompt() {
answer := prompter.Prompt("Enter your twitter ID", "")
_ = answer
fmt.Println("Songmu")
fmt.Printf("Hi Songmu!")
// Output:
// Enter your twitter ID: Songmu
// Hi Songmu!
}
func ExamplePassword() {
passwd := prompter.Password("Enter your password")
_ = passwd
fmt.Println("****")
fmt.Print("I got your password! :P")
// Output:
// Enter your password: ****
// I got your password! :P
}
func ExampleYN() {
if prompter.YN("Do you like sushi?", true) {
fmt.Println("y")
fmt.Print("Nice! Let's go sushi bar!")
}
// Output:
// Do you like sushi? (y/n) [y]: y
// Nice! Let's go sushi bar!
}
func ExampleYesNo() {
if !prompter.YesNo("Do you like beer?", false) {
fmt.Println("no")
fmt.Print("Oops!")
}
// Output:
// Do you like beer? (yes/no) [no]: no
// Oops!
}