Initial commit

This commit is contained in:
enordaz 2025-05-30 13:41:39 -06:00
commit 7723dd4596
5 changed files with 64 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.eo13-dev.com/enordaz/gokedex
go 1.24.2

BIN
gokedex Executable file

Binary file not shown.

21
main.go Normal file
View 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
View 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
View 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])
}
}
}
}