commit 7723dd45960cfb349ff2aa0c0b2c3ccb68938c97 Author: enordaz Date: Fri May 30 13:41:39 2025 -0600 Initial commit diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..414c0cb --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.eo13-dev.com/enordaz/gokedex + +go 1.24.2 diff --git a/gokedex b/gokedex new file mode 100755 index 0000000..8a1f909 Binary files /dev/null and b/gokedex differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..e1bb917 --- /dev/null +++ b/main.go @@ -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]) + } +} diff --git a/repl.go b/repl.go new file mode 100644 index 0000000..e30843c --- /dev/null +++ b/repl.go @@ -0,0 +1,9 @@ +package main + +import "strings" + +func cleanInput(text string) []string { + input := strings.ToLower(text) + words := strings.Fields(input) + return words +} diff --git a/repl_test.go b/repl_test.go new file mode 100644 index 0000000..f81e687 --- /dev/null +++ b/repl_test.go @@ -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]) + } + } + } +}