Initial commit
This commit is contained in:
commit
7723dd4596
21
main.go
Normal file
21
main.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
const prompt = "Pokedex > "
|
||||
|
||||
func main() {
|
||||
dexScanner := bufio.NewScanner(os.Stdin)
|
||||
for {
|
||||
fmt.Print(prompt)
|
||||
if !dexScanner.Scan() {
|
||||
break
|
||||
}
|
||||
command := cleanInput(dexScanner.Text())
|
||||
fmt.Println("Your command was:", command[0])
|
||||
}
|
||||
}
|
||||
9
repl.go
Normal file
9
repl.go
Normal file
@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import "strings"
|
||||
|
||||
func cleanInput(text string) []string {
|
||||
input := strings.ToLower(text)
|
||||
words := strings.Fields(input)
|
||||
return words
|
||||
}
|
||||
31
repl_test.go
Normal file
31
repl_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCleanInput(t *testing.T) {
|
||||
cases := []struct {
|
||||
input string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
input: " hello world ",
|
||||
expected: []string{"hello", "world"},
|
||||
},
|
||||
{
|
||||
input: "pikachu charmander",
|
||||
expected: []string{"pikachu", "charmander"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
actual := cleanInput(c.input)
|
||||
if len(actual) != len(c.expected) {
|
||||
t.Errorf("length of actual (%v) does not match expected length (%v)", len(actual), len(c.expected))
|
||||
}
|
||||
for i := range actual {
|
||||
if actual[i] != c.expected[i] {
|
||||
t.Errorf("actual word %v:%v does not match expected word %v:%v", i, actual[i], i, c.expected[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user